0
0
Postmantesting~8 mins

Run order and flow control in Postman - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Run order and flow control
Folder Structure
postman-project/
├── collections/
│   ├── UserManagement.postman_collection.json
│   ├── ProductAPI.postman_collection.json
│   └── OrderAPI.postman_collection.json
├── environments/
│   ├── dev.postman_environment.json
│   ├── staging.postman_environment.json
│   └── prod.postman_environment.json
├── scripts/
│   ├── pre-request-scripts/
│   │   └── authSetup.js
│   ├── test-scripts/
│   │   └── responseValidation.js
│   └── flow-control/
│       └── runOrderControl.js
├── reports/
│   └── test-run-report.html
├── postman.config.json
└── README.md
    
Test Framework Layers
  • Collections: Group of API requests organized by feature or module.
  • Environments: Variables for different deployment stages (dev, staging, prod).
  • Pre-request Scripts: Code that runs before each request to set up data or authentication.
  • Test Scripts: Code that runs after each request to validate responses and assert conditions.
  • Flow Control Scripts: Scripts to control run order and conditional execution using Postman features like postman.setNextRequest().
  • Reports: Generated test run reports for analysis.
  • Configuration: Central config file for environment selection and global settings.
Configuration Patterns
  • Environment Files: Store variables like base URLs, tokens, and credentials per environment.
  • Global Variables: Use Postman globals for values shared across collections.
  • Collection Variables: Define variables scoped to a collection for modularity.
  • Run Order Control: Use postman.setNextRequest(requestName) in test scripts to control which request runs next, enabling conditional flows.
  • Data Files: Use CSV or JSON files with Newman to run data-driven tests.
  • Config File: postman.config.json to define default environment and run settings for automation.
Test Reporting and CI/CD Integration
  • Newman CLI: Run Postman collections from command line with options to generate HTML, JSON, or JUnit reports.
  • Reporters: Use built-in reporters like html, json, or third-party reporters for detailed test run insights.
  • CI/CD Integration: Integrate Newman runs into pipelines (Jenkins, GitHub Actions, GitLab CI) to automate API testing on code changes.
  • Fail Fast: Use run order control to stop execution on critical failures by skipping subsequent requests.
  • Artifacts: Store test reports as build artifacts for review and traceability.
Best Practices for Run Order and Flow Control in Postman
  1. Use postman.setNextRequest() to control request flow: This allows conditional execution and dynamic run order based on test results.
  2. Keep collections modular: Organize requests logically so flow control scripts remain clear and maintainable.
  3. Use environment and collection variables: Avoid hardcoding values to enable easy switching between environments and test data.
  4. Fail fast on critical errors: Stop the run early if a key request fails to save time and resources.
  5. Document flow logic: Comment scripts to explain why certain requests run conditionally for easier team understanding.
Self Check

Where in this folder structure would you add a new script to conditionally skip a request based on a previous response?

Key Result
Use postman.setNextRequest() in test scripts to control run order and enable conditional flow in Postman collections.