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?
✗ Incorrect
pm.response.headers.get('Header-Name') correctly fetches the value of a response header.
What does the 'Content-Type' header specify in an API response?
✗ Incorrect
The 'Content-Type' header tells the client the format of the response data, like JSON or XML.
If a header assertion fails in Postman, what is the result?
✗ Incorrect
A failed header assertion causes the test to fail and displays an error in the test results.
Which of these is a valid assertion to check a header exists in Postman?
✗ Incorrect
pm.response.to.have.header('Authorization') is the correct syntax to assert header presence.
Why should you test headers in API responses?
✗ Incorrect
Headers contain important info like data format and security details, so testing them ensures correct API behavior.
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.