xml响应中的Postman断言变量

时间:2018-10-24 20:57:27

标签: json xml api postman postman-collection-runner

我发送了POST请求并得到了rsoponse

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
    <ns1:createShipmentsResponse>
    <return xsi:type="ns1:CreateShipmentsResponses">
        <responses xsi:nil="true"/>
        <status xsi:type="ns1:statusEnum">Error</status>
        <message xsi:type="ns1:Message">
            <code xsi:type="xsd:string">G0102</code>
            <content xsi:type="ns1:ansi255">102 Country code seems not to be supported by our system. Please contact administrator.</content>
        <uid xsi:type="xsd:string">39</uid>
        </message>
    </return>
    </ns1:createShipmentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

现在,我尝试添加一个断言,该断言将从响应中检查状态。

var jsonObject = xml2Json(responseBody);
var status = jsonObject['SOAP-ENV:Envelope']['SOAP-ENV:Body']['ns1:createShipmentsResponse']['return']['status'];

tests["Check Return Status"] = status === "Error";

我的测试失败,并带有注释:检查退货状态| AssertionError:期望为假的是真实的

0 个答案:

没有答案