My question:
I am triggering the postman collection with Prerequest script for that collection. In that Pre request script, tried the logic to retry when any unexpected status code got. but getting error(TypeError: Cannot read properties of undefined (reading ācodeā) ) when running the script.
Details (like screenshots):
Prerequest script for collection:
Script:
var maxNumberOfTries = 3;
var sleepBetweenTries = 5000;
if (!pm.environment.get(ācollection_triesā)) {
pm.environment.set(ācollection_triesā, 1);
}
if ((pm.response.code != 200) && (pm.environment.get(ācollection_triesā) < maxNumberOfTries)) {
var tries = parseInt(pm.environment.get(ācollection_triesā), 10);
pm.environment.set(ācollection_triesā, tries + 1);
setTimeout(function() {}, sleepBetweenTries);
postman.setNextRequest(request.name);
}else if ((pm.response.code != 201) && (pm.environment.get(ācollection_triesā) < maxNumberOfTries)) {
var tries = parseInt(pm.environment.get(ācollection_triesā), 10);
pm.environment.set(ācollection_triesā, tries + 1);
setTimeout(function() {}, sleepBetweenTries);
postman.setNextRequest(request.name);
}else if ((pm.response.code !=204) && (pm.environment.get(ācollection_triesā) < maxNumberOfTries)) {
var tries = parseInt(pm.environment.get(ācollection_triesā), 10);
pm.environment.set(ācollection_triesā, tries + 1);
setTimeout(function() {}, sleepBetweenTries);
postman.setNextRequest(request.name);
}
else {
pm.environment.unset("collection_tries");
pm.test("Successful request", () => {
pm.expect(pm.response.code).to.be.oneOf([200,201,204]);
});
}