Test Overview
This test sends a GET request to a sample API endpoint and verifies that the response body contains the expected user data in JSON format.
This test sends a GET request to a sample API endpoint and verifies that the response body contains the expected user data in JSON format.
pm.test("Response body contains user data", function () { pm.response.to.have.status(200); const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property('user'); pm.expect(jsonData.user).to.have.property('id').that.is.a('number'); pm.expect(jsonData.user).to.have.property('name').that.is.a('string'); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send GET request to https://api.example.com/user/123 | Request sent, waiting for response | - | PASS |
| 2 | Receive response with status 200 and JSON body | Response body: {"user":{"id":123,"name":"Alice"}} | Check response status is 200 | PASS |
| 3 | Parse response body as JSON | Parsed JSON object available | - | PASS |
| 4 | Verify response JSON has property 'user' | JSON contains 'user' object | Assert jsonData has property 'user' | PASS |
| 5 | Verify 'user' object has numeric 'id' | 'user.id' is 123 | Assert user.id is a number | PASS |
| 6 | Verify 'user' object has string 'name' | 'user.name' is 'Alice' | Assert user.name is a string | PASS |