Test Overview
This test sends a GET request to a sample API endpoint and verifies that the response status code is 200, indicating a successful request.
Jump into concepts and practice - no test required
This test sends a GET request to a sample API endpoint and verifies that the response status code is 200, indicating a successful request.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Postman app is open with the test script loaded | — | PASS |
| 2 | Sends GET request to https://jsonplaceholder.typicode.com/posts/1 | Request sent, waiting for response | — | PASS |
| 3 | Receives response with status code 200 | Response received with status 200 OK and JSON body | — | PASS |
| 4 | Runs assertion pm.response.to.have.status(200) | Response status code is 200 | Check if response status code equals 200 | PASS |
| 5 | Test ends with PASS | Test result shows status code assertion passed | — | PASS |
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.