0
0
Postmantesting~20 mins

Output block in Postman - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Postman Output Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Postman test script?
Consider this Postman test script that checks the response status and sets a variable. What will be the value of the variable isSuccess after running this test if the response status is 200?
Postman
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
    pm.variables.set("isSuccess", true);
});
AThe variable isSuccess is set to false
BThe variable isSuccess is set to true
CThe variable isSuccess is not set
DThe test script throws an error
Attempts:
2 left
💡 Hint
Think about what happens when the status code matches 200 in the test.
assertion
intermediate
2:00remaining
Which assertion correctly verifies the JSON response contains a key 'userId' with value 5?
You want to assert that the JSON response body has a key 'userId' equal to 5. Which Postman test assertion is correct?
Postman
const jsonData = pm.response.json();
Apm.expect(jsonData.userId).to.eql(5);
Bpm.expect(jsonData['userId']).to.be.undefined;
Cpm.expect(jsonData.userId).to.be.above(5);
Dpm.expect(jsonData.userId).to.not.eql(5);
Attempts:
2 left
💡 Hint
Look for the assertion that checks equality to 5.
🔧 Debug
advanced
2:00remaining
Why does this Postman test script fail with a ReferenceError?
Examine the test script below. Why does it throw a ReferenceError when run?
Postman
pm.test("Check user name", function () {
    pm.expect(user.name).to.eql("Alice");
});
AThe response does not contain a 'name' key
BThe pm.expect syntax is incorrect
CThe test function is missing a closing bracket
DThe variable 'user' is not defined before use
Attempts:
2 left
💡 Hint
Check if the variable 'user' is declared or assigned.
framework
advanced
2:00remaining
Which Postman test script correctly waits for an asynchronous fetch before asserting?
You want to fetch additional data asynchronously inside a test and then assert a value. Which script correctly handles the async operation?
A
pm.test("Async test", function () {
    fetch('https://api.example.com/data').then(res => res.json()).then(data => {
        pm.expect(data.status).to.eql('ok');
    });
});
B
pm.test("Async test", function () {
    const res = fetch('https://api.example.com/data');
    const data = res.json();
    pm.expect(data.status).to.eql('ok');
});
C
pm.test("Async test", async function () {
    const res = await fetch('https://api.example.com/data');
    const data = await res.json();
    pm.expect(data.status).to.eql('ok');
});
D
pm.test("Async test", function () {
    const data = fetch('https://api.example.com/data').json();
    pm.expect(data.status).to.eql('ok');
});
Attempts:
2 left
💡 Hint
Remember that async functions need to be awaited or handled with promises properly.
🧠 Conceptual
expert
2:00remaining
What is the main purpose of the Postman 'Tests' output block?
In Postman, the 'Tests' output block shows results after running a request. What is its main purpose?
ATo display the results of test scripts including pass/fail status and assertion messages
BTo edit the request body before sending
CTo show the raw HTTP request headers sent to the server
DTo configure environment variables for the request
Attempts:
2 left
💡 Hint
Think about what you see after tests run in Postman.