Bird
Raised Fist0
Postmantesting~10 mins

Output block in Postman - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to log the response status code in Postman test script.

Postman
pm.test("Status code is 200", function () {
    pm.expect(pm.response.[1]).to.eql(200);
});
Drag options to blanks, or click blank then click option'
Acode
Bstatus
Cbody
Dheaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.status instead of pm.response.code
Trying to access pm.response.body for status code
2fill in blank
medium

Complete the code to check if the response body contains the string 'success'.

Postman
pm.test("Body contains success", function () {
    pm.expect(pm.response.text().[1]("success")).to.be.true;
});
Drag options to blanks, or click blank then click option'
Asearch
BindexOf
Cincludes
Dmatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using indexOf which returns a number, not a boolean
Using match which returns an array or null
3fill in blank
hard

Fix the error in the code to correctly parse JSON response and check a property.

Postman
pm.test("Check user id", function () {
    let jsonData = pm.response.[1]();
    pm.expect(jsonData.userId).to.eql(1);
});
Drag options to blanks, or click blank then click option'
Ajson
Btext
Cbody
Draw
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.text() which returns a string, not an object
Trying to access pm.response.body() which is not a method
4fill in blank
hard

Fill both blanks to check if the response header 'Content-Type' is 'application/json'.

Postman
pm.test("Content-Type is JSON", function () {
    pm.expect(pm.response.[1].get([2])).to.eql('application/json');
});
Drag options to blanks, or click blank then click option'
Aheaders
B"Content-Type"
C"content-type"
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Using pm.response.body instead of headers
Not quoting the header name string
5fill in blank
hard

Fill all three blanks to create a test that checks if the response time is less than 200ms.

Postman
pm.test("Response time is fast", function () {
    pm.expect(pm.response.[1]).to.be.[2]([3]);
});
Drag options to blanks, or click blank then click option'
AresponseTime
Bbelow
C200
Dabove
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'above' instead of 'below' for less than check
Not using the correct property name for response time

Practice

(1/5)
1. What does the Output block in Postman primarily display after running a request?
easy
A. The list of saved environments
B. The raw API request headers only
C. The Postman app settings and preferences
D. The results of test scripts and any console logs

Solution

  1. Step 1: Understand the purpose of the Output block

    The Output block shows what happened after running a request, including test results and logs.
  2. Step 2: Identify what is NOT shown in the Output block

    Settings, environments, or just headers are not shown here; only test results and logs appear.
  3. Final Answer:

    The results of test scripts and any console logs -> Option D
  4. Quick Check:

    Output block = test results + logs [OK]
Hint: Output block shows test results and logs only [OK]
Common Mistakes:
  • Confusing Output block with environment settings
  • Thinking it shows only request headers
  • Assuming it displays saved collections
2. Which of the following is the correct way to log a message to the Output block in a Postman test script?
easy
A. log('Test passed')
B. print('Test passed')
C. console.log('Test passed')
D. echo('Test passed')

Solution

  1. Step 1: Recall JavaScript logging syntax in Postman

    Postman test scripts use JavaScript, and console.log() is the standard way to log messages.
  2. Step 2: Identify incorrect logging functions

    Functions like print(), log(), and echo() are not valid in Postman scripts.
  3. Final Answer:

    console.log('Test passed') -> Option C
  4. Quick Check:

    Use console.log() to log messages [OK]
Hint: Use console.log() to print messages in Output block [OK]
Common Mistakes:
  • Using print() instead of console.log()
  • Trying to use echo() which is not JavaScript
  • Forgetting parentheses in console.log
3. Given this Postman test script:
pm.test('Status code is 200', () => {
    pm.response.to.have.status(200);
});
console.log('Test completed');

What will you see in the Output block after running the request if the response status is 200?
medium
A. Test failed and no message
B. Test passed and 'Test completed' message
C. Only 'Test completed' message
D. No output at all

Solution

  1. Step 1: Analyze the test script behavior

    The test checks if the response status is 200. If true, the test passes.
  2. Step 2: Understand console.log output

    The console.log prints 'Test completed' regardless of test result.
  3. Final Answer:

    Test passed and 'Test completed' message -> Option B
  4. Quick Check:

    Passing test + console.log message = Test passed and 'Test completed' message [OK]
Hint: Passing test shows pass + console.log output [OK]
Common Mistakes:
  • Assuming console.log only shows on failure
  • Thinking test fails if console.log runs
  • Ignoring test result messages
4. You wrote this Postman test script:
pm.test('Response time is less than 200ms', () => {
    pm.expect(pm.response.responseTime).to.be.below(200);
});
console.log('Check complete');

But after running, the Output block shows no test results or logs. What is the most likely problem?
medium
A. The test script is not saved or attached to the request
B. The response time is exactly 200ms, so test is skipped
C. console.log is not supported in Postman
D. The Output block only shows errors, not passes

Solution

  1. Step 1: Check why Output block is empty

    If no test results or logs appear, the script might not be running at all.
  2. Step 2: Confirm script attachment and saving

    Scripts must be saved and attached to the request to run and show output.
  3. Final Answer:

    The test script is not saved or attached to the request -> Option A
  4. Quick Check:

    Unsaved script = no output [OK]
Hint: Always save and attach test scripts to see output [OK]
Common Mistakes:
  • Thinking console.log is unsupported
  • Assuming Output block hides passing tests
  • Believing test skips on exact boundary values
5. You want to verify in Postman that a JSON response contains a key userId with value 5, and log 'User verified' only if the test passes. Which test script will correctly show this in the Output block?
hard
A. pm.test('UserId is 5', () => { pm.expect(pm.response.json().userId).to.eql(5); }); if(pm.response.json().userId === 5) console.log('User verified');
B. pm.test('UserId is 5', () => { pm.expect(pm.response.json().userId).to.eql(5); console.log('User verified'); });
C. if(pm.response.json().userId === 5) { pm.test('UserId is 5', () => {}); console.log('User verified'); }
D. pm.test('UserId is 5', () => { pm.expect(pm.response.json().userId).to.eql(5); }); console.log('User verified');

Solution

  1. Step 1: Understand conditional logging requirement

    pm.test callbacks always execute fully; assertions don't halt execution. Log only on pass requires a matching condition.
  2. Step 2: Analyze options

    A: unconditional log after test - always logs.
    B: log inside pm.test - executes even if assertion fails.
    C: empty pm.test - no proper verification.
    D: proper assertion test + matching if condition - logs only if userId === 5 (test passes).
  3. Final Answer:

    pm.test('UserId is 5', () => { pm.expect(pm.response.json().userId).to.eql(5); }); if(pm.response.json().userId === 5) console.log('User verified'); -> Option A
  4. Quick Check:

    if() matching test condition = log only on pass [OK]
Hint: Use if() matching assertion after pm.test for log only on pass [OK]
Common Mistakes:
  • Putting console.log inside pm.test (runs on fail too)
  • Logging unconditionally outside pm.test
  • Using empty pm.test callback
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard