如何通过这个邮递员脚本测试?

how to pass this postman script test?

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")

get single workspace | AssertionError: expected { Object (id, _details, ...) } to have property 'code' of 200, but got 401

get single collection | AssertionError: expected { Object (id, _details, ...) } to have property 'code' of 200, but got 401

get single environment | AssertionError: expected { Object (id, _details, ...) } to have property 'code' of 200, but got 401

看起来您需要确保您的 API 请求得到正确验证,以便您得到 200 响应而不是 401,这意味着您无权发出请求。

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

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

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


Learn more about the response status codes

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