Test Overview
This test checks if the API response status is 200 and then verifies the presence of a specific field in the JSON body using a condition block in Postman test script.
This test checks if the API response status is 200 and then verifies the presence of a specific field in the JSON body using a condition block in Postman test script.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); if (pm.response.code === 200) { pm.test("Response has userId field", function () { var jsonData = pm.response.json(); pm.expect(jsonData).to.have.property('userId'); }); }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman app is open with the API request ready | - | PASS |
| 2 | Sends API request | Request sent to server, waiting for response | - | PASS |
| 3 | Receives response with status 200 | Response body contains JSON data with userId field | pm.response.to.have.status(200) | PASS |
| 4 | Checks if response code is 200 (condition block) | Condition true, enters block to check JSON body | - | PASS |
| 5 | Verifies response JSON has 'userId' property | JSON body includes userId field | pm.expect(jsonData).to.have.property('userId') | PASS |