Forum Discussion

retesh101's avatar
New Contributor
11 years ago

Compare two REST API responses for every attribute (nodes)


I have requirement to compare two responses and report any mismatch at the attribute level; two REST API requests which are for different environments like (QA and PROD)
My setup under Test Step as
REST request 1 -
REST request 2 - - using same request for testing purpose

Groovy script:
def Response1 = context.expand( '${All.json - Request 1#ResponseAsXml#declare namespace ns1=\'\'; //ns1:Response[1]}' )
def Response2 = context.expand( '${All.json - Request 2#ResponseAsXml#declare namespace ns1=\'\'; //ns1:Response[1]}' )

assert Response1 == Response2

so far I have learned to get the response from request 1, get the response from request 2 and then compare whole response as one string.

In that case I won't know what attribute is not matching with QA vs PROD.

Can someone please help me with getting each attributes from both response and compare one at a time and then report what's not matching?

Thanks a lot in the advanced!!!

3 Replies