【发布时间】:2019-07-19 00:21:56
【问题描述】:
我想检查答案是否正常。响应码为 200 或 500 时要么正确,要么正确。后者需要区分响应正文中的 String 是正确还是不正确。它应该在一个测试中。
我已经尝试过简单的 if 子句,但它们不起作用。
pm.test("response is ok", function(){
if(pm.response.to.have.status(200)){
//do things
}
});
编辑:
我使用的解决方案是
pm.test("response is valid", function(){
if(pm.response.code === 200){
//is ok
} else if (pm.response.code === 500){
if(pm.expect(pm.response.json().message).to.include("xyz")){
//is ok
} else {
pm.expect.fail("Error 500");
}
} else {
pm.expect.fail("statuscode not 200 or 500");
}
});
【问题讨论】:
标签: javascript http testing http-status-code-404 postman