richie
8 years agoCommunity Hero
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 p...
- 8 years ago
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);