asserting unique ids
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
asserting unique ids
I would like to find sort of a "best practice" solution to this problem.
I need to have an unique id with all my requests. I have to assert that the response contains the same id.
If i make a small class that generates unique ids, i have an issue using property expansions in assertions, since one id will be sent in the request and another will be generated when i do the assertion.
I can do a script assertion but that is fiddly and takes a long time due to the various structures of the responses. I would very much like to avoid property transfers and instead have a simple method to reference the request i just sent as my expected value. Is this possible with a jsonpath match assertion somehow?
Solved! Go to Solution.
- Labels:
-
Assertions
-
REST
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use property expansion to refer to the current request:
${Test Step Name#Request#<json path expression>}
For example, if the request body is
{"id": "${#TestCase#ID}"}
the assertion can refer to the request field "id" as:
${TestStep Name#Request#$.id}
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, you have saved me a lot of time. I felt like this should be possible but couldnt find the right information.
Out of curiosity, can i do a self reference in a property expansion? If i can do something like ${#self#request} i won't have trouble if i copy/move/rename my things.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
${${=context.currentStep.label}#Request#$.id}
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ofcourse. Thank you again.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, trying it out i'm having some trouble.
${${=context.currentStep.label}#Request} works as expected. I get the full request body.
The following gives me nothing at all:
${${=context.currentStep.label}#Request#}
${${=context.currentStep.label}#Request#$.id}
I've tried some variations with no luck. I'm running SoapUI NG pro if that is relevant.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
${...#Request#} is not valid because an expression is expected after "Request#".
${${=context.currentStep.label}#Request#$.id}
works for me in JsonPath Match in Ready! API 1.9 given that the request is exactly as follows:
{"id": "${#TestCase#ID}"}
If your request has a different structure, adjust the JsonPath accordingly.
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think i made sense of this, excuse incorrect terms and such below 🙂
#Request is not correct as this is not the request i actually sent. When looking at #Request, the unique id changes every time and i shouldnt use it even if i could. It also seems like #Request is created as needed and as such doesnt exist when trying to grab something with jsonpath. (possible bug?)
#rawrequest however is what i needed, and this works as expected. My unique id is the actual id use in the request and theres some actual content for my assertions.
${${=context.currentStep.label}#rawrequest#$.ID} has made my day a lot better.
Thanks again for help and direction. Please let me know if i am horribly wrong and about to make everything worse 🙂
