How to extract a value from a SOAP response
I am new with SoapUI tool. I need to extract the values of "resultOperation" and "errorCode" from the following SOAP response:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Mon, 08 Apr 2019 09:49:47 GMT
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:processRequestResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://services.ni.devoteam.vpg.com">
<processRequestReturn href="#id0"/>
</ns1:processRequestResponse>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:NIResponse" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="urn:server.ws.ni.vpg.devoteam.com">
<resultOperation xsi:type="xsd:string">0</resultOperation>
<errorCode xsi:type="xsd:string">0</errorCode>
<errorDescription xsi:type="xsd:string">Operazione eseguita con successo</errorDescription>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
Thanks
Massimo
You may use below Script Assertion:
assert context.response, 'Response is empty or null' def xml = new XmlSlurper().parseText(context.response) def getElementValue = { element -> xml.'**'.find{element == it.name()}?.text() } log.info 'resultOperation value is ' + getElementValue('resultOperation') log.info 'errorCode value is ' + getElementValue('errorCode')
Here is the script which you can play and test it online with fixed response.