0
0
Postmantesting~10 mins

Reusable test scripts 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 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'
AcheckStatus
BsendRequest
ClogResponse
DsetHeader
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like 'sendRequest' which do not describe the test purpose.
2fill in blank
medium

Complete 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'
AsendRequest
BcheckStatus
ClogResponse
DsetHeader
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that does not exist or unrelated to status checking.
3fill in blank
hard

Fix 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'
Aduration
Btime
Clatency
DresponseTime
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'duration', 'time' or 'latency' which are not valid properties.
4fill in blank
hard

Fill 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'
A"status"
C"code"
D"message"
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys in the two blanks causing test failure.
5fill in blank
hard

Fill 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'
A"Content-Type"
C"application/json"
D"Accept"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong header names or values causing test failures.