Introduction
Status codes tell us if a web request worked or not. They help us understand the result quickly.
Status codes tell us if a web request worked or not. They help us understand the result quickly.
pm.response.code
This code gets the numeric status code from the response.
Common codes: 200 means OK, 404 means Not Found, 500 means Server Error.
pm.test("Status code is 200", () => { pm.response.to.have.status(200); });
if(pm.response.code === 404) { console.log("Page not found"); }
pm.test("Status code is success", () => { pm.expect(pm.response.code).to.be.within(200, 299); });
This Postman test script checks if the response status is 200. It also logs a message if the status is 404.
pm.test("Check if response status is 200", () => { pm.response.to.have.status(200); }); pm.test("Log message for 404 status", () => { if(pm.response.code === 404) { console.log("Resource not found"); } });
Always check status codes before reading response data.
Use status codes to decide next test steps or error handling.
Status codes show if a request worked or failed.
Use pm.response.code to read the status code in Postman.
Write tests to check for expected status codes.
200 usually mean in Postman response testing?pm.test('Check status', () => {
pm.expect(pm.response.code).to.be.oneOf([200, 201]);
});pm.test('Status is 200', () => {
pm.expect(pm.response.code = 200);
});Pass the test and this pattern moves unknown