SoapUI-如何从响应中断言
我是 SoapUI 新手,我有一个基本问题。当我收到对服务的响应时,我想对某个值进行断言。下面是我在脚本断言下创建的脚本
import com.eviware.soapui.support.XmlHolder
def holder = new XmlHolder(messageExchange.responseContentAsXml)
assert holder["//ConstraintId[0]"] =="5000006";
I get the following error:
assert holder["//ConstraintId[0]"] =="5000006" | | | | [] false com.eviware.soapui.support.XmlHolder@8b6500 (toString() threw java.lang.NullPointerException)
**********************************************************
import org.xml.sax.helpers.DefaultHandler
def rootNode = new XmlSlurper().parseText(messageExchange.responseContentAsXml)
assert rootNode.Body.Constraintid[0].text=="5000006";
I get the following error:
assert rootNode.Body.Constraintid[0].text=="5000006" | | | | | | | | | | | false | | | | groovy.util.slurpersupport.NodeChildren@17a5c01 (toString() == "") | | | groovy.util.slurpersupport.NoChildren@2e80e1 (toString() == "") | | groovy.util.slurpersupport.NodeChildren@10f682f (toString() == "") |
Response
<soap:Body>
<GetEnumResponse xmlns="http://www.xyz.com/">
<GetEnumResult>
<ErrorCode>0</ErrorCode>
<StatusId>0</StatusId>
</GetEnumResult>
<enumsInformation>
<EnumInformation>
<TransactionId>0</TransactionId>
<ConstraintId>5000006</ConstraintId>
<EnumValue>abc</EnumValue>
<Index>10</Index>
</EnumInformation>
</enumsInformation>
</GetEnumResponse>
</soap:Body>
I am new to SoapUI I have a basic question. When i get a response to a services i would like to do an assert for a value. below is scripts i had created under Script Assertion
import com.eviware.soapui.support.XmlHolder
def holder = new XmlHolder(messageExchange.responseContentAsXml)
assert holder["//ConstraintId[0]"] =="5000006";
I get the following error:
assert holder["//ConstraintId[0]"] =="5000006" | | | | [] false com.eviware.soapui.support.XmlHolder@8b6500 (toString() threw java.lang.NullPointerException)
**********************************************************
import org.xml.sax.helpers.DefaultHandler
def rootNode = new XmlSlurper().parseText(messageExchange.responseContentAsXml)
assert rootNode.Body.Constraintid[0].text=="5000006";
I get the following error:
assert rootNode.Body.Constraintid[0].text=="5000006" | | | | | | | | | | | false | | | | groovy.util.slurpersupport.NodeChildren@17a5c01 (toString() == "") | | | groovy.util.slurpersupport.NoChildren@2e80e1 (toString() == "") | | groovy.util.slurpersupport.NodeChildren@10f682f (toString() == "") |
Response
<soap:Body>
<GetEnumResponse xmlns="http://www.xyz.com/">
<GetEnumResult>
<ErrorCode>0</ErrorCode>
<StatusId>0</StatusId>
</GetEnumResult>
<enumsInformation>
<EnumInformation>
<TransactionId>0</TransactionId>
<ConstraintId>5000006</ConstraintId>
<EnumValue>abc</EnumValue>
<Index>10</Index>
</EnumInformation>
</enumsInformation>
</GetEnumResponse>
</soap:Body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
能够找到解决方案。命名空间在使用 getNodeValue 之前声明。
Was able to find the solution. Namespace is decalared before using getNodeValue.