0
0
Postmantesting~5 mins

Conditional request execution (setNextRequest) in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the setNextRequest() function do in Postman?
It controls which request runs next in a collection run, allowing you to skip or repeat requests based on conditions.
Click to reveal answer
beginner
How can you skip a request in Postman using setNextRequest()?
By calling postman.setNextRequest(null), you stop the collection run from continuing to any further requests.
Click to reveal answer
intermediate
True or False: setNextRequest() can be used to create loops in a Postman collection run.
True. You can set the next request to a previous one to repeat it, creating a loop.
Click to reveal answer
beginner
In which script tab do you write setNextRequest() to control request flow?
You write it in the Tests tab of a request, after the response is received.
Click to reveal answer
intermediate
Example: How to run Request B only if Request A returns status 200?
In Request A's Tests tab, write:<br>
if (pm.response.code === 200) {
  postman.setNextRequest('Request B');
} else {
  postman.setNextRequest(null);
}
Click to reveal answer
What happens if you call postman.setNextRequest(null) in a test script?
AThe collection run stops after the current request.
BThe next request runs as usual.
CThe current request repeats indefinitely.
DAn error occurs and the run fails.
Where do you place the setNextRequest() function to control request flow?
APre-request Script tab
BTests tab
CBody tab
DHeaders tab
Can setNextRequest() create loops in a Postman collection?
ANo, it only moves forward.
BOnly in the pre-request script.
COnly if you use external scripts.
DYes, by setting the next request to a previous one.
If you want to run Request C only when a variable isReady is true, what should you do?
AUse an if statement in Tests tab to call <code>postman.setNextRequest('Request C')</code> only if <code>isReady</code> is true.
BSet <code>isReady</code> in the Pre-request Script tab.
CAlways call <code>postman.setNextRequest('Request C')</code>.
DYou cannot control request execution based on variables.
What is the default behavior if you do NOT use setNextRequest() in a collection run?
AOnly the first request runs.
BRequests run randomly.
CRequests run in the order they appear in the collection.
DThe collection run stops immediately.
Explain how setNextRequest() can be used to control the flow of requests in a Postman collection.
Think about how you decide which request runs next after one finishes.
You got /4 concepts.
    Describe a scenario where you would use postman.setNextRequest() to skip some requests.
    Imagine you only want to continue if a test passes.
    You got /4 concepts.