我正在使用Wiremocks创建案例,并且正在生成响应模拟。Xpath验证wiremock matchesXPath表达式
我有一个这样的XML请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xw="http://example.com">
<soapenv:Header/>
<soapenv:Body>
<xw:gen>
<xw:input>
<xw:element1>0100</xw:element1>
<xw:element2>741</xw:element2>
<xw:element3>JAVA</xw:element3>
<xw:element4>123</xw:element4>
</xw:input>
<xw:global>
<xw:obj1>
<xw:attr1>john</xw:attr1>
<xw:attr2>doe</xw:attr2>
</xw:obj1>
</xw:global>
</xw:gen>
</soapenv:Body>
</soapenv:Envelope>
我只需要验证XW:输入/ XW:元素1 = 0100,XW:输入/ XW:在element2 = 741和我需要那个节点有什么东西。 xw:global的唯一条件不是空的。 (该节点可以是<xw:global></xw:global>
)。
这是我在JSON模拟:
{
"request" : {
"url" : "/myweb/myrequest.asmx",
"headers": {
"SOAPAction": {
"equalTo": "\"http://example.com/gen\""
}
},
"bodyPatterns" : [ {
"matchesXPath": "//xw:input[xw:element1=\"0100\" and xw:element2=\"741\" ]",
"xPathNamespaces" : {
"xw" : "http://example.com"
}
}]
},
"response" : {
"status" : 200,
"headers": {
"Content-Type": "text/xml;charset=UTF-8"
},
"body" : "<Abody>"
}
}
的问题是:我怎么能验证该节点XW:全球不为空或不为空?
我试着用这个matchesXPath,但我没有运气:
"matchesXPath": "//xw:input[xw:element1=\"0100\" and xw:element2=\"741\" ] and count(//xw:global) > 0"
。
谢谢。
您是否在存根定义中指定了命名空间?如果不是,那么你不能在XPath表达式中使用它们。 – Tom
是的。我指定了命名空间。谢谢。 – dani77