Improve postman.setNextRequest()

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:

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]);

EDIT: Pretty much ignore everything above, a MUCH better way of doing this would be to define a request by some-kind-of internal “requestID”, this way it doesn’t matter if the test is renamed/moved etc.

postman.setNextRequest("eoaaqxyywn6o");
1 Like

Hey @postman-paul540, 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.
2 Likes

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]"]);

Hello,
I am having the same requirement somehow.
It would be fine to specify a folder only in the setNextRequest() such that we can position the workflow at the beginning of a folder to execute the pre-request script followed by the request in the folder.
and also to specify a request by its folder path:
setNextRequest(folder.subfolder1. … .request Name)
this way it would be possible to duplicate folders with having to rename all requests within it.
Thanks,

2 Likes

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