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.
Jump into concepts and practice - no test required
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.
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 } });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and sends 'Request A' to the server | Postman sends HTTP request 'Request A' and waits for response | — | PASS |
| 2 | Postman receives response for 'Request A' | Response status 200 and JSON body received | Check response status is 200 | PASS |
| 3 | Test script parses JSON response and checks if 'success' is true | JSON parsed, 'success' field evaluated | — | PASS |
| 4 | Based on condition, setNextRequest is called with 'Request B' | Postman sets next request to 'Request B' | — | PASS |
| 5 | Postman sends 'Request B' as next request | Request B sent to server | — | PASS |
pm.setNextRequest() in Postman?pm.setNextRequest()if (pm.response.code === 200) {
pm.setNextRequest('ProcessData');
} else {
pm.setNextRequest('ErrorHandler');
}
If the response code is 404, which request runs next?if (pm.response.code = 200) {
pm.setNextRequest('NextStep');
} else {
pm.setNextRequest('Stop');
}
What is the problem with this script?userExists is true, the next request is "GetUserData", else the flow stops. Which script correctly implements this in the test tab?