admin管理员组文章数量:1312651
How do I make it work?
Goal: call a variable inside test script
Test script:
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"));
});
The error:
Error: TypeError: Cannot read property 'get' of undefined
How do I make it work?
Goal: call a variable inside test script
Test script:
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"));
});
The error:
Error: TypeError: Cannot read property 'get' of undefined
Share
Improve this question
edited Apr 10, 2018 at 10:50
31piy
23.9k6 gold badges51 silver badges68 bronze badges
asked Apr 10, 2018 at 10:49
SunguresatSunguresat
6332 gold badges7 silver badges11 bronze badges
1
- Wrong problem statement I suppose. I want to create a variable and assign it a value "Unknown Error" then assert response body that under Errors > Title has value of my variable, how would a test script look like? – Sunguresat Commented Apr 10, 2018 at 11:07
1 Answer
Reset to default 4I'm not sure where you have found pm.errors.get
as a function that you can use but I don't believe it is something that is within Postman.
All the sandbox functions can be found here https://www.getpostman./docs/v6/postman/scripts/postman_sandbox_api_reference
If you are just looking to assert that jsonData.results[0].errors.title
equals a string value, you could just do this:
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"))
})
If you set a global
variable you can reference in the test like this:
版权声明:本文标题:javascript - Postman test throws "TypeError: Cannot read property 'get' of undefined" - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741918597a2404874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论