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
Add a ment  | 

1 Answer 1

Reset to default 4

I'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:

本文标签: javascriptPostman test throws quotTypeError Cannot read property 39get39 of undefinedquotStack Overflow