Home > Testing > SoapUI – tips & tricks – part1

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 com.eviware.soapui.support.GroovyUtils( context );
def holder = groovyUtils.getXmlHolder( response );
holder.namespaces["ns"] = holder.getNodeValue("//namespace::*[2]"); // set the namespace
</br>
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:
${previousTestStepName#ResponseAsXML#//*:this/*:is/*:your/*:xpath/*:to/*:the/*:value}


Categories: Testing Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.