Executing postman.setNextRequest from collection tests

Hello there,

I have a collection in which i need to abort the entire run when any test fails. While searching about this, I came across the postman.setNextRequest(null) hack. Instead of adding this in each test, I thought of having a function in the collection’s test and simply call that function each time.
Accordingly, I wrote the below:

utils = {
    check_abort: function(is_failure){
        if (is_failure){

And in each test, I set the is_failure and call utils.check_abort. Now the call goes into the function, but the execution does not stop on that request, it goes ahead.

On the other hand, if I write this in the request’s test itself, the execution stops:

if (is_failure){

I am not sure what am i missing here.
I just need an elegant way of stopping runs when even a single test fails.

Thanks you.

Are you using newman ? If so there is a --bail flag

Could you also add your code on how you are callign the function from the script

1 Like

Yes I came across the --bail flag… originally i wanted to do it in Postman instead of Newman. But nevermind, i will be using Newman itself, so this works!

Thanks! :v:t3: