0
0
Postmantesting~10 mins

Header assertions in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the response has the 'Content-Type' header.

Postman
pm.test('Content-Type header exists', function () {
    pm.response.to.have.header('[1]');
});
Drag options to blanks, or click blank then click option'
AAuthorization
BContent-Type
CAccept
DCache-Control
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong header name like 'Authorization' or 'Accept'.
Misspelling the header name or using lowercase.
2fill in blank
medium

Complete the code to assert the 'Content-Type' header value equals 'application/json'.

Postman
pm.test('Content-Type is application/json', function () {
    pm.response.to.have.header('Content-Type', [1]);
});
Drag options to blanks, or click blank then click option'
A'application/json'
B'text/html'
C'application/xml'
D'text/plain'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect content types like 'text/html' or 'application/xml'.
Forgetting to put quotes around the string value.
3fill in blank
hard

Complete the code to assert the 'Cache-Control' header equals 'no-cache'.

Postman
pm.test('Cache-Control equals no-cache', function () {
    pm.response.to.have.header('Cache-Control', [1]);
});
Drag options to blanks, or click blank then click option'
A'public'
B'no-store'
C'no-cache'
D'max-age=3600'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cache directives like 'no-store' or 'public'.
Missing quotes around the string value.
4fill in blank
hard

Fill both blanks to assert the response header 'Authorization' exists and its value is 'Bearer token123'.

Postman
pm.test('Authorization header check', function () {
    pm.response.to.have.header('[1]');
    pm.expect(pm.response.headers.get('[2]')).to.eql('Bearer token123');
});
Drag options to blanks, or click blank then click option'
AAuthorization
BContent-Type
DCache-Control
Attempts:
3 left
💡 Hint
Common Mistakes
Using different header names in the two blanks.
Checking a wrong header like 'Content-Type' instead of 'Authorization'.
5fill in blank
hard

Fill all three blanks to assert the response header 'Content-Type' exists and its value is 'application/json'.

Postman
pm.test('Content-Type header presence and value', function () {
    pm.response.to.have.header('[1]');
    pm.expect(pm.response.headers.get('[2]')).to.eql('[3]');
});
Drag options to blanks, or click blank then click option'
AContent-Type
BCache-Control
Capplication/json
Dno-store
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing header names between blanks.
Using wrong expected values like 'no-store' for 'Content-Type'.