0
0
Postmantesting~15 mins

Running a collection in Postman - Deep Dive

Choose your learning style9 modes available
Overview - Running a collection
What is it?
Running a collection in Postman means executing a group of API requests together in a sequence. It helps test multiple endpoints or workflows automatically without clicking each request manually. This process can include setting variables, running tests, and viewing results in one go. It is useful for checking if APIs work as expected across different scenarios.
Why it matters
Without running collections, testers would manually send each API request one by one, which is slow and error-prone. Running collections automates this, saving time and ensuring consistent testing. It helps catch bugs early by running many tests quickly and repeatedly. This improves software quality and speeds up development cycles.
Where it fits
Before running a collection, you should know how to create and save individual API requests in Postman. After learning to run collections, you can explore running them with different environments, scheduling runs, and integrating with CI/CD pipelines for automated testing.
Mental Model
Core Idea
Running a collection is like pressing 'play' on a playlist of API requests to test them all automatically in order.
Think of it like...
Imagine a playlist of songs you want to listen to without picking each one manually. Running a collection is like hitting 'play' on that playlist so all songs play one after another without stopping.
┌───────────────┐
│ Collection    │
│ ┌───────────┐ │
│ │ Request 1 │ │
│ └───────────┘ │
│ ┌───────────┐ │
│ │ Request 2 │ │
│ └───────────┘ │
│     ...       │
│ ┌───────────┐ │
│ │ Request N │ │
│ └───────────┘ │
└───────┬───────┘
        │
        ▼
┌───────────────┐
│ Runner        │
│ Executes each │
│ request in    │
│ sequence      │
└───────┬───────┘
        │
        ▼
┌───────────────┐
│ Results       │
│ Pass/Fail &   │
│ Logs          │
└───────────────┘
Build-Up - 7 Steps
1
FoundationWhat is a Postman Collection
🤔
Concept: Introduce the idea of grouping API requests into a collection.
A Postman collection is a folder that holds multiple API requests. Instead of testing one request at a time, you can organize related requests together. For example, all requests for user management can be in one collection.
Result
You have a named group of API requests saved in Postman.
Understanding collections helps organize tests logically, making it easier to run and maintain them.
2
FoundationManual Execution of Single Requests
🤔
Concept: Explain how to send one API request manually in Postman.
In Postman, you select a request and click 'Send' to execute it. You see the response and can check if it works. This is simple but slow for many requests.
Result
You get the response for one API call at a time.
Knowing manual execution is the base before automating multiple requests.
3
IntermediateUsing the Collection Runner
🤔Before reading on: do you think running a collection sends all requests at once or one after another? Commit to your answer.
Concept: Learn how the Collection Runner executes requests sequentially.
Postman has a Collection Runner tool that runs all requests in a collection one by one automatically. You open the runner, select your collection, and click 'Run'. It sends each request in order and shows results.
Result
All requests in the collection run in sequence without manual clicks.
Understanding sequential execution helps predict test flow and debug failures.
4
IntermediateSetting Environment Variables for Runs
🤔Before reading on: do you think environment variables change during a collection run or stay fixed? Commit to your answer.
Concept: Introduce environment variables to customize requests during runs.
Environments store variables like URLs or tokens. When running a collection, you can select an environment so requests use those variable values. This allows testing the same collection against different servers or users.
Result
Requests use dynamic values from the selected environment during the run.
Knowing environment variables enables flexible and reusable tests across setups.
5
IntermediateAdding Tests and Assertions in Requests
🤔Before reading on: do you think tests run after each request or only at the end? Commit to your answer.
Concept: Explain how to write tests that check responses automatically during runs.
In Postman, you can add test scripts to each request. These scripts check if the response meets expectations, like status code 200 or specific data. When running a collection, these tests run after each request and show pass/fail results.
Result
You get detailed feedback on each request's success during the collection run.
Adding tests turns simple requests into automated checks, improving reliability.
6
AdvancedUsing Data Files for Data-Driven Runs
🤔Before reading on: do you think data files run requests once or multiple times with different data? Commit to your answer.
Concept: Teach how to run collections multiple times with different input data from files.
Postman lets you upload CSV or JSON files with data sets. When running a collection with a data file, each row runs the collection once with that data. This helps test many input cases automatically.
Result
The collection runs repeatedly, each time using different data from the file.
Data-driven runs enable broad test coverage without manual repetition.
7
ExpertIntegrating Collection Runs in CI/CD Pipelines
🤔Before reading on: do you think collection runs can be automated outside Postman app? Commit to your answer.
Concept: Show how to run collections automatically in development pipelines using Newman.
Newman is Postman's command-line tool to run collections. Developers integrate Newman in CI/CD tools like Jenkins or GitHub Actions to run tests automatically on code changes. This ensures APIs stay reliable without manual testing.
Result
Collections run automatically in pipelines, providing continuous feedback on API health.
Automating collection runs in pipelines is key for fast, reliable software delivery.
Under the Hood
When you run a collection, Postman sends each HTTP request in the order saved. After each request, it executes any test scripts attached to check the response. Variables are resolved from the selected environment or data files before sending. Results and logs are collected and displayed in the runner interface. Internally, Postman manages asynchronous HTTP calls and script execution in a controlled sequence to ensure order and data flow.
Why designed this way?
Postman was designed to simplify API testing by grouping requests and automating their execution. Sequential runs reflect real-world API workflows where order matters. Using environments and data files allows reuse and flexibility. Newman CLI was created to integrate testing into automated pipelines, reflecting modern DevOps practices. Alternatives like manual testing or separate scripts were slower and error-prone.
┌───────────────┐
│ Collection    │
│ Requests 1..N │
└───────┬───────┘
        │
        ▼
