Forum Discussion
GiscardN
11 years agoFrequent Contributor
Hi,
You can do this with a Groovy script assertion using XMLSlurper.
This is an example comparing two responses:
def response1 = context.expand( '${JDBC result#JDBC_Response}' )
def response2 = context.expand( '${Request 2#Response}' )
def firstrecords = new XmlSlurper().parseText(response1)
def secondrecords = new XmlSlurper().parseText(response2)
Then for each record in response 1, you loop through response 2 and assert. Return true if a match is found in the second response, false otherwise.
Ex: you are comparing each firstrecords.Record.price with each secondrecords.Record.price[j]
You can learn more about XMLSlurper here: http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper
Regards,
Giscard
SmartBear Support
You can do this with a Groovy script assertion using XMLSlurper.
This is an example comparing two responses:
def response1 = context.expand( '${JDBC result#JDBC_Response}' )
def response2 = context.expand( '${Request 2#Response}' )
def firstrecords = new XmlSlurper().parseText(response1)
def secondrecords = new XmlSlurper().parseText(response2)
Then for each record in response 1, you loop through response 2 and assert. Return true if a match is found in the second response, false otherwise.
Ex: you are comparing each firstrecords.Record.price with each secondrecords.Record.price[j]
You can learn more about XMLSlurper here: http://groovy.codehaus.org/Reading+XML+using+Groovy%27s+XmlSlurper
Regards,
Giscard
SmartBear Support