Sometimes the only thing you need to test is a header, and a Postman header test covers it. This is when a PDF or something else is returned. Below is how you can test a header.
Testing for Correct Headers and PDF Responses
Below are test you can run on headers. The great thing about this is it allows us to find out if a PDF was passed as that will be in the headers.
pm.test("Headers are correct", function () {
pm.response.to.have.header("Content-Type", 'application/pdf');
pm.response.to.have.header("Content-Disposition");
pm.expect(postman.getResponseHeader("Content-Disposition")).to.contain('filename="application.pdf"', 'No application.pdf was passed.')
})More Testing with Postman
- Testing with Postman: Getting Started
- Testing with Postman: Variables
- Testing with Postman: Reusable Code
- Testing with Postman: Looping Test
- Testing with Postman: Chai Assertions
- Testing with Postman: Moment
- Testing with Postman: Lodash
- Testing with Postman: Checking Schema
- Testing with Postman: Newman for CI/CD
- Testing with Postman: A Complete Guide to Automation
Links
Postman Quick Reference Guide
Chai Assertion Library
Regex Cheat Sheet
Postman: The Complete Guide on Udemy
