0
0
Postmantesting~8 mins

Running a collection in Postman - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Running a collection
Folder Structure
postman-project/
├── collections/
│   └── my-collection.json
├── environments/
│   ├── dev.postman_environment.json
│   └── prod.postman_environment.json
├── tests/
│   └── test-scripts/
│       └── pre-request-scripts.js
├── reports/
│   └── run-report.html
├── newman-config.json
└── README.md
Test Framework Layers
  • Collections: JSON files defining API requests and test scripts grouped logically.
  • Environments: JSON files holding variables for different deployment stages (dev, prod).
  • Test Scripts: JavaScript code for pre-request and test assertions embedded in collections or external files.
  • Utilities: Helper scripts or libraries for common functions used in tests.
  • Configuration: Newman config files or CLI parameters controlling run options like iteration count, environment, reporters.
  • Reports: Output files generated after running collections, showing pass/fail results and details.
Configuration Patterns
  • Environment Variables: Use separate environment JSON files for dev, test, and prod to switch base URLs and credentials easily.
  • Global Variables: Store values shared across collections, like tokens or user IDs.
  • Newman CLI Options: Pass environment, iteration count, reporters, and export report paths via command line or config JSON.
  • Secrets Management: Avoid hardcoding sensitive data; use environment variables or secure vaults integrated with CI/CD.
  • Collection Versioning: Keep collections under version control to track changes and rollback if needed.
Test Reporting and CI/CD Integration
  • Newman Reports: Generate HTML, JSON, or JUnit XML reports after running collections for easy review.
  • CI/CD Pipelines: Integrate Newman runs in pipelines (GitHub Actions, Jenkins, GitLab CI) to automate API testing on code changes.
  • Fail Fast: Configure pipelines to fail if any test in the collection fails, preventing faulty deployments.
  • Notifications: Send test results via email or messaging tools (Slack) after runs.
  • Historical Tracking: Store reports in artifact repositories or dashboards for trend analysis.
Best Practices
  • Modular Collections: Organize requests into logical folders for clarity and reuse.
  • Use Environment Variables: Avoid hardcoding URLs and credentials; use environments for flexibility.
  • Write Clear Assertions: Keep test scripts simple and descriptive for easy debugging.
  • Automate Runs: Use Newman in CI/CD to catch issues early and often.
  • Maintain Reports: Keep test reports accessible and readable for the whole team.
Self Check

Where in this folder structure would you add a new environment file for testing the staging environment?

Key Result
Organize Postman collections, environments, and scripts clearly; run collections with Newman; integrate with CI/CD for automated API testing.