空手道xml bodyPath在模拟中未匹配:方案匹配评估失败

时间:2019-12-19 17:26:17

标签: 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: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>

和模拟:

  Scenario: pathMatches('<path>') && requestHeaders['SOAPAction'][0] == '<soapAction>' && bodyPath('/ns1:customerQualificationRequest/ns1:creditApplication/ns1:lastName') == 'Shopping'

如果我只是删除bodyPath,但没有找到与bodyPath匹配的内容,则可以使用。我需要在几种情况下,lastName不同,因为答案会有所不同,因此我需要与该参数匹配。 我在做什么错了?

2 个答案:

答案 0 :(得分:1)

经过一段时间的努力,我找到了答案。以下工作: && bodyPath('/信封/正文/ customerQualificationRequest / creditApplication / lastName')

答案 1 :(得分:0)

我希望XML更简单。这是我刚想到的。您可以在XML上使用Json-Path,有时效果更好。举个例子(正常的空手道测试,不是模拟的):

create

这意味着它应该起作用:

update

由于比较笨拙,您可以在* def req = """ <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <ns1:customerQualificationRequest> <ns1:creditApplication> <ns1:lastName>Shopping</ns1:lastName> </ns1:creditApplication> </ns1:customerQualificationRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope> """ * def temp = karate.get('$req..ns1:lastName') * match temp == ['Shopping'] 中定义一个自定义函数:

bodyPath('$..ns1:lastName').length > 0 && bodyPath('$..ns1:lastName')[0] == 'Shopping'

然后:

Background