0
0
Postmantesting~10 mins

Tests tab and pm.test() 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 create a test that checks if the response status code is 200.

Postman
pm.test('Status code is 200', function () { pm.response.to.have.status([1]); });
Drag options to blanks, or click blank then click option'
A200
B201
C500
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong status code like 404 or 500.
Forgetting to put the status code inside the function call.
2fill in blank
medium

Complete the code to test if the response body contains the string 'success'.

Postman
pm.test('Body contains success', function () { pm.expect(pm.response.text()).to.include([1]); });
Drag options to blanks, or click blank then click option'
A'fail'
B'error'
C'success'
D'warning'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong string that does not appear in the response.
Not using quotes around the string.
3fill in blank
hard

Fix the error in the test code to correctly check if the response header 'Content-Type' is 'application/json'.

Postman
pm.test('Content-Type is JSON', function () { pm.expect(pm.response.headers.get([1])).to.eql('application/json'); });
Drag options to blanks, or click blank then click option'
A'Content-Type'
B'content-type'
C'ContentType'
D'contentType'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or camelCase header names.
Missing quotes around the header name.
4fill in blank
hard

Fill both blanks to test if the JSON response has a property 'success' set to true.

Postman
pm.test('Response success is true', function () { pm.expect(pm.response.json().[1]).to.be.[2]; });
Drag options to blanks, or click blank then click option'
Asuccess
Btrue
Cfalse
Dok
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property name.
Checking for string 'true' instead of boolean true.
5fill in blank
hard

Fill all three blanks to test if the response JSON has a property 'data' which is an array with length greater than 0.

Postman
pm.test('Data array is not empty', function () { pm.expect(pm.response.json().[1]).to.be.an('[2]').and.have.length.[3](0); });
Drag options to blanks, or click blank then click option'
Adata
Barray
Cabove
Dobject
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'object' instead of 'array' for type check.
Using 'length.above' incorrectly or missing it.