I use Collection Runner with 1000 iterations. I want to be able to stop (short circuit) from a test script. If I do postman.setNextRequest(null) only stops current iteration and moves to next iteration but I want to stop runner completely.
I also need a workaround for this as well.
I am at a loss as to why is this so difficult to implement. Multiple posts got closed by Postman employees with the setNextRequest(null) explanation, while clearly not understanding the issue.
I’m using Postman 11 with the new pm.execution.setNextRequest(null) method and that doesn’t seem to be working either when using the runner.
Not sure if it’s because I’m using nested Folders, but It’s worked for me in the past.
Hey @cruxto
I think you’re better off creating a new topic here and providing all the contextual details, including the scripts.
If that method worked before, It will work again. Nothing have changed with that apart from name. The old name syntax will also continue to work for 2 more major versions too.
Cheers @danny-dainton, I’ll try it out on a few more collections and if I can consistently reproduce it on other collections I’ll raise a new topic with an example.
Just wondered if anyone else had noticed the same thing.
I believe that the original topic was asking about doing something that wasn’t possible 2 years ago.
We now have a pm.execution.skipRequest()
function that can be added to the pre request which would stop the run.
The original poster asked how to stop the runner completely. The current request and all further iterations.
The problem with setNextRequest(null) is that is stops the runner for that iteration and then starts the next iteration.
It’s not fully stopping the run.
skipRequest() would only skip the current request, so I don’t think that would have any bearing on this.
I don’t know if this is exactly the same scenario as @cruxto is detailing so a new issue with the relevant details does sound like the correct approach in that respect.
After 4 years of the original topic being opened and a few replies, things get a little messed up in my mind
I guess you could work something like into the post response logic:
throw new Error("Stop execution");
It would stop the execution but it wouldn’t do it in a clean and controlled way.
I’m sure it would have implications on the way the run is reported too.
Thanks @danny-dainton and @michaelderekjones
I’ve tried it again today and It works as expected.
When using the runner I added pm.execution.setNextRequest(null) in my test script, the execution will stop on that request for the current iteration.
I can see a use for “throw new Error(“Stop execution”);” as well.
For example, you are using the runner but you forget to add the data file to drive it.
It would kill the execution but just wouldn’t do it in a very graceful manner which preserves the run report. I’ve not looked further into that so I can’t be 100% certain.
Glad to hear you have the other part working