Verify API response time is under 2 seconds
Preconditions (2)
✅ Expected Result: The response time should be less than 2000 milliseconds (2 seconds)
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.
Now add data-driven testing with 3 different API endpoints to verify their response times
pm.response.responseTime represent in Postman?pm.response.responseTime returnspm.response.responseTime gives the time in milliseconds the server took to respond.pm.test with a callback and pm.expect for assertions.pm.expect(pm.response.responseTime).to.be.below(500).pm.test('Check response time', () => {
pm.expect(pm.response.responseTime).to.be.below(300);
});pm.test('Response time test', () => {
pm.expect(pm.response.responseTime).to.be.lessThan(400);
});below, not lessThan.lessThan causes a syntax error because it is not recognized.lessThan is not valid in Postman assertions -> Option BPass the test and this pattern moves unknown