0
0
Postmantesting~5 mins

Header assertions in Postman - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a header assertion in API testing?
A header assertion checks if the response headers from an API contain expected values, like content type or authorization status.
Click to reveal answer
beginner
How do you assert a response header in Postman?
Use the test script with pm.response.headers.get('Header-Name') and compare it to the expected value using assertions.
Click to reveal answer
beginner
Why is it important to check the 'Content-Type' header in API responses?
Because it tells the client how to interpret the response data, like JSON or HTML, ensuring correct processing.
Click to reveal answer
intermediate
Example of a Postman test script to check if 'Content-Type' is 'application/json'.
pm.test('Content-Type is application/json', () => { pm.response.to.have.header('Content-Type'); pm.expect(pm.response.headers.get('Content-Type')).to.include('application/json'); });
Click to reveal answer
beginner
What happens if a header assertion fails in Postman?
The test will fail and show an error in the test results, indicating the header did not match the expected value.
Click to reveal answer
Which Postman method retrieves a response header value?
Apm.response.header('Header-Name')
Bpm.request.headers.get('Header-Name')
Cpm.response.body.get('Header-Name')
Dpm.response.headers.get('Header-Name')
What does the 'Content-Type' header specify in an API response?
AThe size of the response body
BThe format of the response data
CThe server's IP address
DThe HTTP status code
If a header assertion fails in Postman, what is the result?
AThe test fails and shows an error
BThe response body is ignored
CThe request is retried automatically
DThe test passes silently
Which of these is a valid assertion to check a header exists in Postman?
Apm.response.header.exists('Authorization')
Bpm.response.has.header('Authorization')
Cpm.response.to.have.header('Authorization')
Dpm.response.check.header('Authorization')
Why should you test headers in API responses?
ATo verify response data format and security info
BTo check the server's uptime
CTo measure response time
DTo validate the request payload
Explain how to write a Postman test to assert that the 'Content-Type' header is 'application/json'.
Think about checking header presence first, then comparing its value.
You got /4 concepts.
    Why are header assertions important in API testing? Give two reasons.
    Consider what headers tell the client about the response.
    You got /3 concepts.