Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  164] [ 7]  / answers: 1 / hits: 15149  / 6 Years ago, tue, april 10, 2018, 12:00:00

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

More From » postman

 Answers
29

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.com/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:



enter


[#54704] Saturday, April 7, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loric

Total Points: 110
Total Questions: 96
Total Answers: 91

Location: Estonia
Member since Wed, Jun 8, 2022
2 Years ago
;