模拟中未匹配空手道xml bodyPath:场景匹配评估失败
这是请求的外观:模拟中未匹配空手道xml bodyPath:场景匹配评估失败,xml,soap,mocking,karate,Xml,Soap,Mocking,Karate,这是请求的外观: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" ... <SOAP-ENV:Header> <ns2:Security SOAP-ENV:mustUnderstand="1"> <ns2
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
...
<SOAP-ENV:Header>
<ns2:Security SOAP-ENV:mustUnderstand="1">
<ns2:UsernameToken>
...
</ns2:UsernameToken>
</ns2:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:customerQualificationRequest>
<ns1:header>
...
</ns1:header>
<ns1:creditApplication>
...
<ns1:lastName>Shopping</ns1:lastName>
...
</ns1:creditApplication>
</ns1:customerQualificationRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我真希望XML更简单。这是我刚想到的。可以在XML上使用Json路径,有时效果更好。举个例子(普通空手道测试,非模拟):
由于这很笨重,您可以在背景中定义自定义函数:
Background:
* def getLastName = function(){ var temp = karate.get('$request..ns1:lastName'); return temp.length > 0 ? temp[0] : null }
然后:
getLastName() == 'Shopping'
经过一段时间的努力,我找到了答案。以下方面发挥了作用:
&&bodyPath('/Envelope/Body/customerQualificationRequest/creditApplication/lastName')bodyPath('//ns1:customerQualificationRequest/ns1:creditApplication/ns1:lastName')
可以通过选择所有customerQualificationRequest
标记来工作,无论它们在XML文档中的何处。指定从根开始的具体路径-/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:customerQualificationRequest/ns1:creditApplication/ns1:lastName
-是一种“更安全”的方法。不过,在这两种情况下,都必须有一种方法来指定标记前缀的名称空间(xmlns
)(ns1
,SOAP-ENV
)
bodyPath('$..ns1:lastName').length > 0 && bodyPath('$..ns1:lastName')[0] == 'Shopping'
Background:
* def getLastName = function(){ var temp = karate.get('$request..ns1:lastName'); return temp.length > 0 ? temp[0] : null }
getLastName() == 'Shopping'