【问题标题】:how to pass this postman script test?如何通过这个邮递员脚本测试?
【发布时间】:2021-10-26 15:23:50
【问题描述】:
pm.test('get single collection', () => {
    pm.expect(error).to.equal(null);
    pm.expect(response).to.have.property('code', 200);
    pm.expect(response).to.have.property('status', 'OK');
    pm.expect(response.json().collection.auth.type, 'check collection authorization').to.equal("apikey")

获取单个工作区 | AssertionError: 预期 { Object (id, _details, ...) } 的属性“代码”为 200,但得到了 401

获取单个集合 | AssertionError: 预期 { Object (id, _details, ...) } 的属性“代码”为 200,但得到了 401

获取单一环境 | AssertionError: 预期 { Object (id, _details, ...) } 的属性“代码”为 200,但得到了 401

【问题讨论】:

    标签: javascript postman postman-collection-runner


    【解决方案1】:

    您似乎需要确保您的 API 请求经过正确身份验证,以便您收到 200 响应而不是 401,这意味着您未经授权提出请求。

    这是失败的断言,因为它期望响应代码为 200 - 成功,但根据您的错误,您将得到 401 - 未授权

     pm.expect(response).to.have.property('code', 200);
    

    如果您成功验证了您的请求,您的测试应该会通过。


    Learn more about the response status codes

    【讨论】:

      【解决方案2】:

      您需要从授权选项卡发送授权详细信息,如下图所示。

      【讨论】:

        猜你喜欢
        • 2017-02-21
        • 2019-04-23
        • 2021-01-16
        • 2019-10-26
        • 2020-06-30
        • 1970-01-01
        • 1970-01-01
        • 2020-07-13
        • 1970-01-01
        相关资源
        最近更新 更多