0
0
Postmantesting~10 mins

Conditional request execution (setNextRequest) in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the Postman collection runs the next request conditionally based on the response of the current request. It verifies that setNextRequest correctly directs the flow.

Test Code - Postman
Postman
pm.test("Check response status and set next request", function () {
    pm.response.to.have.status(200);
    const jsonData = pm.response.json();
    if (jsonData.success === true) {
        pm.setNextRequest("Request B");
    } else {
        pm.setNextRequest(null); // stops the run
    }
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and sends 'Request A' to the serverPostman sends HTTP request 'Request A' and waits for response-PASS
2Postman receives response for 'Request A'Response status 200 and JSON body receivedCheck response status is 200PASS
3Test script parses JSON response and checks if 'success' is trueJSON parsed, 'success' field evaluated-PASS
4Based on condition, setNextRequest is called with 'Request B'Postman sets next request to 'Request B'-PASS
5Postman sends 'Request B' as next requestRequest B sent to server-PASS
Failure Scenario
Failing Condition: Response status is not 200
Execution Trace Quiz - 3 Questions
Test your understanding
What does setNextRequest("Request B") do in this test?
AIt tells Postman to run 'Request B' next
BIt stops the collection run immediately
CIt retries the current request
DIt skips 'Request B' and runs the next request
Key Result
Use setNextRequest to control the flow of requests dynamically based on response data, enabling conditional testing scenarios in Postman collections.