0
0
Postmantesting~15 mins

Response time in Postman - Build an Automation Script

Choose your learning style9 modes available
Verify API response time is under 2 seconds
Preconditions (2)
Step 1: Open Postman and create a new GET request
Step 2: Enter the API endpoint URL: https://api.example.com/data
Step 3: Send the request by clicking the Send button
Step 4: Observe the response time displayed in Postman
✅ Expected Result: The response time should be less than 2000 milliseconds (2 seconds)
Automation Requirements - Postman test scripts
Assertions Needed:
Response time is less than 2000 ms
Best Practices:
Use pm.response.responseTime to get response time
Write clear assertion messages
Keep test scripts simple and readable
Automated Solution
Postman
pm.test('Response time is less than 2000 ms', function () {
    pm.expect(pm.response.responseTime).to.be.below(2000);
});

This script uses Postman's built-in pm object to access the response time of the API call.

The pm.test function defines a test with a clear name.

Inside, pm.expect checks that the response time is below 2000 milliseconds.

This ensures the API responds quickly enough, and the test will pass or fail accordingly.

Common Mistakes - 3 Pitfalls
Using hardcoded response time values without checking actual response
Not adding assertion messages
{'mistake': 'Checking response time in the request body or headers instead of using pm.response.responseTime', 'why_bad': 'Response time is not part of response data; it is a separate metric.', 'correct_approach': "Use Postman's responseTime property to measure response duration."}
Bonus Challenge

Now add data-driven testing with 3 different API endpoints to verify their response times

Show Hint