Verify API response time and status code using Postman
Preconditions (2)
✅ Expected Result: The response status code should be 200 OK and the response time should be less than 2000 milliseconds
pm.test('Status code is 200', () => { pm.response.to.have.status(200); }); pm.test('Response time is less than 2000ms', () => { pm.expect(pm.response.responseTime).to.be.below(2000); });
The first test checks if the API response status code is exactly 200, which means the request was successful.
The second test checks if the response time is less than 2000 milliseconds, ensuring the API is fast enough.
Both tests use Postman's built-in pm object and assertion methods for clarity and reliability.
Now add tests to verify the API response contains a specific JSON field with expected value for 3 different endpoints
pm.test('API is fast', () => {
pm.expect(pm.response.responseTime).to.be.below(200);
});pm.test('Security headers present', () => {
pm.expect(pm.response.headers.has('Content-Security-Policy')).to.equal(true
});Pass the test and this pattern moves unknown