Skip to main content

Posts

Showing posts from May, 2022

Want to auto retry a failing request in postman based on a set number of max tries and with a certain amount of wait time?

  Of course, there are many ways to tackle it but I have mentioned below one of the ways where you can use the given code in the Tests tab of the postman. Unfortunately, in some of the lower environments, there can be a situation where you request fail at times due to infra issues, timeouts, etc., so in that case, this can be super helpful: var notExpectedText = 'Failed'; var maxTries = 3; var pauseBetweenTries = 5000; if (!pm.environment.get("tries")) {     pm.environment.set("tries", 1); } if ((pm.expect(pm.response.text()).to.not.include(notExpectedText)) && (pm.environment.get("tries") < maxTries)) {      var tries = parseInt(pm.environment.get("tries"), 10);      pm.environment.set("tries", tries + 1);      setTimeout(function() {}, pauseBetweenTries);      postman.setNextRequest('PaymentService'); //here you should give your request name that you want to retry on failure  } else {      pm.environment.uns