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.
Jump into concepts and practice - no test required
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 |
{{random.int(min,max)}} to generate random integers.{{random.int(1,100)}} matches the correct syntax exactly.{"userId": "{{random.uuid}}"}{{random.int(10,5)}} in your Postman test to generate a random number between 10 and 5. What is the issue and how to fix it?{{random.int(5,10)}} corrects the range.@example.com. Which of the following is the best way to do this?{{random.username}}@example.com concatenates a random username with fixed domain correctly. {{random.email}} uses full random email (domain varies). {{random.username}}@{{random.domain}} randomizes domain (not fixed). {{random.email}}@example.com appends fixed domain to full email (invalid).