0
0
Postmantesting~15 mins

First API request in Postman - Build an Automation Script

Choose your learning style9 modes available
Send a GET request to retrieve user data
Preconditions (2)
Step 1: Open Postman application
Step 2: Create a new GET request
Step 3: Enter the URL https://jsonplaceholder.typicode.com/users/1 in the request URL field
Step 4: Click the Send button
Step 5: Observe the response status code and body
✅ Expected Result: Response status code is 200 OK and the response body contains user data with id 1
Automation Requirements - Postman (using Postman test scripts)
Assertions Needed:
Verify response status code is 200
Verify response body contains user id equal to 1
Best Practices:
Use built-in Postman test scripting with pm.* API
Write clear and simple assertions
Avoid hardcoding values except the endpoint URL
Use descriptive test names
Automated Solution
Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});

pm.test('Response has user id 1', function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.id).to.eql(1);
});

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

The second test parses the JSON response body and verifies that the user id field equals 1, confirming the correct user data was returned.

Using pm.test allows grouping assertions with descriptive names for clear test reports.

This script runs automatically after the request is sent in Postman.

Common Mistakes - 3 Pitfalls
Not checking the response status code
Parsing response body without checking if it is JSON
Hardcoding values inside test scripts without explanation
Bonus Challenge

Now add data-driven testing with 3 different user IDs (1, 2, 3) to verify each returns status 200 and correct user id

Show Hint