Reputation: 15
If I have the following response in Soap UI:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ConvertTempResponse xmlns="http://www.webserviceX.NET/">
<ConvertTempResult>40</ConvertTempResult>
</ConvertTempResponse>
</soap:Body>
</soap:Envelope>
I'm able to get the entire response copied to a text file using:
//create folder and file.
createFolder = new File("C:/SOAPUI")
createFolder.mkdir()
file = new File("C:/SOAPUI/test.txt")
file.createNewFile()
a = testRunner.testCase.getTestStepByName("Property Transfer")
responsedata = a.getProperty('transfer')
file.write(responsedata)
How do I get data for specific node copied. For example, If need '40' copied only. How can I achieve that?
Upvotes: 1
Views: 2212
Reputation: 18517
You can use an XmlHolder and then apply XPath to get the node value, see the code below:
//create folder and file
createFolder = new File("C:/SOAPUI")
createFolder.mkdir()
file = new File("C:/SOAPUI/test.txt")
file.createNewFile()
a = testRunner.testCase.getTestStepByName("Property Transfer")
responsedata = a.getProperty('transfer')
// create an XmlHolder
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
// get the response as string
def responseAsString = responsedata.getProperty('response').getValue()
def xml = groovyUtils.getXmlHolder(responseAsString)
// get the node value
def nodeValue = xml.getNodeValue("//*:ConvertTempResult")
log.info nodeValue;
file.write(nodeValue)
Hope this helps,
Upvotes: 3