cancel
Showing results for 
Search instead for 
Did you mean: 

How I can use JSON Path assertion for two different strings without using Groovy

SOLVED
Highlighted
Contributor

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 

image.png

I tried the JSONPath Regx match assertion as well but didn't work. Help much appreciated. 

image.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Hero

Highlighted
Community Hero

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

 

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

View solution in original post

6 REPLIES 6
Highlighted
Community Hero

Highlighted
Contributor

@nmrao , thanks for the reply. Can you please explain more how to get the regular expression for two strings? 

Highlighted
Community Hero

The samples are available in the link given in the previous reply. Have you gone through it?


Regards,
Rao.
Highlighted
Community Hero

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

 

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

View solution in original post

Highlighted
Contributor

@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 

Highlighted
Contributor

yes I had but didn't work. Because of the way that I am getting the data. Thanks anyway.  

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