Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Postman Tutorial Part 27 – Building Workflows in Collection Runner Using setNextRequest() in Postman

Posted on 12/11/2024 By admin

Hello Folks,

We already know that “A Postman collection allows you to group individual pre-built requests together. You can even group by creating folders in a Collection“. Read more about collection here.

Suppose you have 10 requests in a Collection. When you run this collection using Collection Runner, you will see execution of requests happens in the same order as it appears in Collection.

What will be the sequence if your collection has folder/s in it?

By default folder is shown first in Collection than any requests in the root of the collection. So all requests of folders are executed first as they appear in Collection and then any requests in the root of the collection. Within folder of a collection, request are executed in same order as it appears in folder. Note here that you can drag request or folder in Collection to change order.

For example:-

Import below Postman Collection:-

https://www.getpostman.com/collections/603df4d90a8e6d4de49b

In the above Collection, I have two folders and four individual requests in root of Collection. In Collection runner, it will appear in same order as shown below:-

It will be run in same order as well:-

Above is the default behaviour of Collection run.

But you may need to:-

  1. Dynamically decide the next request to be executed at run time.
  2. Skip/Jump requests in Collection

To achieve above customization, we need to use built-in function postman.setNextRequest().

setNextRequest() is a function which takes single argument as the name of request which we want to execute next. It always gets executed at end of the current request. We can use this method in pre-request or test scripts.

Let’s do an example:-

I am using above function to execute request “Get All Bookings” after request “Restful Booker Token Generator API“. As a default run, “Create Booking” should run after “Restful Booker Token Generator API” which I am overriding. Refer below image:-

When you run above collection, you see result as:-

Did you notice that request “Create Booking” did not run at all? It was skipped in flow.

Functionality of setNextRequest() is as below:-

  1. setNextRequest() always runs in the last of current request even you write it in pre-request script tab of request.
  2. We can jump to any request in Collection including any request in folder of collection as well if you are running whole Collection.
  3. If you set next request in forward flow, request/s in between will be skipped. For example:- If we have requests R1, R2, R3 and R4 and we set next request as R4 in R1, only R1 and R4 will be executed. R2 and R3 will be skipped. But if we set next request as R3 in Request R1, then R1, R3 and R4 will be executed and only R2 will be skipped. So if setNextRequest() is not found, default order is assumed from next requests in Collection.
  4. If we set next request in backward direction (Already executed or skipped request), collection run may go in infinite loop. For example:- If we have requests R1, R2, R3 and R4 and we set next request as R1 in R2, then run will be as:- R1, R2, R1, R2, R1…..
  5. If you set next request as the same request, Collection run will go in infinite loop.
  6. You can terminate execution of Collection run in between by setting next request as null i.e. postman.setNextRequest(null);
  7. This method has scope as well. Scope defines the visibility of requests to set as next. If you run entire collection, you can jump to any request in the collection including requests inside folders. But if you run a folder of Collection, you can jump to any request within that folder only, not outside of the folder. It includes requests inside other folders, and also root-level requests in the collection.
  8. If you set a next request which does not exist, execution of Collection will be terminated at that point. It is same as postman.setNextRequest(null);
  9. This is applicable only if you run using Collection Runner. Not as individual request.

It is a very helpful method to create custom workflow but use it carefully. One mistake can take you in infinite loop.

More about API Testing in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyApiTesting

Uncategorized

Post navigation

Previous Post: TestNG Tutorials 22: @Test Annotation – Games Of Priority Of Methods In TestNG
Next Post: How To Verify Text In Bold Using Selenium WebDriver

Related Posts

DefineOrOptional – Make Selenium Easy Uncategorized
postman tutorials – Page 2 Uncategorized
JsonPath – RestAssured Uncategorized
Frequently Asked Java Programs In Interview Archives – Page 2 of 3 – Make Selenium Easy Uncategorized
How To Upload A File In Selenium Webdriver Uncategorized
Conditional1 – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark