Test Overview
This test sends a GET request to a sample API endpoint and verifies that the response status code is 200, indicating success.
This test sends a GET request to a sample API endpoint and verifies that the response status code is 200, indicating success.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Send GET request to https://jsonplaceholder.typicode.com/posts/1 | Postman sends the HTTP request to the server | — | PASS |
| 2 | Receive response from server | Response received with status code 200 and JSON body | — | PASS |
| 3 | Run test script to check status code | Test script executes pm.response.to.have.status(200) | Verify response status code equals 200 | PASS |
Send request block in Postman?pm.sendRequest({
url: 'https://api.example.com/data',
method: 'GET'
}, function (err, res) {
pm.test('Status code is 200', function () {
pm.expect(res.code).to.eql(200);
});
});
What will happen when this script runs?pm.sendRequest({
url: 'https://api.example.com/users',
method: 'POST',
body: {
mode: 'raw',
raw: JSON.stringify({name: 'John'})
}
}, function (err, res) {
// callback function
});
But the request is not sent. What is the likely problem?success set to true. Which Postman script correctly sends the request and tests the response?Pass the test and this pattern moves unknown