Hi, can you please help me to resolve this issue on newman. This is the error that i’m getting in newman: TypeError: Cannot read properties of undefined (reading 'id') at test-script
compared to postman runner, I do not encounter this issue, only when running to newman.
This is the postman tests that I created
const jsonData = pm.response.json();
var response = pm.response.json();
pm.collectionVariables.set("vesselAccountingId", jsonData.data.id);
pm.collectionVariables.set("vesselName", jsonData.data.vesselName);
pm.test("C28806 Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("C28806 Response time is less than 2000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(2000);
});
pm.test("C28806 Response data for endOfTermReason=0", function () {
pm.expect(response.data.endOfTermReason).to.eql(0);
});
console.log(responseBody);
I already added CONST and VAR but nothing works.
I’m using the same test on my other tests but this issue only occurs in this post request
I’ve already tried to update newman to latest version, still not working.
Tried to change the variabl from collection to environment, still not working.
now the error do not show in post request anymore, but in put request i can still encounter the error, this is my tests
const jsonData = pm.response.json();
console.log(jsonData.data.endOfTermReason);
pm.collectionVariables.set("endOfTermReason", jsonData.data.endOfTermReason);
console.log(pm.collectionVariables.get("endOfTermReason"));
pm.test("C28806 Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("C28806 Response time is less than 2000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(2000);
});
pm.test("C28803 Response data for endOfTermReason not 0", function () {
pm.expect(jsonData.data.endOfTermReason).to.not.eql(0);
});
What is the console logs showing? Is it “undefined” or 1?
Based on your example response, the code looks fine to me so the next steps are checking the log files.
First in Postman, then in Newman.
Are you sure the response is coming back ok in Newman first? Console log the entire response as the first troubleshooting step. (jsonData in your example). Do it at the top just after you define the response before you do anything else.
Can you console log the entire response as the first step, and ensure that the response is returning properly as I can’t see a problem on face value with your targeting of the endOfTermReason element.
I would also recommend removing all other code from the tests tab, and build it back up line by line, so you can work out exactly which line is failing (which means removing the tests to start with and just having a bunch of console logs before adding the tests back in one by one).