0
0
Postmantesting~8 mins

Path parameters in Postman - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Path parameters
Folder Structure for Postman API Tests
PostmanTests/
├── collections/
│   └── UserAPI.postman_collection.json
├── environments/
│   ├── dev.postman_environment.json
│   ├── staging.postman_environment.json
│   └── prod.postman_environment.json
├── globals/
│   └── globals.postman_globals.json
├── scripts/
│   ├── pre-request/
│   │   └── setPathParams.js
│   └── tests/
│       └── validateResponse.js
└── README.md
Test Framework Layers in Postman
  • Collections: Group of API requests organized by feature or resource (e.g., User API).
  • Environments: Store variables like base URLs, tokens, and path parameters for different deployment stages.
  • Globals: Variables accessible across all collections and environments.
  • Scripts: JavaScript code for pre-request setup (e.g., setting path parameters) and test assertions after response.
  • Tests: Assertions written in JavaScript to verify API responses, status codes, and data correctness.
Configuration Patterns for Path Parameters in Postman
  • Use Environment Variables: Define path parameters as variables in environment files (e.g., {{userId}}).
  • Dynamic Path Parameters: Use variable placeholders in request URLs like /users/{{userId}} to substitute values at runtime.
  • Pre-request Scripts: Optionally set or modify path parameter variables before sending requests.
  • Multiple Environments: Maintain separate environment files for dev, staging, and prod with different parameter values.
  • Secure Sensitive Data: Store tokens or credentials in environment variables, not hardcoded in requests.
Test Reporting and CI/CD Integration
  • Postman Test Results: View test pass/fail status in Postman Test Results tab after running collections.
  • Newman CLI: Run Postman collections from command line with newman to automate tests.
  • CI/CD Integration: Integrate Newman runs into pipelines (e.g., Jenkins, GitHub Actions) to run API tests on code changes.
  • Report Formats: Generate HTML, JSON, or JUnit reports from Newman for easy analysis.
  • Alerts: Configure pipeline to notify team on test failures via email or chat tools.
Best Practices for Path Parameters in Postman Framework
  1. Use Clear Variable Names: Name path parameters descriptively (e.g., userId, orderId) for readability.
  2. Keep Environments Updated: Regularly update environment variables to reflect current test data and endpoints.
  3. Reuse Variables: Use environment or global variables to avoid duplication and ease maintenance.
  4. Validate Parameter Usage: Add tests to confirm path parameters are correctly substituted and API responds as expected.
  5. Document Variables: Maintain README or documentation explaining what each path parameter variable means and where it is used.
Self Check Question

Where in this folder structure would you add a new path parameter variable for a "productId" used in the Product API requests?

Key Result
Use environment variables to manage path parameters dynamically in Postman API tests.