Reputation: 11
In SoapUI I am trying to read response xml and perform assert equals this is //my code
import com.eviware.soapui.support.XmlHolder
import com.eviware.soapui.support.*
responseHolder = groovyUtils.getXmlHolder
(
testRunner.testCase.testSteps["NDCIssueTKT"].testRequest.response.responseContent );
responseHolder.declareNamespace("ns1","http://TKT.svc")
CDATAXml = respXmlHolder.getNodeValue("//ns1:NDCIssueTKTResult")
log.info(CDATAXml)
CDATAXmlHolder = new XmlHolder(CDATAXml)
errorMSG = CDATAXmlHolder.getNodeValue("//description")
log.info("errorMSG = $errorMSG")
assert errMSG == propTestStep.getPropertyValue("Response")
but I get no such property exception, can anyone help?
EDIT: based on comments
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsd="w3.org/2001/XMLSchema" xmlns:xsi="w3.org/2001/XMLSchema-instance">
<NDCIssueTKTResponse xmlns="TKT.svc">
<NDCIssueTKTResult>
<err xmlns="web2200/webservices/">
<code>11000011</code>
<description>FBA ERROR: incorrect quantity.</description>
<level>200</level>
</err>
</NDCIssueTKTResult>
</NDCIssueTKTResponse>
</s:Body>
</s:Envelope>
Upvotes: 1
Views: 1908
Reputation: 21369
You can use Script Assertion for the same request step as shown below:
Script Assertion
//Check if the response is not null or empty
assert context.response, 'response is null or empty'
//Define the expected description
def expectedDescription = 'FBA ERROR: incorrect quantity.'
def pXml = new XmlSlurper().parseText(context.response)
def actualDescription = pXml.'**'.find {it.name() == 'description'}
assert actualDescription == expectedDescription, 'Description is not matching'
Similarly if you want to assert code
, do the following:
def expectedCode = 11000011
def actualCode = pXml.'**'.find {it.name() == 'code'}
assert actualCode == expectedCode, 'Code does not match'
You can quickly try online Demo
EDIT: based on the comment by OP.
Looks like you are using Groovy Script
Test step with a fixed value. If use Script Assertion
as suggested, you do not have to have additional test step that you have (groovy script step).
Upvotes: 1