cancel
Showing results for 
Search instead for 
Did you mean: 

Create a script assertion with groovy script

SOLVED
sfr
New Contributor

Create a script assertion with groovy script

how can we create a script assertion with groovy script ?

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Re: Create a script assertion with groovy script

This is a really vague question and one probably more suited to reading the SoapUI Guides.

 

That said, you have a number of of options, you can add a script assertion to the test step itself or you could create a Groovy test step to script one or many assertions.

 

Below is a really simplistic assertion that is bound to the test step itself....

 

import com.eviware.soapui.support.XmlHolder

// Grab the response from the step itself as XML
def holder = new XmlHolder( messageExchange.responseContentAsXml )

// You need to define the namepsace and you should be able to find this is in the reponse.
holder.namespaces["ns3"] = "urn:someorg:domain:1"

// Grab the node of interest from the XML Holder
def node = holder.getDomNode( "//ns3:customerInfo[1]/ns3:surname[1]" );

// Quick check to make sure the value exists
assert node != null

// Pull out the surname
def surname= holder.getNodeValue( "//ns3:customerInfo[1]/ns3:surname[1]" );

// Make your assertion
assert (surname.contains('Smith'));

 

3 REPLIES 3
Occasional Contributor

Re: Create a script assertion with groovy script

This is a really vague question and one probably more suited to reading the SoapUI Guides.

 

That said, you have a number of of options, you can add a script assertion to the test step itself or you could create a Groovy test step to script one or many assertions.

 

Below is a really simplistic assertion that is bound to the test step itself....

 

import com.eviware.soapui.support.XmlHolder

// Grab the response from the step itself as XML
def holder = new XmlHolder( messageExchange.responseContentAsXml )

// You need to define the namepsace and you should be able to find this is in the reponse.
holder.namespaces["ns3"] = "urn:someorg:domain:1"

// Grab the node of interest from the XML Holder
def node = holder.getDomNode( "//ns3:customerInfo[1]/ns3:surname[1]" );

// Quick check to make sure the value exists
assert node != null

// Pull out the surname
def surname= holder.getNodeValue( "//ns3:customerInfo[1]/ns3:surname[1]" );

// Make your assertion
assert (surname.contains('Smith'));

 

Highlighted
Community Hero

Re: Create a script assertion with groovy script

It would be helpful if you are specific about the problem.

If it is generic, please refer documentation or watch available videos.


Regards,
Rao.
Community Manager

Re: Create a script assertion with groovy script

Hi @sfr,

 

Did the suggestions given here help you find a solution?

If you are still looking for an assistant, please clarify your request.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
Top Kudoed Authors