Test Overview
This test demonstrates the default sequential order in which Postman requests run within a collection and shows that simply setting environment variables does not automatically manage flow control or conditional execution.
Jump into concepts and practice - no test required
This test demonstrates the default sequential order in which Postman requests run within a collection and shows that simply setting environment variables does not automatically manage flow control or conditional execution.
pm.test("First request runs", function () { pm.expect(true).to.be.true; }); // Set a variable to control flow pm.environment.set("runNext", "second"); // Second request test script: pm.test("Second request runs only if runNext is 'second'", function () { pm.expect(pm.environment.get("runNext")).to.eql("second"); }); // Change variable to stop further requests pm.environment.set("runNext", "stop"); // Third request test script: pm.test("Third request should not run if runNext is 'stop'", function () { pm.expect(pm.environment.get("runNext")).to.not.eql("stop"); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Start collection run in Postman | Postman collection runner opens with three requests queued | — | PASS |
| 2 | Run first request and execute its test script | First request response received | Check that the test 'First request runs' passes | PASS |
| 3 | Set environment variable 'runNext' to 'second' | Environment variable 'runNext' is set to 'second' | — | PASS |
| 4 | Run second request and execute its test script | Second request response received | Verify 'runNext' equals 'second' in test script | PASS |
| 5 | Set environment variable 'runNext' to 'stop' | Environment variable 'runNext' is set to 'stop' | — | PASS |
| 6 | Attempt to run third request and execute its test script | Third request response received | Check that 'runNext' is not 'stop' (expected to fail) | FAIL |
pm.setNextRequest() do in a collection run?pm.setNextRequest()pm.setNextRequest(null), not this function. Restarting or logging are unrelated.pm.setNextRequest(null) to stop running further requests.pm.stopCollection() or pm.abortRun() do not exist in Postman scripting.if (pm.response.code === 200) {
pm.setNextRequest('Request B');
} else {
pm.setNextRequest(null);
}pm.setNextRequest(null).pm.setNextRequest(null)pm.setNextRequest('Request C');
pm.setNextRequest(null);pm.setNextRequest() call takes effect in a single script execution.pm.setNextRequest(null)pm.setNextRequest() calls in the 'Login' and 'GetData' test scripts achieves this flow?pm.setNextRequest(null).pm.setNextRequest('Logout') is set in 'GetData' tests.pm.setNextRequest('GetData') if 200 else pm.setNextRequest(null);pm.setNextRequest('Logout') [OK]