0
0
Postmantesting~10 mins

Header assertions in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GET request to an API endpoint and verifies that the response headers contain the expected content type and server information.

Test Code - Postman
Postman
pm.test("Response has correct Content-Type header", function () {
    pm.response.to.have.header("Content-Type");
    pm.expect(pm.response.headers.get("Content-Type")).to.include("application/json");
});

pm.test("Response has Server header", function () {
    pm.response.to.have.header("Server");
    pm.expect(pm.response.headers.get("Server")).to.equal("nginx/1.18.0");
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Send GET request to the API endpointRequest sent, waiting for response-PASS
2Check if response has 'Content-Type' headerResponse received with headersVerify 'Content-Type' header existsPASS
3Verify 'Content-Type' header includes 'application/json'Header value is 'application/json; charset=utf-8'Check header value contains 'application/json'PASS
4Check if response has 'Server' headerResponse headers availableVerify 'Server' header existsPASS
5Verify 'Server' header equals 'nginx/1.18.0'Header value is 'nginx/1.18.0'Check header value equals expected stringPASS
Failure Scenario
Failing Condition: The response does not include the expected 'Content-Type' or 'Server' headers or their values differ
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check first after receiving the response?
AIf the response body is empty
BIf the 'Content-Type' header exists
CIf the status code is 404
DIf the 'Authorization' header is present
Key Result
Always verify both the presence and the exact value or pattern of response headers to ensure the API behaves as expected.