0
0
Postmantesting~15 mins

Path parameters in Postman - Build an Automation Script

Choose your learning style9 modes available
Verify GET request with path parameters returns correct user data
Preconditions (2)
Step 1: Set the HTTP method to GET
Step 2: Set the request URL to https://api.example.com/users/123 where 123 is the userId path parameter
Step 3: Send the request
Step 4: Observe the response status code and body
✅ Expected Result: Response status code is 200 and response body contains user data for userId 123
Automation Requirements - Postman Tests (JavaScript)
Assertions Needed:
Verify response status code is 200
Verify response body contains userId equal to 123
Best Practices:
Use path parameters properly in the request URL
Write clear and simple test scripts in Postman Tests tab
Use JSON parsing to verify response content
Avoid hardcoding values in multiple places; use variables if possible
Automated Solution
Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});

pm.test('Response has correct userId', function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.userId).to.eql(123);
});

The first test checks that the HTTP response status code is 200, which means the request was successful.

The second test parses the JSON response body and verifies that the userId field equals 123, matching the path parameter used in the request URL.

This ensures the API returns the correct user data for the given path parameter.

Common Mistakes - 3 Pitfalls
Not replacing the path parameter placeholder with an actual value
Checking response status code without verifying response body
Hardcoding userId in multiple places in the test script
Bonus Challenge

Now add data-driven testing with 3 different userIds: 101, 202, and 303

Show Hint