0
0
Postmantesting~10 mins

Reporter options (CLI, HTML, JUnit) in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs a Postman collection using Newman CLI and verifies that the test results are correctly reported in CLI, HTML, and JUnit formats.

Test Code - unittest
Postman
import subprocess
import os
import unittest

class TestNewmanReporters(unittest.TestCase):
    def setUp(self):
        self.collection = 'sample_collection.json'
        self.environment = 'sample_environment.json'
        self.report_dir = 'reports'
        os.makedirs(self.report_dir, exist_ok=True)

    def test_newman_cli_report(self):
        # Run Newman with CLI reporter
        result = subprocess.run([
            'newman', 'run', self.collection,
            '-e', self.environment
        ], capture_output=True, text=True)
        self.assertIn('iterations', result.stdout)
        self.assertEqual(result.returncode, 0)

    def test_newman_html_report(self):
        # Run Newman with HTML reporter
        html_report = os.path.join(self.report_dir, 'report.html')
        result = subprocess.run([
            'newman', 'run', self.collection,
            '-e', self.environment,
            '-r', 'html',
            '--reporter-html-export', html_report
        ], capture_output=True, text=True)
        self.assertTrue(os.path.exists(html_report))
        self.assertEqual(result.returncode, 0)

    def test_newman_junit_report(self):
        # Run Newman with JUnit reporter
        junit_report = os.path.join(self.report_dir, 'report.xml')
        result = subprocess.run([
            'newman', 'run', self.collection,
            '-e', self.environment,
            '-r', 'junit',
            '--reporter-junit-export', junit_report
        ], capture_output=True, text=True)
        self.assertTrue(os.path.exists(junit_report))
        self.assertEqual(result.returncode, 0)

if __name__ == '__main__':
    unittest.main()
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test starts - Setup directories and files for reportsReports directory created if not existing-PASS
2Run Newman CLI reporter with collection and environmentNewman runs in terminal, outputs CLI summaryCheck output contains 'iterations' and return code is 0PASS
3Run Newman with HTML reporter and export reportHTML report file generated in reports directoryVerify HTML report file exists and return code is 0PASS
4Run Newman with JUnit reporter and export reportJUnit XML report file generated in reports directoryVerify JUnit report file exists and return code is 0PASS
Failure Scenario
Failing Condition: Newman command fails or report file is not generated
Execution Trace Quiz - 3 Questions
Test your understanding
What does the CLI reporter output verify in the test?
AThat the terminal output contains test summary like 'iterations'
BThat an HTML file is created
CThat a JUnit XML file is created
DThat the collection file exists
Key Result
Always verify both the command execution success and the existence of generated report files to ensure reporter options work correctly.