最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to test for multiple acceptable status codes in Postman? - Stack Overflow

programmeradmin9浏览0评论

I have an endpoint that can return a status code 200 or 400 depending the time of day.
How would I go about creating a test that can check for either of them?

In the test snippets, there is a test that would assert one status code:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

But, this is only for one status code.
How could it be adapted to assert multiple acceptable status code?

I have an endpoint that can return a status code 200 or 400 depending the time of day.
How would I go about creating a test that can check for either of them?

In the test snippets, there is a test that would assert one status code:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

But, this is only for one status code.
How could it be adapted to assert multiple acceptable status code?

Share Improve this question edited Mar 12 at 19:49 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Mar 16, 2018 at 4:39 matias90matias90 2231 gold badge2 silver badges4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 35
pm.test('Check status code', () => {
    pm.expect(pm.response.code).to.be.oneOf([200, 400])
})

That’s a quick example of a test that would check to see if the status code was either 200 or 400.

发布评论

评论列表(0)

  1. 暂无评论