cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
New Contributor

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. 

anita_0-1590001125171.png

 

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
                        }
                      ]
              }

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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

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 ~



Regards,
Rao.

View solution in original post

4 REPLIES 4
Highlighted
Community Hero

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

Could not find the documentation reference in SoapUI. However, below is the documentation for the same in Pro tool, I guess you can follow the same.
https://support.smartbear.com/readyapi/docs/testing/assertions/reference/property/json-regex.html

Please see if the above is helpful.


Regards,
Rao.
Highlighted
New Contributor

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

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.

Highlighted
Community Hero

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

Hey @anita,

I appreciate there isnt an "allow wildcard" checkbox like there is in readyapi!, (so it doesnt support using the typical text asterisk wildcard) but im wondering if you can use regex's wildcards instead?

See following link: https://www.google.com/url?sa=t&source=web&rct=j&url=https://www.keycdn.com/support/regex-cheatsheet...

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

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

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 ~



Regards,
Rao.

View solution in original post

New Here?
Join us and watch the welcome video:
Top Kudoed Authors