Challenge - 5 Problems
Postman Conditional Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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'); }
Attempts:
2 left
💡 Hint
Check the condition inside the if statement and what setNextRequest is called with.
✗ Incorrect
The script checks if the response code is 200. If true, it sets the next request to 'RequestB'. Otherwise, it sets it to 'RequestC'.
❓ assertion
intermediate2: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'); });
Attempts:
2 left
💡 Hint
Where should setNextRequest be placed to run only if assertion passes?
✗ Incorrect
Placing setNextRequest inside pm.test ensures it runs only if the test passes (status 200).
🔧 Debug
advanced2: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 runsAttempts:
2 left
💡 Hint
Check if other scripts or requests call setNextRequest after this code.
✗ Incorrect
Calling setNextRequest(null) stops the collection run only if no other setNextRequest calls override it later.
🧠 Conceptual
advanced2: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?
Attempts:
2 left
💡 Hint
Think about default behavior when setNextRequest is not used.
✗ Incorrect
If setNextRequest is not called, Postman runs the next request in the collection order by default.
❓ framework
expert3: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); }
Attempts:
2 left
💡 Hint
Check the condition logic and how setNextRequest controls looping.
✗ Incorrect
The script loops by setting next request to 'RequestA' while done is false, stopping when done is true by setting null.