┌───────────────┐
│ Runner Engine │
│ - Sends HTTP  │
│ - Runs Tests  │
│ - Handles Vars│
└───────┬───────┘
        │
        ▼
┌───────────────┐
│ Results Panel │
│ - Pass/Fail   │
│ - Logs       │
└───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does running a collection send all requests at the exact same time? Commit to yes or no.
Common Belief:Running a collection sends all requests simultaneously to save time.
Tap to reveal reality
Reality:Postman runs requests one after another in sequence, not all at once.
Why it matters:Assuming parallel execution can cause confusion when tests depend on order or shared data.
Quick: Do environment variables change automatically during a collection run? Commit to yes or no.
Common Belief:Environment variables remain fixed and cannot be changed during a run.
Tap to reveal reality
Reality:Tests and scripts can update environment variables during a run, affecting subsequent requests.
Why it matters:Not knowing this can lead to missed opportunities for dynamic workflows and cause test failures.
Quick: Can you run a collection with different data sets without changing requests manually? Commit to yes or no.
Common Belief:You must edit each request manually to test different input data.
Tap to reveal reality
Reality:Postman supports data-driven runs using external files to automate multiple test cases.
Why it matters:Ignoring data-driven testing limits test coverage and wastes time.
Quick: Is Newman only for running collections inside the Postman app? Commit to yes or no.
Common Belief:Newman is just a different interface for Postman collections within the app.
Tap to reveal reality
Reality:Newman is a separate command-line tool designed for automation outside the Postman app.
Why it matters:Misunderstanding Newman limits automation possibilities in CI/CD pipelines.
Expert Zone
1
Tests can modify environment and global variables mid-run, enabling complex workflows and conditional logic.
2
Collection Runner supports delay between requests to simulate real user pacing or avoid rate limits.
3
Newman supports reporters and integrations that produce detailed test reports for professional analysis.
When NOT to use
Running collections is not ideal for testing highly asynchronous or event-driven APIs where requests depend on external triggers. In such cases, specialized tools or custom scripts that handle event listening and callbacks are better.
Production Patterns
Teams use collections to automate regression tests that run on every code commit via Newman in CI/CD. They also use data files for broad input coverage and environment variables to switch between staging and production servers seamlessly.
Connections
Continuous Integration (CI)
Builds-on
Understanding collection runs helps grasp how automated API tests fit into CI pipelines to ensure code quality.
Test Automation Frameworks
Same pattern
Running collections is a form of test automation, similar to how frameworks run suites of unit or UI tests.
Assembly Line in Manufacturing
Analogy in process flow
Like an assembly line processes parts step-by-step, running a collection processes API requests sequentially to build confidence in the product.
Common Pitfalls
#1Running a collection without selecting the correct environment.
Wrong approach:Run collection with default environment but requests use variables like {{baseUrl}} that are undefined.
Correct approach:Select the proper environment with all variables defined before running the collection.
Root cause:Not understanding that environment variables must be set for requests to resolve URLs and data correctly.
#2Ignoring test failures during collection runs.
Wrong approach:Run collection and assume all requests passed without checking test results panel.
Correct approach:Review test results after run and investigate any failed assertions or errors.
Root cause:Assuming a successful HTTP response means the test passed, ignoring test scripts.
#3Using hardcoded values inside requests instead of variables.
Wrong approach:Set request URL as https://api.example.com/user/123 instead of https://{{baseUrl}}/user/{{userId}}.
Correct approach:Use variables for parts that change to enable flexible runs across environments and data sets.
Root cause:Not realizing variables make collections reusable and easier to maintain.
Key Takeaways
Running a collection automates sending multiple API requests in order, saving time and reducing errors.
Environment variables and data files make collection runs flexible and reusable across different scenarios.
Tests attached to requests provide automatic checks that improve confidence in API behavior.
Newman allows running collections outside Postman, enabling integration with automated pipelines.
Understanding how collection runs work under the hood helps design better tests and troubleshoot failures.