abhishekc17
12 years agoNew Contributor
Compare XML Response using SoapUI and writing to Database
Hi All,
I am very new to SOAPUI and I have come across a situation where I need to compare two XML Responses within a test case and if they do not match then log it to the database. After my research I found that there are two ways of doing it
1) Adding an Assertion ( Since I am using a SOAP UI PRO) - This was easy to setup however, I am unable to write the assertion results to a log ( in my case database)
2) So I went for a Groovy script - I have never worked with Groovy script before and I wanted some help in figuring out how to write code for it. below is the code I came up with so far but I get an error -
Code I used -
def LagacyResponse = context.expand( '${Legacy Call(app1)#Response#declare namespace ns1=\'com.rovicorp.metadataservice\'; //ns1:searchResponse[1]/ns1:results[1]/ns1:result[1]/ns1:id[1]}' )
def NewResponse = context.expand( '${New Call(app 2)#Response#declare namespace ns1=\'com.rovicorp.metadataservice\'; //ns1:searchResponse[1]/ns1:results[1]/ns1:result[1]/ns1:id[1]}' )
IF (LagacyResponse == NewResponse)-------------------Here I am comparing the two XML responses but it fails here
{
log.info "Status:Testcase passed"
}
ELSE {
testRunner.fail( runner.reason )
///////////////Database code not added yet.
}
Any help would be great.
Ab
I am very new to SOAPUI and I have come across a situation where I need to compare two XML Responses within a test case and if they do not match then log it to the database. After my research I found that there are two ways of doing it
1) Adding an Assertion ( Since I am using a SOAP UI PRO) - This was easy to setup however, I am unable to write the assertion results to a log ( in my case database)
2) So I went for a Groovy script - I have never worked with Groovy script before and I wanted some help in figuring out how to write code for it. below is the code I came up with so far but I get an error -
Code I used -
def LagacyResponse = context.expand( '${Legacy Call(app1)#Response#declare namespace ns1=\'com.rovicorp.metadataservice\'; //ns1:searchResponse[1]/ns1:results[1]/ns1:result[1]/ns1:id[1]}' )
def NewResponse = context.expand( '${New Call(app 2)#Response#declare namespace ns1=\'com.rovicorp.metadataservice\'; //ns1:searchResponse[1]/ns1:results[1]/ns1:result[1]/ns1:id[1]}' )
IF (LagacyResponse == NewResponse)-------------------Here I am comparing the two XML responses but it fails here
{
log.info "Status:Testcase passed"
}
ELSE {
testRunner.fail( runner.reason )
///////////////Database code not added yet.
}
Any help would be great.
Ab