How I can use JSON Path assertion for two different strings without using Groovy
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How I can use JSON Path assertion for two different strings without using Groovy
I have a JSON Path assertion which expecting a string like "PAYMENT REVERSED" but sometimes the string also can be "PAYMENT REVERSAL". Is it possible to do as follows? (tried but didn't work) or what is the best way to do this?
PAYMENT REVERSED || PAYMENT REVERSAL
I tried the JSONPath Regx match assertion as well but didn't work. Help much appreciated.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For more details:
https://stackoverflow.com/questions/28954720/jsonpath-expression-to-filter-using-regex
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@nmrao , thanks for the reply. Can you please explain more how to get the regular expression for two strings?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @mpw83
I understand a reluctance relying on coding if you're not a coder (or if managers dont want to include code when considering future maintenance, etc.) - but adding a small 2 line script assertion would resolve this problem.
Also - considering that the two possiible values are PAYMENT REVERSED and PAYMENT REVERSAL, wouldnt they have identical regex patterns anyway?
a while back I had to assert that a certain json value had either of 2 values and @nmrao supplied me the following Script Assertion:
//courtesy of Rao
def jsonResponseContent = new groovy.json.JsonSlurper().parseText(context.response) assert jsonResponseContent.parentattribute.childattribute == ['PAYMENT REVERSED' || 'PAYMENT REVERSAL']
As I say - I know you say you dont want to use groovy script - but it's a two line script assertion - anyone reading this (even with zero groovy) would be able to understand what the code is actually doing.
If you're still struggling with the JSON Regex match assertion - perhaps the above might help you?
Just a suggestion, cheers,
rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@richie , thanks for the reply. yes .. I was able to solve this issue using groovy but want to know how I can directly use via the UI.. Thanks
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes I had but didn't work. Because of the way that I am getting the data. Thanks anyway.
