If test of request under the folder fails, run next folder

I have many folders under my Collection and under these folders I have many requests. When I run this collection, if one of the test of any requests in a folder fails, I need a structure that will not send the next requests in the folder it is in and exit the folder and continue from the next folder.


  • Request1
  • Request2
  • Request3


  • Request4
  • Request5 (If any test of this request fails, don’t proceed to the next request, exit this folder and continue from the next folder.)
  • Request6


  • Request7
  • Request8
  • Request9

This is not that straightforward to achieve.

The only options for controlling flows is to use the collection runner and setNextRequest.

You can use a similar approach that is used for the “submit” requests within the Postman Challenges.

This defines a counter for the number of tests for the request.

// counter for passed tests
let pass = 0
let totalToPass = 5

Within each test block, the last line of code should increment the counter by 1. If the test fails the assertion, then this line of code won’t execute.

    pass += 1

At the end of the tests tab, you would have an IF statement that controls the next request to run.

if (pass != totalToPass) {
   // Something has failed

However, you are going to need to know the name of the first request in the next set of folders which comes with its own overhead maintaining those relationships unless you have an sequential naming convention or something else that helps with this without specifically needing to know the request name.

Thank you, this workaround opened up my horizon even though it didn’t exactly meet what I wanted.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.