Forum Discussion

rana1's avatar
rana1
New Contributor
8 years ago

Re: Compare two REST API responses for every attribute (node

Hi

How can I compare two json responses in ready api i.e.,I have a url I have requested a response1 and received response1. Now I have created another step in the same test case with the same parameters and requested response2 and received the response2.

NOW

I want to I want to compare RESPONSE1 with RESPONSE2.

Is it possible..?? If yes please reply me asap.

Thanks

Rana

  • Hello, It is possible to compare two JSON responses.

     

    Simplest approach is to parse the response using JsonSlurper and assert.

     

    import groovy.json.JsonSlurper

     

    def Response1 = context.expand( '${#TestStepName#Response}' ).toString()
          JSON1 = new JsonSlurper().parseText Response1

     

    def Response2 = context.expand( '${#TestStepName#Response}' ).toString()
          JSON2 = new JsonSlurper().parseText Response2

     

    assert JSON1 == JSON2

     

     

  • rana1's avatar
    rana1
    New Contributor

    Hi I'm using Ready API Pro 1.9.0 version

    How can I compare two json responses in ready api i.e.,I have a url I have requested a response1 and received response1. Now I have created another step in the same test case with the same parameters and requested response2 and received the response2.

    NOW

    I want to I want to compare RESPONSE1 with RESPONSE2.

    Is it possible..?? If yes please reply me asap.

    Thanks

    Ranadheer

  • nmrao's avatar
    nmrao
    Champion Level 3

     

    Now moved this messaged to right forum.

     

    Please add more details of your data and use case.

    • rana1's avatar
      rana1
      New Contributor

      I want to use My 1st response as a base line and I want to compare my 2nd response to my 1st response and check whether I'm getting the same response in both or not. Is it possible to check...???

      • New2API's avatar
        New2API
        Frequent Contributor

        Hello, It is possible to compare two JSON responses.

         

        Simplest approach is to parse the response using JsonSlurper and assert.

         

        import groovy.json.JsonSlurper

         

        def Response1 = context.expand( '${#TestStepName#Response}' ).toString()
              JSON1 = new JsonSlurper().parseText Response1

         

        def Response2 = context.expand( '${#TestStepName#Response}' ).toString()
              JSON2 = new JsonSlurper().parseText Response2

         

        assert JSON1 == JSON2