0
0
Postmantesting~5 mins

Output block in Postman

Choose your learning style9 modes available
Introduction

An output block in Postman shows the results of your test scripts after running a request. It helps you see if your tests passed or failed.

After sending an API request to check if the response is correct
When you want to verify that your test scripts are working as expected
To quickly see errors or success messages from your tests
When debugging your API tests to find issues
To confirm that your assertions match the API response
Syntax
Postman
// Example of test script output in Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});

console.log('Test completed');

The output block shows results from pm.test() assertions and console.log() messages.

You can view the output block in the Postman app under the Test Results tab after running a request.

Examples
This test checks if the API response time is under 500 milliseconds.
Postman
pm.test('Response time is less than 500ms', function () {
    pm.expect(pm.response.responseTime).to.be.below(500);
});
This test verifies that the response body is in JSON format.
Postman
pm.test('Response has JSON body', function () {
    pm.response.to.be.json();
});
This prints the response status code to the output block for debugging.
Postman
console.log('Response status:', pm.response.code);
Sample Program

This script runs two tests: one checks if the status code is 200, the other checks if the response JSON has a userId property. It also logs a message to the output block.

Postman
// Test script in Postman
pm.test('Status code is 200', function () {
    pm.response.to.have.status(200);
});

pm.test('Response body has userId', function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData).to.have.property('userId');
});

console.log('Tests finished');
OutputSuccess
Important Notes

Use pm.test() to create tests that show pass or fail in the output block.

Use console.log() to print helpful messages or variable values for debugging.

The output block updates only after you send the request and run the tests.

Summary

The output block shows test results and logs after running a request.

It helps you quickly see if your API tests passed or failed.

Use it to debug and verify your test scripts in Postman.