Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a reusable test script function in Postman.
Postman
function [1]() { pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like 'sendRequest' which do not describe the test purpose.
✗ Incorrect
The function name 'checkStatus' clearly describes the reusable test script checking the status code.
2fill in blank
mediumComplete the code to call the reusable test script function inside another test.
Postman
pm.test("Check response status", function () { [1](); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that does not exist or unrelated to status checking.
✗ Incorrect
Calling 'checkStatus()' runs the reusable test script that checks the status code.
3fill in blank
hardFix the error in the reusable test script by completing the missing Postman assertion.
Postman
function checkResponseTime() {
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.[1]).to.be.below(200);
});
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'duration', 'time' or 'latency' which are not valid properties.
✗ Incorrect
In Postman, 'pm.response.responseTime' gives the response time in milliseconds.
4fill in blank
hardFill both blanks to create a reusable test script that checks if a JSON response has a specific key and its value.
Postman
function checkJsonKey() {
const jsonData = pm.response.json();
pm.test("Response has key", function () {
pm.expect(jsonData).to.have.property([1]);
pm.expect(jsonData[[2]]).to.eql("success");
});
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys in the two blanks causing test failure.
✗ Incorrect
The test checks that the JSON response has the key 'status' and its value equals 'success'.
5fill in blank
hardFill all three blanks to create a reusable test script that checks a header exists and its value matches expected.
Postman
function checkHeader() {
pm.test("Content-Type header is present", 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong header names or values causing test failures.
✗ Incorrect
The test checks that the 'Content-Type' header exists and equals 'application/json'.