Thanks for this template @chrissbaumann (cc @postman-paul540) - This is just what I have been looking for! I linked this new thread outside of the “showcase” category as I’ve having some issues.
I’m looking to use it (with a small tweak) that also changes one of my request variables - specifically setting a boolean from FALSE
to TRUE
in the event of my most common error: 422. (A 201 is my sucessful “Service Entry Created” response).
From doing a few collection runner tests - it seems my setNextRequest
is not initiating, but I’m not 100% - still getting the hang of this and learning as I go.
If anyone can spot check me here and give a bit of guidance on this test script, I’d really appreciate it!
Thank you!
Here is my test script as currently written:
// Retry if the request fails (422) and correct for commonly seen mileage error issue:
var expectedHttpStatus = 201;
var maxNumberOfTries = 3;
var sleepBetweenTries = 250;
if (!pm.environment.get("tries")) {
pm.environment.set("tries", 1);
}
if ((pm.response.code != 201) && (pm.environment.get("collection_tries") < maxNumberOfTries)) {
var tries = parseInt(pm.environment.get("tries"), 10);
pm.environment.set("tries", tries + 1);
setTimeout(function() {}, sleepBetweenTries);
// ** Addition - unset and change odometer_valid variable **
pm.variable.unset("odometer_valid");
pm.variable.set("meter_entry_attributes[void]", "TRUE");
postman.setNextRequest('Create Service Entry & Line Item(s)');
} else {
pm.environment.unset("tries");
pm.test("Status code is " + 201, function () {
pm.response.to.have.status(201);
});
}