SoapUI – tips & tricks – part1

I’ve decided to group and share all the helper scripts/methods etc. that I’m using in SoapUI.
This time there are only 3 short hints but I hope they can be useful 🙂

Verify Content-Type of response message using script assertion:

String actual = new String(messageExchange.responseHeaders["Content-Type"].getAt(0).toString())
String expected = "application/json";
assert actual.equals( expected ), "Actual Content-Type: '" + actual + "' does not match expected: '" + expected + "'";

To access body of the response message as XML in script assertion (this method will also transform JSON into XML):

def response = messageExchange.getResponse().getContentAsXml();
def groovyUtils = new context );
def holder = groovyUtils.getXmlHolder( response );
holder.namespaces["ns"] = holder.getNodeValue("//namespace::*[2]"); // set the namespace
def valuesYouWantToGetUsingXPath = holder.getNodeValues( "//ns:list/ns:item/ns:description" ); // get all descriptions
def valueYouWantToGetUsingXPath = holder.getNodeValue( "//ns:list/ns:item[id=1]/ns:description" ); // get specific description

To quickly access the response from different test step as XML and using XPath: