Introduction
In this tutorial, we’ll explore the Collection Runner feature, which enables you to run collections using custom data for each iteration.Steps to Get Started
- Open the Bruno app.
- Create a collection called
runner-example - Create a POST request and name it
runner-request - Use the URL:
https://reqres.in/api/users - Select the JSON format for the request body and add the following data:
Using the Collection Runner
We will create a sample data filecsv-example.csv that includes input fields such as name and job to be used in data-driven testing. You need to create a CSV or JSON file according to the specific requirements of the API you’re working with.
Since the API in this case expects two data inputs name and job the file should contain these fields. Here’s an example of how to structure your data:
1. CSV Format Example
A sample CSV file might look like this:copy
2. JSON Format Example
A sample JSON file might look like this:copy
Using the Bruno App
- Click on the runner icon in the right-hand navbar.
- Check the Run with Parameters option.
- Select the file type: CSV or JSON.
- Click Run Collection.
How to Use Variables from CSV/JSON Files
When you upload a CSV or JSON file, the variables within the file can be accessed using the{{var}} syntax.
You can access these variables dynamically in your requests and use them within Bruno.
Accessing Variables in Request Body
request-body
{{name}} and {{email}} will be replaced by the actual values from the uploaded JSON file.
request-body
Accessing Variables in Scripts
You can also access these variables directly in your pre-request or post-response scripts usingbru.getVar().
Using the Bruno CLI
- Navigate to the root directory of your Bruno collection.
- Run the following command:
copy
results.html file in your Bruno collection’s root directory. You can view this file in your browser.
Command Overview
--reporter-html results.html: Generates a human-readable HTML report.--csv-file-path /path/to/csv/file.csv: Specifies the path to the CSV file you want to use.
Runner Iteration Utilities
Bruno provides various utility functions to access and manipulate data from attached data files (CSV/JSON) during collection runs.Accessing Iteration Data
Check if a variable exists
Get a specific value
Get all iteration data
Convert to JSON string
Remove a variable
Iteration Information
Get current iteration index
Get total iterations
Example Usage
Basic Data Access
Conditional Logic Based on Iteration
Data File Examples
CSV Format
JSON Format
Notes
- Variables removed with
unset()only affect the current iteration - Each iteration runs with fresh data from the file
- Supports both CSV and JSON data files
- Data is automatically loaded from the attached file at the start of each iteration