Test Overview
This test sends a POST request with randomly generated user data to an API endpoint. It verifies that the response status is 201 Created and that the response body contains the same random name and email sent.
This test sends a POST request with randomly generated user data to an API endpoint. It verifies that the response status is 201 Created and that the response body contains the same random name and email sent.
pm.test("Create user with random data", function () { const randomName = pm.variables.replaceIn("{{$randomFullName}}") const randomEmail = pm.variables.replaceIn("{{$randomEmail}}") const requestBody = { name: randomName, email: randomEmail }; pm.sendRequest({ url: pm.environment.get("apiUrl") + "/users", method: 'POST', header: { 'Content-Type': 'application/json' }, body: { mode: 'raw', raw: JSON.stringify(requestBody) } }, function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('code', 201); const jsonData = res.json(); pm.expect(jsonData).to.have.property('name', randomName); pm.expect(jsonData).to.have.property('email', randomEmail); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman test runner is ready | - | PASS |
| 2 | Generate random full name and email using Postman dynamic variables | Random values assigned to variables randomName and randomEmail | - | PASS |
| 3 | Send POST request to API endpoint /users with JSON body containing randomName and randomEmail | Request sent to server with random user data | - | PASS |
| 4 | Receive response from server | Response received with HTTP status code and JSON body | Check response status code is 201 | PASS |
| 5 | Parse response JSON and verify 'name' and 'email' fields match sent random data | Response JSON parsed and fields compared | Assert response.name == randomName and response.email == randomEmail | PASS |
| 6 | Test ends | Test completed successfully | - | PASS |