How can I stop test immediately or set timeout while testing

So we have the need sometimes to wait for processing between calls in some of our tests or in the case of a failed call, retry. In those cases we do something like this:

if (responseCode.code === 200) {
        // Delay for 60 Seconds (set in milliseconds)
        setTimeout(function(){}, 60000);
}
else
{
        // Retry the call again
        postman.setNextRequest("CreateData");
}

So basically this would be housed in my Tests tab but it simply checks the response code, if its what we want then wait 60 seconds before proceeding to the next call.
Otherwise retry the call because for some reason it was not successful. There is also some logic you can add in here to retry X times and then stop the run or do some other action based on this outcome, because there is a chance you could get into an endless loop. For this example I kept it simple.

Hope this helps.

1 Like