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.
This test runs a Postman collection using Newman CLI and verifies that the test results are correctly reported in CLI, HTML, and JUnit formats.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts - Setup directories and files for reports | Reports directory created if not existing | - | PASS |
| 2 | Run Newman CLI reporter with collection and environment | Newman runs in terminal, outputs CLI summary | Check output contains 'iterations' and return code is 0 | PASS |
| 3 | Run Newman with HTML reporter and export report | HTML report file generated in reports directory | Verify HTML report file exists and return code is 0 | PASS |
| 4 | Run Newman with JUnit reporter and export report | JUnit XML report file generated in reports directory | Verify JUnit report file exists and return code is 0 | PASS |