Generate dynamic user data for API request
Preconditions (2)
✅ Expected Result: The API accepts the dynamically generated user data and returns status 201 with the correct user details in the response body
Jump into concepts and practice - no test required
pm.test('Status code is 201', function () { pm.response.to.have.status(201); }); const responseJson = pm.response.json(); pm.test('Response contains sent name', function () { pm.expect(responseJson.name).to.eql(pm.variables.get('name')); }); pm.test('Response contains sent email', function () { pm.expect(responseJson.email).to.eql(pm.variables.get('email')); });
This test script runs after the request is sent.
First, it checks the response status is 201, meaning the user was created successfully.
Then it parses the JSON response body.
It asserts that the response's name and email fields match the values sent in the request, which are stored in Postman variables.
This ensures the API accepted the dynamic data correctly.
Now add data-driven testing by running the request with 3 different sets of dynamic user data automatically
{{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).