在SoapUI中我试图读取响应xml并执行assert equals这是//我的代码
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")
但我没有这样的财产例外,有人可以帮忙吗?
编辑:基于评论
<?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>
答案 0 :(得分:1)
您可以将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'
同样,如果要断言code
,请执行以下操作:
def expectedCode = 11000011
def actualCode = pXml.'**'.find {it.name() == 'code'}
assert actualCode == expectedCode, 'Code does not match'
您可以快速在线试用 Demo
编辑:根据OP的评论
看起来您正在使用具有固定值的Groovy Script
测试步骤。如果按照建议使用Script Assertion
,则不必执行其他测试步骤(groovy脚本步骤)。