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.
Collection
Folder1
Request1
Request2
Request3
Folder2
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.)
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
pm.setNextRequest("requestName")
}
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.