Forum Discussion
$.accessToken should equal to the desired value.
nmrao wrote:
For the mentioned case, JsonPatMatch is fine.
$.accessToken should equal to the desired value.
nmraoI entered this (see screenshot), but it's not working. as you can see there is an accesstoken in the response, but validating it gives an error (it thinks it should be false?). Do you have any tips?
- HKosova8 years agoSmartBear Alumni (Retired)
mgroen2, you're using JsonPath Regex Match. Try the regular JsonPath Match instead.
- mgroen28 years agoSuper Contributor
Hi,
HKosova as you suggested, I implemented the JsonPath Match,
the strange this is, that validation initially succeeds (I clicked on "select from current"), however when re-executing the test it fails, and the reason for that is that expected value is changed, a comma is added to the end (see second screenshot).
After re-selecting the value again (" select from current"), the assertion passes again first time, but re-executing the test, makes the assertion fail again (comma is added again). Is this known behaviour? Possibly a bug?
- HKosova8 years agoSmartBear Alumni (Retired)
Mathijs,
The comma is part of the error message, not the value. And the error happens because the token value is different - e.g. on your image the expected value ends with "...D8LE" and the actual value ends with "... JSPPA" (or vice versa).
I guess the token is generated dynamically and is different for each new session, like a unique session ID. How are you supposed to validate it? Do you just need to verify this token is present in the response, regardless of the value?
- nmrao8 years agoChampion Level 3You should be able to try here
http://jsonpath.com/
Following Script Assertion should help:
def parsedJson = new groovy.json.JsonSlurper().parseText(context.response)
log.info parsedJson.accessToken
//replace expectedValue below
assert expectedValue == parsedJson.accessToken, 'Not matched.'
You can also check here:
http://groovyconsole.appspot.com/script/5179916383420416
Related Content
- 9 years ago
Recent Discussions
- 15 years ago