Improve postman.setNextRequest()

setnextrequest

#1

The postman.setNextRequest("name of request) command is extremely useful.
However I feel like this can be greatly improved.
If I use the below code, this will find all the requests that match and the last match will be the resulting “next request”.

postman.setNextRequest("Health Check [200]");

Ideally, I’d like to specify which request to use if there are actually several requests which the same name. My test collection could have several Health checks with the same name.

postman.setNextRequest("Health Check [200]"[0]);

Perhaps something like the above which will match and set the first request as the next request.

Even better, would be to specify a folder path structure:
image

Given the above, if I want to set the “Health [200]” request in the User Service API child folder as the next request:

postman.setNextRequest(Example.UserService API.Health [200]);

Either something like that, or give each request an ID that I can specify:

postman.setNextRequest("eoaaqxyywn6o");

#2

Hey @pfarrell, thanks for the suggestion!

At the moment, we’re deliberating the right transition from postman.setNextRequest to the corresponding pm.* equivalent. Until the required behaviour is finalized, this will serve as a useful reference for possible improvements.

At the time of writing, I can think of the following:

  1. Ability to specify the scope of the match (current folder, entire collection, and so on) (https://github.com/postmanlabs/postman-app-support/issues/2819)
  2. Ability to pick which matched request to proceed with (1st, 2nd, last, and so on)
  3. Ability to skip to the start of a folder. (https://github.com/postmanlabs/postman-app-support/issues/2851)
  4. In addition, information on the previous and next requests could also be included for more advanced workflows.

EDIT: (9 July 2018)

  1. Setting the next to request to null should stop the collection run, even if the current scope is in a pre-request script.

How to explicitly stop calling a request in postman through pre-request script?
Support of "old" test-framework
#3

Any update to this? :smiley:

Perhaps when using setNextRequest() it should return an array of collections that match the collection name?

// This will select the first match in the array by default?
postman.setNextRequest("Health [200]");
// This will select the second match
postman.setNextRequest("Health [200]")[1];

Ideally, I’d love to have the ability to stay within a sub-folder.
So if my “Tests” collection contains multiple sub-directories “sub-tests1”,“sub-tests2” etc.
And each sub-directory has the same requests/request names but I’m testing different scenarios in each folder, I’d like to stay within the sub-directory.

// This will select the "Health [200]" request in the "sub-tests1" subdirectory
postman.setNextRequest(sub-tests1["Health [200]"]);
// Or specify to stay within the parent folder
postman.setNextRequest(tests.sub-tests1["Health [200]"]);