Test Overview
This test sends a GET request to a user API endpoint and verifies that the returned user ID matches the expected dynamic value from the response. It checks that the user name is not empty and the status code is 200.
This test sends a GET request to a user API endpoint and verifies that the returned user ID matches the expected dynamic value from the response. It checks that the user name is not empty and the status code is 200.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("User ID matches dynamic value", function () { const jsonData = pm.response.json(); const expectedUserId = jsonData.data.id; pm.expect(jsonData.data.id).to.eql(expectedUserId); }); pm.test("User name is not empty", function () { const jsonData = pm.response.json(); pm.expect(jsonData.data.name).to.not.be.empty; });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send GET request to https://api.example.com/users/123 | Request sent, waiting for response | - | PASS |
| 2 | Receive response with status code 200 and JSON body containing user data | Response received: {"data":{"id":123,"name":"Alice"}} | Check that status code is 200 | PASS |
| 3 | Extract user ID from response JSON and assign to expectedUserId | expectedUserId = 123 | Verify that response user ID equals expectedUserId | PASS |
| 4 | Check that user name field is not empty | User name is 'Alice' | Verify user name is not empty | PASS |