Assert on XML fragment within a single XML element?
Hi,
I am using SoapUI to publish a SOAP POST request to a web service and I'm trying to create an assertion on the response
I've gotten used to SoapUI now and I didn't think this would be a problem, however, the XML response to my request includes XML for failures and successes all in one tag within a CDATA element which means I'm struggling to create an assertion on the content.
When I launch the XML option on the 'Response' for a Successful submission it appears as follows:
<Responses> <SyncSuccesses> <SyncSuccess SyncID="CV00B" DateTime="20170727080932GMT"/> </SyncSuccesses> <SyncErrors> </SyncErrors> </Responses>
Likewise when launch When I launch the XML option on the 'Response' for a Failed submission it appears as follows:
<Responses> <SyncSuccesses> </SyncSuccesses> <SyncErrors> <SyncError SyncID="CV00C" DateTime="20170727080932GMT"/> </SyncErrors> </Responses>
I need to be able to assert whether the request was a FAILURE or SUCCESSFUL - and normally because all the different elements would be on separate lines in the XML window in the 'Response' - I could do this - but because they're using a SOAP wrapper and the payload is all within one tag within a CDATA element - I don't know how to do this.
I've attached the genuine response XML so you can see what I mean about the CDATA element resulting in all the XML being contained within a single tag
Any help/guidance would be great - I've 2 days to work out how to do this, so I'd appreciate any and all comments if possible please!
Richie
Here's a groovy script that may help. Ultimately if you need to treat the //return field as XML to parse, I usually go with a groovy script assertion.
import com.eviware.soapui.support.XmlHolder def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ); // get the response, specifically the //RETURN element that contains DATA tags. This may need to be adjusted to fit your own project, but you want to collect the //return element def response = context.expand( '${TESTTSTEP#Response#declare namespace NS1=\'urn:SyncServicesIntf-ISyncServices\'; //NS1:SyncResponse[1]/return[1]}' ) // remove the CDATA tags response = response.replaceAll( "<!\\[CDATA\\[", "" ) response = response.replaceAll( "]]>", "" ) // Parse the response into XML def holder = groovyUtils.getXmlHolder( response ) log.info((holder["exists(//Responses/SyncSuccesses/SyncSuccess)"])); log.info(holder["count(//Responses/SyncErrors/SyncError)"]); def successExists = (holder["exists(//Responses/SyncSuccesses/SyncSuccess)"]); def errorCount = (holder["count(//Responses/SyncErrors/SyncError)"]).toInteger(); assert (successExists && errorCount == 0);