Using a data file with Newman lets you run the same API tests many times with different inputs. This helps check if your API works well with various data.
0
0
Data file with Newman in Postman
Introduction
You want to test an API with many user details like names and emails.
You need to check how your API handles different product IDs.
You want to run the same test steps but with different login credentials.
You want to automate testing for multiple scenarios without writing many tests.
You want to save time by running many tests in one go using a data file.
Syntax
Postman
newman run <collection-file.json> -d <data-file.json|csv>
The -d option tells Newman to use a data file for multiple test runs.
The data file can be JSON or CSV format with different sets of data.
Examples
Runs the collection using data from a JSON file named
users.json.Postman
newman run mycollection.json -d users.json
Runs the collection using data from a CSV file named
data.csv.Postman
newman run mycollection.json -d data.csv
Sample Program
This command runs the Postman collection sample_collection.json using the data in sample_data.json. Each row in the data file runs the tests once with that data.
Postman
newman run sample_collection.json -d sample_data.json
OutputSuccess
Important Notes
Make sure your data file keys match the variable names used in your Postman requests.
Use JSON for complex data and CSV for simple tabular data.
Newman runs one iteration per row in the data file.
Summary
Data files let you run the same tests with different inputs easily.
Newman supports JSON and CSV data files for this purpose.
Use the -d option with Newman to specify your data file.