此测试pm.expect(jsonData.payload.invitationStatus == "A");
的工作与invitationStatus
实际包含的值无关。
即payload.invitationStatus = E
将通过测试。
如何使它仅在值为A时通过?
以下是有效负载的几个示例:
{
"payload": {
"buyer": "",
"error": "E",
"invitationStatus": "E",
"supplier": "",
"terms": ""
}
}
{
"payload": {
"buyer": "omitted omitted",
"error": "S",
"invitationStatus": "A",
"supplier": "ABC Supplier",
"terms": ""
}
}
这是测试本身:
// Setters
let jsonData = JSON.parse(responseBody);
// Testers
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Invitation status is A", function () {
if(jsonData.payload) {
pm.expect(jsonData.payload.invitationStatus == "A");
} else {
throw new Error("Unexpected structure");
}
});
答案 0 :(得分:0)
我不确定==
为何不起作用,但这pm.expect(jsonData.payload.invitationStatus).to.eql("A");
有用
这里是其他邮递员测试示例的好资源https://www.getpostman.com/docs/v6/postman/scripts/test_examples