Verify API response time is under 500 milliseconds
Preconditions (2)
✅ Expected Result: The API responds successfully and the response time is less than 500 milliseconds
Jump into concepts and practice - no test required
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response time is less than 500 ms', () => { pm.expect(pm.response.responseTime).to.be.below(500); });
The first test checks that the API returns a status code 200, which means success.
The second test checks that the response time is below 500 milliseconds using pm.response.responseTime.
Both tests use Postman's built-in pm object and chai assertion library for clear and readable assertions.
This script should be placed in the Tests tab of the Postman request.
Now add data-driven testing with 3 different API endpoints and verify each response time is under 500 ms
pm.response.responseTime represent in Postman tests?pm.response.responseTimepm.response.responseTime. To check if it is less than 500ms, use to.be.below(500).pm.response.responseTime with to.be.below() [OK]pm.test('Response time is acceptable', () => {
pm.expect(pm.response.responseTime).to.be.below(400);
});pm.response.responseTime to be below 400 milliseconds.pm.test('Response time check', function() {
pm.expect(pm.response.responseTime).to.be.lessThan(300);
});to.be.below(), not lessThan().lessThan is incorrect in Postman tests -> Option Ato.be.below() not lessThan() [OK]to.be.at.most(1000) checks if value is less than or equal to 1000, matching the requirement. to.be.below(1000) excludes 1000, to.equal(1000) only passes exactly 1000, and to.be.above(1000) is opposite.