# Using setNextRequest in test script with folders

**URL:** <https://community.postman.com/t/using-setnextrequest-in-test-script-with-folders/59874>\
**Category:** Help Hub\
**Tags:** tests, collections\
**Created:** [April 12, 2024, 6:54am UTC](https://community.postman.com/t/using-setnextrequest-in-test-script-with-folders/59874 "2024-04-12T06:54:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![meredithalcorn](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@meredithalcorn](https://community.postman.com/u/meredithalcorn)\
**Post date:** [April 12, 2024, 6:54am UTC](https://community.postman.com/t/using-setnextrequest-in-test-script-with-folders/59874/1 "2024-04-12T06:54:30Z")

</div>

I have a collection in Postman with folders that are structured like this:

**Team Collection**  
Season1 (folder)  
Stats (folder)  
Player1 Tests (folder) - contains a pre-request and a test script. If the request name is “R2”–\> It calls setNextRequest(“Player3 Tests”)  
R1  
R2  
Player2 Tests (folder)  
R3  
Player3 Tests (folder) - contains pre and post request tests.  
R4  
R5

I’m hoping to get the Player3 Tests folder’s tests to execute, but it’s not working as it stands with setNextRequest(“Player3 Tests”).  
I’ve selected Player1 Tests, Player2 Tests, and Player3 Tests from the collection runner before executing the run. Is there something I might be missing to make this work in the collection runner? Or does the folder level execution only work from Newman and not the collection runner in the Desktop app

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [April 12, 2024, 9:21am UTC](https://community.postman.com/t/using-setnextrequest-in-test-script-with-folders/59874/2 "2024-04-12T09:21:47Z")

</div>

setNextRequest just sets the next **request** that will run after the current request and all of the code in any pre-request script and tests tab has completed.

The key element here is **request**.

You can’t run a folder, so you will have to tell it to run the first request within that folder. In this case it would be R4.

Not sure if your logic for this is correct. The Collection runner runs requests run by folder then request order.

If you have a pre-request script for the Player1 folder looking for R2 (which will always be true). Then it will always skip the Player2 folder and miss R3 as far as I can tell from the logic you provided.

---

<div class="post-metadata">

**Author:** ![meredithalcorn](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@meredithalcorn](https://community.postman.com/u/meredithalcorn)\
**Post date:** [April 12, 2024, 4:22pm UTC](https://community.postman.com/t/using-setnextrequest-in-test-script-with-folders/59874/3 "2024-04-12T16:22:14Z")

</div>

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [May 12, 2024, 4:22pm UTC](https://community.postman.com/t/using-setnextrequest-in-test-script-with-folders/59874/4 "2024-05-12T16:22:57Z")

</div>

Closed on May 12, 2024, 4:22pm UTC

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