【问题标题】:Postman pm.response.to.have.header not working as expected邮递员 pm.response.to.have.header 没有按预期工作
【发布时间】:2018-11-11 18:33:57
【问题描述】:

第 1 部分

Postman 的测试示例包括此测试以查看是否存在标头:

pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});

我的响应标头包含以下内容:

Content-Type →application/json

我希望上面的测试能够通过,但它失败了。为什么? 它说:

FAIL  Content-Type is present | AssertionError: expected response to not have header with key 'Content-Type'

此外,由于上述测试失败,那么我希望这个否定测试成功,但它也失败了:

pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type");
});

上面写着:

FAIL  Content-Type is present | AssertionError: expected response to not have header with key 'Content-Type'

请注意,这是与上述完全相同的错误消息。他们都说“没有预期的反应”,这对我来说似乎是错误的。

第 2 部分

为了让整个体验更加混乱,测试 key 和 value 字符串是可行的。我对“have.header”有什么误解吗?

pm.test("Content-Type is present", function () {
    pm.response.to.have.header("Content-Type →application/json");
});

返回:

PASS  Content-Type is present

再一次,这个也通过了!

pm.test("Content-Type is present", function () {
    pm.response.to.not.have.header("Content-Type →application/json");
});

返回:

PASS  Content-Type is present

第 3 部分

帮助?!

【问题讨论】:

    标签: automated-tests postman


    【解决方案1】:

    我的问题似乎与这个错误有关:

    https://github.com/postmanlabs/postman-app-support/issues/3690

    “pm.response.to.not.be 导致后面的断言向后工作。”

    【讨论】:

      【解决方案2】:

      您现在可能已经完成了这项工作,但无论如何这对我来说是有效的:

      pm.test("Content Type is present", function () {
          pm.expect(pm.response).to.have.header("Content-Type");
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-08
        • 2014-08-20
        • 1970-01-01
        • 2021-10-19
        • 2020-03-18
        • 2012-06-14
        • 2014-11-15
        • 1970-01-01
        相关资源
        最近更新 更多