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 se...
  • nmrao's avatar
    nmrao
    5 years ago

    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 ~