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 parame...
  • New2API's avatar
    New2API
    8 years ago

    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