Comparing Json node values against each other
- 4 years ago
Hi ChrisAdams,
I used part of you logic and got the solution.
1. Converted both json responses to string and created objects of it (Using jsonSlurper()) with parsing
//Stored response
def response1 = context.expand( '${TestCaseName#Response}' )
def response2 = context.expand( '${TestCaseName#Response}' )def jsonSlurper = new JsonSlurper();
//Parsing the response received
def resp1_obj = jsonSlurper.parseText( response1.toString());
def resp2_obj = jsonSlurper.parseText( response2.toString());2. Accessed json file content with Key
resp1_obj.key_value[i]
resp2_obj.key_value[i]
3. Parameterized the key indexing ('i' value parameterized)
4. Compared the node values one after teh other using for loop.
for(int i=0;i<5;i++)
{
if(resp1_obj.key_value[i] == resp2_obj.key_value[i])
log.info("PASS")
else
log.error("FAILED")
break
}
Thanks once again for the solution and response.
Thanks & Regards,
Vivek Kulkarni