0
votes

everybody!

Using SoapUI 5.2.1 and Groovy TestCase has 2 Test Steps:

  1. SOAP Request "create"
  2. Groovy Script

Inside the request:

<soapenv:Envelope ... >
 <soapenv:Header/>
 <soapenv:Body>
  <ban:transactions>
   <session>x</session>
   <type>y</type>
  </ban:transactions>
 </soapenv:Body>
</soapenv:Envelope ... >

Inside script:

def xml = context.expand('${create#request#//ban:transactions}')

This script returns:

  <ban:transactions>
   <session>x</session>
   <type>y</type>
  </ban:transactions>

What should i change in script, so that script could return me:

   <session>x</session>
   <type>y</type>
1
What are you trying to achieve? How are you going to use that data? - Rao
@Rao, i need that child node, because i'm going to compare it with the repeat transation, which has different parent tags - not <ban:transactions>, but <ban:scheme> - Nikita Rysin
Are you comparing one response with another? what is the use case? - Rao
Yes. So, we create transaction and want to repeat this transaction. My use case is to compare both - has back-end worked correctly and the tags are equal or not, because sometimes developers forgets to add different tags to repeat operation. For example, dev forgot to add <type>y</type> to response of repeat - Nikita Rysin

1 Answers

0
votes

Suppose your XML is and we will extract the data under the nodes body

<Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<hello>oye1</hello>
<ok>test</ok>
 <hello>oye2</hello>
<ok>test2</ok>
</Body>
</Envelope>

The groovy code below can extract the nodes from an xml mentioning the node above it. So here we are trying to extract the nodes under tag

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder("testStepName#Response")
def  responseXml=holder.getXmlObject()
String xmlObj=responseXml.toString()
String [] responseXmlObj=xmlObj.split('<Body>')[1].split('</Body>')
log.info responseXmlObj[0]

output will come as

Thu Nov 23 12:38:05 GMT+05:30 2017:INFO:
<hello>oye1</hello>
<ok>test</ok>
<hello>oye2</hello>
<ok>test2</ok>

you will need to change testStepName with the name of the step which has the response