【问题标题】:Postman Tests: Assert several possible response statuses邮递员测试:断言几种可能的响应状态
【发布时间】:2017-11-29 22:02:46
【问题描述】:

在 Postman 中测试时,可以使用pm.response.to.have.status(200) 断言响应状态应为 200。

有没有简单的方法来断言多个状态?我试过pm.response.to.have.status(200||404),但没用。

我正在查看Postman Sandbox API Reference,似乎没有直接的解决方案,尽管也许可以解决一些问题。

由于它相当奇怪,我将解释为什么我想要这个:它是一个 DELETE 请求,它将为以后的请求标准化数据库,我不在乎返回哪个,只要它是 200 或 404。

【问题讨论】:

    标签: testing postman


    【解决方案1】:

    (It's OK to Ask and Answer Your Own Questions)

    test examples找到一个例子:

    pm.test("Successful POST request", function () {
        pm.expect(pm.response.code).to.be.oneOf([201,202]);
    });
    

    在我的情况下,它会像

    pm.test("Previous DELETE request", function () {
        pm.expect(pm.response.code).to.be.oneOf([200,404]);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 2019-01-12
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      相关资源
      最近更新 更多