/* Request1 Tests */
pm.test('Request1 runs', function () {
pm.expect(true).to.be.true;
});
/* Request2 Tests and flow control */
// In Tests tab of Request2
pm.test('Request2 runs and sets runNext', function () {
pm.environment.set('runNext', 'true'); // Change to 'false' to test skipping
pm.expect(pm.environment.get('runNext')).to.be.oneOf(['true', 'false']);
});
// Control flow
if (pm.environment.get('runNext') === 'true') {
postman.setNextRequest('Request3');
} else {
postman.setNextRequest(null); // Stops collection run
}
/* Request3 Tests */
pm.test('Request3 runs only if runNext is true', function () {
pm.expect(pm.environment.get('runNext')).to.eql('true');
});This script uses Postman test scripts to control the run order and flow.
In Request2, we set an environment variable runNext to 'true' or 'false'.
Then, using postman.setNextRequest(), we decide if Request3 should run.
If runNext is 'true', Request3 runs next; otherwise, the collection stops.
Assertions verify that each request runs in order and that flow control works as expected.