Forum Discussion

vivekkulkarni's avatar
vivekkulkarni
Occasional Contributor
3 years ago

Comparing Json node values against each other

 Hi Team,   I have query regarding the json values comparison.   I have request say Request-1 and gives response as Response-1. Gives 10 node values One more request say Request-2 and gives resp...
  • vivekkulkarni's avatar
    vivekkulkarni
    3 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