0
0
Postmantesting~15 mins

GET request in Postman - Build an Automation Script

Choose your learning style9 modes available
Verify GET request to retrieve user data
Preconditions (2)
Step 1: Open Postman
Step 2: Create a new GET request
Step 3: Enter the URL https://jsonplaceholder.typicode.com/users/1
Step 4: Click the Send button
Step 5: Observe the response status code and body
✅ Expected Result: Response status code is 200 OK and response body contains user data with id 1
Automation Requirements - Postman test scripts
Assertions Needed:
Verify response status code is 200
Verify response body contains user id equals 1
Best Practices:
Use pm.response.to.have.status for status code assertion
Use pm.expect with JSON parsing for body content assertion
Keep test scripts simple and readable
Automated Solution
Postman
pm.test('Status code is 200', () => {
    pm.response.to.have.status(200);
});

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

The first test checks that the response status code is exactly 200, which means the GET 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 is returned.

Using pm.test groups assertions with clear names, making test results easy to understand.

Common Mistakes - 3 Pitfalls
Not checking the status code before parsing the response body
{'mistake': 'Using incorrect assertion syntax like pm.expect(pm.response.status).to.equal(200)', 'why_bad': "pm.response.status is a string like 'OK', not the numeric code. This causes assertion failures.", 'correct_approach': 'Use pm.response.to.have.status(200) to correctly assert numeric status codes.'}
Hardcoding checks for fields that might not exist in the response
Bonus Challenge

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

Show Hint