retesh101
11 years agoNew Contributor
Compare two REST API responses for every attribute (nodes)
Hi,
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 - http://coinmarketcap.northpole.ro/api/usd/all.json
REST request 2 - http://coinmarketcap.northpole.ro/api/usd/all.json - using same request for testing purpose
Groovy script:
def Response1 = context.expand( '${All.json - Request 1#ResponseAsXml#declare namespace ns1=\'http://coinmarketcap.northpole.ro/api/usd/all.json\'; //ns1:Response[1]}' )
def Response2 = context.expand( '${All.json - Request 2#ResponseAsXml#declare namespace ns1=\'http://coinmarketcap.northpole.ro/api/usd/all.json\'; //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!!!
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 - http://coinmarketcap.northpole.ro/api/usd/all.json
REST request 2 - http://coinmarketcap.northpole.ro/api/usd/all.json - using same request for testing purpose
Groovy script:
def Response1 = context.expand( '${All.json - Request 1#ResponseAsXml#declare namespace ns1=\'http://coinmarketcap.northpole.ro/api/usd/all.json\'; //ns1:Response[1]}' )
def Response2 = context.expand( '${All.json - Request 2#ResponseAsXml#declare namespace ns1=\'http://coinmarketcap.northpole.ro/api/usd/all.json\'; //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!!!