Test Overview
This test checks if the reusable test script correctly validates the response status and content type for an API endpoint. It verifies that the response status is 200 and the content type is JSON.
This test checks if the reusable test script correctly validates the response status and content type for an API endpoint. It verifies that the response status is 200 and the content type is JSON.
pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); pm.test("Content-Type is application/json", function () { pm.response.to.have.header("Content-Type", /application\/json/); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and sends API request | Postman sends HTTP request to the API endpoint | — | PASS |
| 2 | Check if response status code is 200 | Response received with status code 200 | pm.response.to.have.status(200) | PASS |
| 3 | Check if Content-Type header includes 'application/json' | Response headers include Content-Type: application/json | pm.response.to.have.header("Content-Type", /application\/json/) | PASS |
function followed by the function name and parentheses.function checkStatus() {
pm.test('Status is 200', () => pm.response.to.have.status(200));
}
checkStatus();checkStatus runs a test that expects the response status to be 200.function checkResponse() {
pm.test('Response time is less than 200ms', () => {
pm.expect(pm.response.responseTime).to.be.below(200);
});
}
checkResponse
What is the error and how to fix it?checkResponse is defined correctly but called without parentheses, so it does not execute.() after checkResponse calls the function properly and runs the test.to.have.property(key).that.is.not.empty which checks key existence and non-empty value.to.include.key which is invalid.to.have.key(key).not.empty.Pass the test and this pattern moves unknown