Sun*_*sat 5 javascript postman
我如何使它工作?
目标:在测试脚本中调用一个变量
测试脚本:
pm.test("shipment registration not allowed", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.results[0].errors.title).to.eql(pm.errors.get("shipmentRegistrationNotAllowed"));
});
Run Code Online (Sandbox Code Playgroud)
错误:
Error: TypeError: Cannot read property 'get' of undefined
Run Code Online (Sandbox Code Playgroud)
我不确定您在哪里找到了pm.errors.get可以使用的功能,但我不相信它是 Postman 中的东西。
所有沙箱功能都可以在这里找到https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference
如果您只是想断言它jsonData.results[0].errors.title等于字符串值,您可以这样做:
pm.test("shipment registration not allowed", () => {
var jsonData = pm.response.json()
pm.expect(jsonData.results[0].errors.title).to.eql(pm.globals.get("my_error_value"))
})
Run Code Online (Sandbox Code Playgroud)
如果您设置一个global变量,您可以在测试中引用,如下所示:
| 归档时间: |
|
| 查看次数: |
11403 次 |
| 最近记录: |