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.
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 |