Postman 基于arrayElement响应的JSON验证检查
我想从响应格式检查status=AVAILABLE,然后arrayElement应返回roomTypeId,否则roomTypeId不应返回其他状态Postman 基于arrayElement响应的JSON验证检查,postman,postman-testcase,Postman,Postman Testcase,我想从响应格式检查status=AVAILABLE,然后arrayElement应返回roomTypeId,否则roomTypeId不应返回其他状态 [ { “状态”:“索尔多”, “属性ID”:“dc00e77f”, “费用”:0, “isComp”:false }, { “roomTypeId”:“c5730b9e”, “状态”:“可用”, “属性ID”:“dc00e77f”, “价格”:{ “基准平均价格”:104.71, “折扣平均价格”:86.33 }, “费用”:37, “isCo
[
{
“状态”:“索尔多”,
“属性ID”:“dc00e77f”,
“费用”:0,
“isComp”:false
},
{
“roomTypeId”:“c5730b9e”,
“状态”:“可用”,
“属性ID”:“dc00e77f”,
“价格”:{
“基准平均价格”:104.71,
“折扣平均价格”:86.33
},
“费用”:37,
“isComp”:false
},
]
您需要检查该属性是否存在
通过have.property
语法,您可以做到这一点
你可以阅读,而且
更新脚本:
pm.test("Verify if Status is SOLDOUT, roomTypeId and price information is not returned ", () => {
var jsonData = pm.response.json();
jsonData.forEach(function(arrayElement) {
if (arrayElement.status === "SOLDOUT") {
pm.expect(arrayElement).to.not.have.property("roomTypeId");
} else if (arrayElement.status === "AVAILABLE") {
pm.expect(arrayElement).to.have.property("roomTypeId");
}
});
});