Test Overview
This test checks a simple API workflow in Postman where a user is created, then retrieved, and finally deleted. It verifies that each step completes successfully and the data matches expectations.
This test checks a simple API workflow in Postman where a user is created, then retrieved, and finally deleted. It verifies that each step completes successfully and the data matches expectations.
pm.test("Create User - Status 201", function () { pm.response.to.have.status(201); const jsonData = pm.response.json(); pm.environment.set("userId", jsonData.id); }); pm.test("Get User - Status 200 and correct user", function (done) { pm.sendRequest({ url: `https://api.example.com/users/${pm.environment.get("userId")}`, method: 'GET' }, function (err, res) { pm.expect(res).to.have.property('code', 200); const user = res.json(); pm.expect(user.id).to.eql(pm.environment.get("userId")); done(); }); }); pm.test("Delete User - Status 204", function (done) { pm.sendRequest({ url: `https://api.example.com/users/${pm.environment.get("userId")}`, method: 'DELETE' }, function (err, res) { pm.expect(res).to.have.property('code', 204); done(); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send POST request to create a new user | API server receives user creation request | Response status is 201 Created | PASS |
| 2 | Extract user ID from response and save to environment variable | User ID stored for next requests | - | PASS |
| 3 | Send GET request to retrieve the created user using saved user ID | API server returns user data | Response status is 200 OK and user ID matches saved ID | PASS |
| 4 | Send DELETE request to remove the created user using saved user ID | API server deletes user | Response status is 204 No Content | PASS |