Runner custom request order

Hello all,

I have several request I want to unitest, problem is some of the, are dependant on other previous requests:

Request 1
Validate response and save header
Use header in Request 2
Validate Request 2

Request 1
Validate response and save header
Use header in Request 3
Validate Request 3

etc…

Is it possible to call the first request more than once, and initiate the requests as I see fit? Or is this not supported in Postman?

Thanks!

1 Like

Have you looked into postman.setNextRequest();

It’s a game-changer :slight_smile:

https://learning.getpostman.com/docs/postman/collection_runs/building_workflows/

https://learning.getpostman.com/docs/postman/scripts/branching_and_looping/

Thanks @
pfarrell
, this seems to help a lot when determining the order of requests. However, after request1 is done, along with all of its setNextRequest() commands, it will still continue to the next requests in order, right? That’s not good, for me, anyways…

I’m tying to construct a very know of test cases:

test 1

Request 1
Request 2

test 2

Request 1
Request 3

test 3

Request 2
Request 3

etc… I guess I need several runners? How do I create a runner only for 2 request and not all of the request in a collection?

You could add some logic into the tests and have some kind of “counter” value, so when it’s 1 (using postman.setNextRequest()), you could say to run requests 1 and 2, if the counter value is 2 then run 1 and 3 etc.

Removing the whole duplication thing in Postman seems to be one of the biggest challenges, in my opinion.

Check out the below post on keeping your tests DRY as there are some good answers from other experienced Postman users:

Thanks again, after reading this a bit, and considering my API is going to get considerably bigger than it is now, duplicating collections for each test case seems like a huge overhead…

Was thinking about using Chai on my own and create my own tests using js, but we can’t really integrate it with postman… Sad day…

Yep, I’ve been there :slight_smile:

I may be biased here, but checkout my posts on using “beforeEachHooks” in Postman:

So if you have a User API and you want to create a new user per test scenario so you have no persisting data from other tests.

You’d want a “create user” request to run first, then run request 2. Then go back and create a new user and run request 3. etc.

I’ve used this method at my current place of work and it has dramatically cut down maintenance. There is a little bit of a learning curve whenever new testers start using my API tests but it’s SO much better than duplicating and maintaining the same request.

https://community.postman.com/t/implement-hooks-to-postman-to-improve-maintainability-of-test-collections-before-beforeeach-aftereach-etc/3778

My post on the below thread has example collections etc.