0
0
Postmantesting~10 mins

Default and conditional responses 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 set a default response status code in Postman test script.

Postman
pm.test('Status code is 200', function () { pm.response.to.have.status([1]); });
Drag options to blanks, or click blank then click option'
A201
B404
C500
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 or 500 as default success status codes.
Confusing 201 (Created) with 200 (OK).
2fill in blank
medium

Complete the code to check if the response body contains the word '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'error'
B'success'
C'fail'
D'warning'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect strings like 'error' or 'fail'.
Forgetting to include quotes around the string.
3fill in blank
hard

Fix the error in the conditional test to check if status code is 404.

Postman
pm.test('Status code is 404', function () { pm.response.to.have.status([1]); });
Drag options to blanks, or click blank then click option'
A404
B400
C200
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 or 500 instead of 404.
Confusing 200 with 404.
4fill in blank
hard

Fill both blanks to check if response JSON has a key 'status' equal to 'success'.

Postman
pm.test('Response status is success', function () { const jsonData = pm.response.json(); pm.expect(jsonData.[1]).to.eql([2]); });
Drag options to blanks, or click blank then click option'
Astatus
B'success'
C'status'
Dsuccess
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the key when accessing jsonData (should be without quotes).
Not quoting the expected string value.
5fill in blank
hard

Fill all three blanks to write a conditional test that checks if response code is 200 and response body contains 'OK'.

Postman
pm.test('Status 200 and body contains OK', function () { pm.expect(pm.response.code).to.equal([1]); pm.expect(pm.response.text()).to.include([2]); if (pm.response.code === [3]) { console.log('Response is OK'); } });
Drag options to blanks, or click blank then click option'
A200
B'OK'
C404
D'Error'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong status codes like 404 in conditions.
Forgetting quotes around string 'OK'.