0
0
Postmantesting~20 mins

Conditional request execution (setNextRequest) in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Postman Conditional Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the next request executed?
Given this Postman test script, which request will run next after the current one?
Postman
if (pm.response.code === 200) {
    postman.setNextRequest('RequestB');
} else {
    postman.setNextRequest('RequestC');
}
ANo next request will run; the collection stops
BRequestB if response code is 200, otherwise RequestC
CAlways RequestB regardless of response code
DRequestC if response code is 200, otherwise RequestB
Attempts:
2 left
💡 Hint
Check the condition inside the if statement and what setNextRequest is called with.
assertion
intermediate
2:00remaining
Which assertion ensures the next request runs only on success?
You want the next request to run only if the current request succeeded (status 200). Which assertion and setNextRequest code is correct?
Postman
pm.test('Status is 200', function () {
    pm.response.to.have.status(200);
    postman.setNextRequest('NextRequest');
});
AUse pm.test to check status 200 and call setNextRequest inside it
BCall setNextRequest before pm.test assertion
CCall setNextRequest unconditionally outside pm.test
DUse pm.expect(pm.response.code).to.equal(200) without setNextRequest
Attempts:
2 left
💡 Hint
Where should setNextRequest be placed to run only if assertion passes?
🔧 Debug
advanced
2:00remaining
Why does setNextRequest not work as expected?
This script aims to skip the next request if a condition is false, but the next request still runs. What is the issue?
Postman
if (pm.response.json().success === false) {
    postman.setNextRequest(null);
}
// Next request still runs
AsetNextRequest(null) is correct to stop execution; issue is elsewhere
BsetNextRequest(null) must be called inside pm.test block to work
CsetNextRequest(null) stops execution only if no other setNextRequest calls override it
DsetNextRequest(null) should be setNextRequest('null') as string
Attempts:
2 left
💡 Hint
Check if other scripts or requests call setNextRequest after this code.
🧠 Conceptual
advanced
2:00remaining
What happens if setNextRequest is not called?
In a Postman collection run, if a request script does not call postman.setNextRequest, what happens after this request finishes?
AAn error is thrown and the run aborts
BThe collection run stops immediately
CThe same request runs again in a loop
DThe collection runs the next request in the defined order
Attempts:
2 left
💡 Hint
Think about default behavior when setNextRequest is not used.
framework
expert
3:00remaining
How to conditionally loop a request using setNextRequest?
You want to repeat 'RequestA' until a response field 'done' is true. Which script correctly implements this loop?
Postman
const done = pm.response.json().done;
if (!done) {
    postman.setNextRequest('RequestA');
} else {
    postman.setNextRequest(null);
}
ALoop while done is false by setting next request to 'RequestA', else stop with null
BLoop while done is true by setting next request to 'RequestA', else stop with null
CAlways set next request to 'RequestA' regardless of done value
DUse postman.setNextRequest('null') as string to stop looping
Attempts:
2 left
💡 Hint
Check the condition logic and how setNextRequest controls looping.