[TechCorner Challenge #7] Change an XPath Match assertion to a JSONPath Match assertion
Imagine that the logic of the server has been changed and you started getting responses from the server in the JSON format instead of XML. And, it may appear that XMLPath assertions don’t suit you anymore. In this case, you need to convert all XPath Match assertions to JSONPath Match assertions in your project. There could be a lot of test steps to change, so it’s better to automate this process.
Task: Create a script to convert XPath Match assertion to JSONPath Match assertion for the REST test steps where the request URL is the following: https://example.com/test.
Difficulty:
A script should do this:
1. Add the JSONPath Match assertion to REST test steps that have the https://example.com/test endpoint.
2. Convert the XPath expression and expected result from the XPath Match assertion to the JSONPath expression and expected result for the corresponding test steps.
3. Remove the XPath Match assertions for those test steps.
A sample response:
JSON |
XML |
---|---|
|
|
XMLPath Match assertions example:
Condition:
declare namespace ns1='https://petstore.swagger.io/v2/pet';
//ns1:Response[1]/ns1:tags[1]/ns1:e[1]/ns1:id[1]
Expected result:
${#TestCase#ID}
Tips:
-
https://support.smartbear.com/readyapi/docs/soapui/steps/groovy.html#working-with
-
https://support.smartbear.com/readyapi/apidocs/soapui/DefaultPackage/XPathContainsAssertion.html
-
https://support.smartbear.com/readyapi/apidocs/pro/DefaultPackage/JsonPathContentAssertion.html
Good luck and have fun😊