{"library":"newman","title":"Newman - Postman CLI Runner","description":"Newman is a powerful command-line collection runner for Postman, enabling users to execute and test Postman collections directly from the command line without the Postman GUI. It is primarily designed for integration into continuous integration and continuous delivery (CI/CD) pipelines and other automated build systems to facilitate automated API testing. The current stable version is 6.2.2. While there isn't a fixed release cadence, the project is actively maintained, with major versions typically introducing Node.js compatibility updates and dependency upgrades (e.g., v6 was released in late 2023). Key differentiators include its seamless integration with Postman collections, support for various output reporters (CLI, JSON, JUnit, HTML), and its capability for programmatic use as a Node.js library, offering a robust solution for automated API testing workflows.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install newman"],"cli":{"name":"newman","version":null}},"imports":["import newman from 'newman';","import type { NewmanRunOptions } from 'newman';","import type { NewmanRunSummary } from 'newman';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import newman from 'newman';\nimport path from 'path';\nimport fs from 'fs';\n\n// Create a dummy collection file for demonstration\nconst dummyCollectionPath = path.resolve(__dirname, 'dummy-collection.json');\nconst dummyCollectionContent = {\n  \"info\": {\n    \"_postman_id\": \"b8c5f2b8-f3d9-4b6a-8b1b-c7e1e4f9b8c2\",\n    \"name\": \"Dummy API Tests\",\n    \"schema\": \"https://schema.getpostman.com/json/collection/v2.1.0/collection.json\"\n  },\n  \"item\": [\n    {\n      \"name\": \"Test Get Request\",\n      \"request\": {\n        \"method\": \"GET\",\n        \"header\": [],\n        \"url\": {\n          \"raw\": \"https://postman-echo.com/get?foo=bar\",\n          \"protocol\": \"https\",\n          \"host\": [\"postman-echo\", \"com\"],\n          \"path\": [\"get\"],\n          \"query\": [\n            {\n              \"key\": \"foo\",\n              \"value\": \"bar\"\n            }\n          ]\n        }\n      },\n      \"response\": []\n    }\n  ]\n};\n\nfs.writeFileSync(dummyCollectionPath, JSON.stringify(dummyCollectionContent, null, 2));\n\nconsole.log(`Running collection: ${dummyCollectionPath}`);\n\nnewman.run({\n  collection: dummyCollectionPath,\n  reporters: ['cli', 'json'],\n  reporter: {\n    json: {\n      export: './newman-report.json'\n    }\n  },\n  environment: {  // Example of passing environment variables programmatically\n    values: [\n      { key: 'baseUrl', value: 'https://postman-echo.com', enabled: true }\n    ]\n  }\n}, (err, summary) => {\n  // Clean up dummy file after run\n  fs.unlinkSync(dummyCollectionPath);\n\n  if (err) {\n    console.error('Collection run encountered an error:', err);\n    return;\n  }\n\n  if (summary.run.failures.length) {\n    console.error('Collection run completed with failures:');\n    summary.run.failures.forEach(failure => {\n      console.error(`  - ${failure.error.message} in ${failure.source.name}`);\n    });\n  } else {\n    console.log('Collection run completed successfully!');\n    console.log(`Total requests: ${summary.run.stats.requests.total}`);\n    console.log(`Total assertions: ${summary.run.stats.assertions.total}`);\n    console.log(`Assertions failed: ${summary.run.stats.assertions.failed}`);\n    console.log('JSON report generated at ./newman-report.json');\n  }\n});","lang":"typescript","description":"This quickstart demonstrates how to programmatically run a Postman collection using Newman as a Node.js library, including specifying reporters and handling the run summary for success or failure states. It generates a temporary collection file and cleans it up after execution.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}