Test Overview
This test sends a GET request to a sample API endpoint and verifies that the response status code is 200 and the response body contains a specific key with the expected value.
This test sends a GET request to a sample API endpoint and verifies that the response status code is 200 and the response body contains a specific key with the expected value.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Response has userId 1", function () { var jsonData = pm.response.json(); pm.expect(jsonData.userId).to.eql(1); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send GET request to https://jsonplaceholder.typicode.com/posts/1 | Request sent, waiting for response | — | PASS |
| 2 | Receive response with status code 200 and JSON body | Response received: {"userId":1,"id":1,"title":"...","body":"..."} | Check if status code is 200 | PASS |
| 3 | Parse JSON response body | Parsed JSON object available | Verify jsonData.userId equals 1 | PASS |
Output block in Postman primarily display after running a request?console.log() is the standard way to log messages.print(), log(), and echo() are not valid in Postman scripts.pm.test('Status code is 200', () => {
pm.response.to.have.status(200);
});
console.log('Test completed');pm.test('Response time is less than 200ms', () => {
pm.expect(pm.response.responseTime).to.be.below(200);
});
console.log('Check complete');userId with value 5, and log 'User verified' only if the test passes. Which test script will correctly show this in the Output block?Pass the test and this pattern moves unknown