Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 or 500 as default success status codes.
Confusing 201 (Created) with 200 (OK).
✗ Incorrect
The default successful HTTP status code is 200, so the test should check for status 200.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect strings like 'error' or 'fail'.
Forgetting to include quotes around the string.
✗ Incorrect
The test checks if the response text includes the string 'success'.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 or 500 instead of 404.
Confusing 200 with 404.
✗ Incorrect
The test must check for status 404 to confirm the resource was not found.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the key when accessing jsonData (should be without quotes).
Not quoting the expected string value.
✗ Incorrect
The JSON key is accessed as jsonData.status and compared to the string 'success'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong status codes like 404 in conditions.
Forgetting quotes around string 'OK'.
✗ Incorrect
The test checks that the status code equals 200, the body includes 'OK', and logs a message if code is 200.