Skip to content

How To Use Collection Runner In Postman

API Testing Blog

Understanding the Postman Collection Runner

The Postman Collection Runner is a powerful tool for automating your API testing workflows. It allows you to execute a series of API requests defined within a Postman Collection, enhancing efficiency and providing valuable insights into your API’s performance and functionality.

Setting Up Your Postman Collection

Before running your collection, you need to create and populate it with requests.

  1. Create a New Collection: In Postman, navigate to the “Collections” tab and click on “Create Collection.” Give your collection a relevant name.
  2. Add Requests: Within your collection, add individual API requests. For each request, define:
    • Request method: GET, POST, PUT, DELETE, etc.
    • URL: The endpoint you want to target.
    • Headers: Any required headers for the request.
    • Body: The data you want to send in the request, if any.
  3. Add Variables: Use variables to make your collection reusable and flexible. You can define variables at the collection, folder, or request level. These variables can hold values like base URLs, API keys, or specific data points.
  4. Script Automation: Enhance your collection with Postman scripts for greater automation. You can use scripts to:
    • Manipulate data between requests.
    • Handle complex logic.
    • Set up dynamic environment variables.

Executing Your Collection in Postman Runner

With your collection ready, it’s time to leverage the runner:

  1. Access Collection Runner: Click on the “Runner” tab within Postman.
  2. Select Collection: Choose the collection you want to run from the dropdown list.
  3. Environment Selection: Select the appropriate environment containing your API credentials and other essential variables.
  4. Iteration and Data:
    • Iterations: Define how many times you want to run the collection. This is useful for testing with different data sets.
    • Data Files: Upload CSV or JSON data files to provide input for your collection’s requests. This allows you to run your tests with multiple sets of data.
  5. Run Collection: Click on the “Run” button. Postman will execute the requests in your collection, one by one, following the order you’ve established.

Analyzing Results and Debugging

Once the execution completes, Postman presents the results in a clear and detailed format:

  1. Results Summary: An overview of the run, including the number of requests, successes, failures, and errors.
  2. Individual Request Details: Each request in the collection is displayed, with information about:
    • Request details (method, URL, headers, body)
    • Response details (status code, headers, body)
    • Any errors encountered during the request.
  3. Detailed Logs: The Runner provides thorough logs, enabling you to troubleshoot issues and identify the root cause of failures.

Example: Testing an API with Collection Runner

Let’s create a simple collection to test a basic API:

1. Collection Setup:

  • Collection name: “Weather API”
  • Request 1:
    • Method: GET
    • URL: https://api.openweathermap.org/data/2.5/weather?q=London&appid={{api_key}}
    • Headers: None
    • Body: None
    • Variable: api_key (set in your environment)

2. Environment Setup:

  • Environment name: “Weather API Env”
  • Variable: api_key (add your actual API key here)

3. Running the Collection:

  • Select Collection: “Weather API”
  • Select Environment: “Weather API Env”
  • Iterations: 1 (Run once)
  • Data Files: None
  • Click “Run”

4. Analyzing Results:

  • Review the response status code (should be 200 for success)
  • Inspect the response body for the expected weather information.

5. Script Example:

You could add a script to your request to extract the temperature from the response and store it in another variable for later use:

// Example script to extract the temperature from the response
pm.test("Check temperature", function() {
const jsonData = pm.response.json();
const temperature = jsonData.main.temp;
pm.environment.set("temperature", temperature);
});

This script uses Postman’s pm object to access the response data and store the temperature in an environment variable.

Exploring Advanced Collection Runner Features

Postman provides numerous powerful features for managing and executing your collections:

  • Multiple Environments: Allow you to test your API against different environments (development, staging, production).
  • Data Driven Testing: Use data files to test your API with various inputs and scenarios.
  • Pre-request and Test Scripts: Add more complex logic to your collection by using these scripts.
  • Postman Monitors: Schedule regular runs of your collection to monitor API health and performance.
  • Reporting Capabilities: Generate detailed reports and dashboards for better insights into your API’s status.

Conclusion

Mastering the Postman Collection Runner unlocks a world of possibilities for automating and streamlining your API testing process. From simple to complex scenarios, the runner empowers you to thoroughly test, analyze, and improve the quality of your APIs. Leveraging the features and customization options discussed in this guide, you can establish a comprehensive and efficient testing workflow that enhances the reliability and performance of your APIs.

API Testing Blog