Forum Discussion

anita's avatar
anita
New Contributor
5 years ago

JsonPath RegEx Match Assertion is not working on SoapUI 5.5.0 open source

I am trying to add the assertion for the JsonPath RegEx Match and it always return false even if the response is present.

I am expecting the program name should have "Auto" keyword in it. I tried several regular expressions e.g. Auto, (.*Auto)

Please refer the attached screenshot. 

 

Json Response:

                        {
                               "records": [{
                                "Program_Name": "Auto Program",
                                 "Terms": ["Automation Term"],
                                 "Program_Type_ID": 1,
                                  "Program_Id": 10075
                         },
                        {
                             "Program_Name": "Automation Program",
                              "Terms": [" Term"],
                               "Program_Type_ID": 1, 
                              "Program_Id": 10000
                        }
                      ]
              }

 

  • Thank you anita 

     

    I don't know about what is there in ReadyAPI.

     

    Looks different tools uses different parsers for evaluating JSONPath.

     

    For example, below sites

    https://jsonpath.com/

    https://jsonpath.curiousconcept.com/

     

    And try below json paths, and both behave differently and I assume the same is happening with SoapUI as well. Tried the same JSONPath expression in JSON Path Match, JSON Path Count and seem to be not working which are supposed to be. May be an issue with few Conditional JsonPath.

     

    • #1. $.records[?(@.Program_Name =~ /Auto*/ )].Program_Name
    • #2. $.records[?(/Auto/.test(@.Program_Name))].Program_Name

    Results same (both names) by both the Json Paths

     

    [
      "Auto Program",
      "Automation Program"
    ]

     

    However, Json Path match works with below expression

     

    • $.records[?(@.Program_Name == 'Auto Program')].Program_Name[0]

     

    If you still want to have your assertion with regex, then below Script Assertion can be used

     

     

    //You may even use test case custom properties for below two so that you dont have to edit to assertion when data changes
    def regEx = 'Auto*' 
    def expectedRecords = 2
    
    def matchedPrograms = new groovy.json.JsonSlurper().parseText(context.response).records.findAll {it.Program_Name =~ /$regEx/}.Program_Name
    log.info matchedPrograms
    assert matchedPrograms.size == expectedRecords
    

     

     

    Thanks for the nice question.

     

    Hope SmartBear team looks into the issue dealing with conditional json path expression which contains characters such as ~

    • anita's avatar
      anita
      New Contributor

      There is no option to select "Allow Wildcards" in open source. I tried to change it in the project xml file but it is also giving the same result and it overwrite(Allow wildcard to false) when I am trying to save the project. 

       

      I am looking for the solution in open source.

      • nmrao's avatar
        nmrao
        Champion Level 3

        Thank you anita 

         

        I don't know about what is there in ReadyAPI.

         

        Looks different tools uses different parsers for evaluating JSONPath.

         

        For example, below sites

        https://jsonpath.com/

        https://jsonpath.curiousconcept.com/

         

        And try below json paths, and both behave differently and I assume the same is happening with SoapUI as well. Tried the same JSONPath expression in JSON Path Match, JSON Path Count and seem to be not working which are supposed to be. May be an issue with few Conditional JsonPath.

         

        • #1. $.records[?(@.Program_Name =~ /Auto*/ )].Program_Name
        • #2. $.records[?(/Auto/.test(@.Program_Name))].Program_Name

        Results same (both names) by both the Json Paths

         

        [
          "Auto Program",
          "Automation Program"
        ]

         

        However, Json Path match works with below expression

         

        • $.records[?(@.Program_Name == 'Auto Program')].Program_Name[0]

         

        If you still want to have your assertion with regex, then below Script Assertion can be used

         

         

        //You may even use test case custom properties for below two so that you dont have to edit to assertion when data changes
        def regEx = 'Auto*' 
        def expectedRecords = 2
        
        def matchedPrograms = new groovy.json.JsonSlurper().parseText(context.response).records.findAll {it.Program_Name =~ /$regEx/}.Program_Name
        log.info matchedPrograms
        assert matchedPrograms.size == expectedRecords
        

         

         

        Thanks for the nice question.

         

        Hope SmartBear team looks into the issue dealing with conditional json path expression which contains characters such as ~