Verify API returns status code 200 for GET /users
Preconditions (2)
✅ Expected Result: The response status code should be 200
Jump into concepts and practice - no test required
pm.test('Status code is 200', () => { pm.response.to.have.status(200); });
This test script uses Postman's built-in pm object to check the response status code.
pm.test defines a test with a descriptive name.
pm.response.to.have.status(200) asserts that the response status code equals 200.
This is simple and clear, making it easy to understand and maintain.
Now add data-driven testing with 3 different API endpoints and verify each returns status code 200
200 usually mean in a Postman response?pm.response.to.have.status(code).pm.response.to.have.status() [OK]pm.test('Check status', () => {
pm.response.to.have.status(201);
});pm.test('Status is 200', () => {
pm.response.to.have.status = 200;
});= which assigns a value instead of calling status(200) as a function.pm.response.to.have.status(200); to assert status code.status().pm.expect with a boolean expression checking if code is 200 or 201, which is correct.