Test Overview
This test sends a GET request to a sample API endpoint and extracts a specific value from the JSON response. It verifies that the extracted value matches the expected result.
This test sends a GET request to a sample API endpoint and extracts a specific value from the JSON response. It verifies that the extracted value matches the expected result.
pm.test("Extract user ID from response", function () { pm.sendRequest('https://jsonplaceholder.typicode.com/users/1', function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('status', 200); const jsonData = res.json(); const userId = jsonData.id; pm.expect(userId).to.eql(1); pm.environment.set('extractedUserId', userId); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and sends GET request to 'https://jsonplaceholder.typicode.com/users/1' | Postman sends HTTP GET request to the API endpoint | - | PASS |
| 2 | Receives HTTP response with status code 200 and JSON body | Response contains user data JSON with id, name, username, etc. | Check that response status code is 200 | PASS |
| 3 | Parses JSON response and extracts 'id' field value | Extracted userId = 1 | Verify extracted userId equals 1 | PASS |
| 4 | Stores extracted userId in environment variable 'extractedUserId' | Environment variable 'extractedUserId' set to 1 | - | PASS |
| 5 | Test completes successfully | Test result marked as passed in Postman test runner | - | PASS |