Test Overview
This test sends a POST request with dynamic user data generated at runtime. It verifies that the API responds with a success status and the correct user name in the response.
This test sends a POST request with dynamic user data generated at runtime. It verifies that the API responds with a success status and the correct user name in the response.
pm.test("Create user with dynamic data", function () { // Generate dynamic user data const randomId = Math.floor(Math.random() * 10000); const userName = `user_${randomId}`; // Set request body with dynamic data pm.request.body.update({ mode: 'raw', raw: JSON.stringify({ name: userName, email: `${userName}@example.com` }) }); // Send the request pm.sendRequest(pm.request, function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('status', 201); const jsonData = res.json(); pm.expect(jsonData.name).to.eql(userName); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and generates a random user ID | Random number generated, userName variable set to 'user_<randomId>' | - | PASS |
| 2 | Updates the request body with dynamic userName and email | Request body now contains JSON with dynamic name and email | - | PASS |
| 3 | Sends POST request to create user with dynamic data | Request sent to API endpoint | - | PASS |
| 4 | Receives response and checks for no error and status code 201 | Response received with status code 201 | Assert err is null and response status is 201 | PASS |
| 5 | Parses response JSON and verifies returned user name matches dynamic userName | Response JSON contains user data | Assert response JSON name equals generated userName | PASS |