I am checking the status of a previous request in a post-response script. Is there any way that I can I set some delay if the previous step has not finished yet and I want to wait, let’s say, 5 seconds? This delay is set inside a loop that after ten attempts will throw a timeout and stop.
Yes, this is definitely doable—Postman runs on JavaScript behind the scenes, so you can use JavaScript features like setTimeout.
Instead of throwing an exception, a simpler approach is to create a variable at the top of your script (maybe call it success) and set it to false to start with.
Then, as your loop runs, if you get the expected status at any point, you can update that variable to true.
At the end of your script, you can add a proper test that checks the value of that variable. This will then show any failures in the tests results tab. If you’re running this as part of a collection and want to stop the whole thing when the condition is not met, you can use postman.setNextRequest(null) to halt further execution.
Quick question—how are you currently checking the status? Are you using pm.sendRequest() or looping with setNextRequest()?
If you can share your current code (feel free to redact any sensitive bits), I’ll be able to give you a more tailored example instead of just general advice.