0
0
Postmantesting~20 mins

Header assertions in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Header Assertion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2:00remaining
Check for exact header value
You want to verify that the response header Content-Type exactly equals application/json; charset=utf-8. Which Postman test snippet correctly asserts this?
Apm.test('Content-Type is correct', () => { pm.response.to.have.header('content-type', 'application/json'); });
Bpm.test('Content-Type is correct', () => { pm.response.headers.get('Content-Type') === 'application/json; charset=utf-8'; });
Cpm.test('Content-Type is correct', () => { pm.expect(pm.response.headers['Content-Type']).to.equal('application/json; charset=utf-8'); });
Dpm.test('Content-Type is correct', () => { pm.response.to.have.header('Content-Type', 'application/json; charset=utf-8'); });
Attempts:
2 left
💡 Hint
Use Postman's built-in assertion methods for headers.
assertion
intermediate
2:00remaining
Verify header presence without value check
Which Postman test code correctly asserts that the response contains a header named X-Request-ID, regardless of its value?
Apm.test('X-Request-ID header exists', () => { pm.response.to.have.header('X-Request-ID'); });
Bpm.test('X-Request-ID header exists', () => { pm.expect(pm.response.headers.get('X-Request-ID')).to.exist; });
Cpm.test('X-Request-ID header exists', () => { pm.response.headers.has('X-Request-ID'); });
Dpm.test('X-Request-ID header exists', () => { pm.expect(pm.response.headers['X-Request-ID']).to.be.ok; });
Attempts:
2 left
💡 Hint
Use Postman's header assertion method that checks presence only.
Predict Output
advanced
2:00remaining
Output of header value assertion with regex
What will be the result of this Postman test if the response header Server is nginx/1.18.0?
Postman
pm.test('Server header matches nginx version', () => {
  pm.expect(pm.response.headers.get('Server')).to.match(/^nginx\/\d+\.\d+\.\d+$/);
});
ATest fails due to syntax error in regex.
BTest passes because header matches regex exactly.
CTest fails because regex expects three version numbers but header has only two.
DTest passes because regex matches any string starting with 'nginx'.
Attempts:
2 left
💡 Hint
Check the regex pattern and the actual header value carefully.
🔧 Debug
advanced
2:00remaining
Identify the error in header assertion code
This Postman test is intended to check that the Cache-Control header contains the word no-cache. What is wrong with it?
Postman
pm.test('Cache-Control contains no-cache', () => {
  pm.expect(pm.response.headers.get('Cache-Control')).to.include('no-cache');
});
AThe method 'to.include' does not exist; it should be 'to.contain'.
BIf the header is missing, 'get' returns null and 'to.include' causes an error.
CThe header name should be lowercase 'cache-control' to match.
DThe assertion should use 'pm.response.to.have.header' instead.
Attempts:
2 left
💡 Hint
Consider what happens if the header is not present.
🧠 Conceptual
expert
3:00remaining
Best practice for asserting multiple headers in Postman
You want to assert that the response contains headers Content-Type with value application/json and Cache-Control with value no-store. Which approach is best to ensure clear, maintainable tests?
AWrite separate tests for each header: pm.test('Content-Type check', () => { pm.response.to.have.header('Content-Type', 'application/json'); }); pm.test('Cache-Control check', () => { pm.response.to.have.header('Cache-Control', 'no-store'); });
BUse a single assertion with a custom function to check both headers at once.
CWrite one test with multiple assertions inside: pm.test('Headers check', () => { pm.response.to.have.header('Content-Type', 'application/json'); pm.response.to.have.header('Cache-Control', 'no-store'); });
DCombine headers into one string and assert: pm.test('Headers combined', () => { pm.expect(pm.response.headers.toString()).to.include('Content-Type: application/json').and.to.include('Cache-Control: no-store'); });
Attempts:
2 left
💡 Hint
Think about test clarity and reporting.