Data file integration helps you run the same test many times with different data. It saves time and finds more problems.
Data file integration (CSV, JSON) in Postman
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Postman
1. Prepare a CSV or JSON file with test data. 2. In Postman, go to the Collection Runner. 3. Select your collection and choose the data file. 4. Run the collection; Postman uses each row or object as input.
CSV files have rows and columns, like a table.
JSON files have objects and arrays, good for complex data.
Examples
Postman
CSV file example: username,password user1,pass1 user2,pass2
Postman
JSON file example:
[
{"username": "user1", "password": "pass1"},
{"username": "user2", "password": "pass2"}
]Sample Program
This test script runs for each row/object in the data file. It checks username is not empty and password is longer than 3 characters.
Postman
// Postman test script example using data file pm.test("Check username is not empty", () => { pm.expect(pm.iterationData.get("username")).to.not.be.empty; }); pm.test("Check password length", () => { pm.expect(pm.iterationData.get("password").length).to.be.above(3); });
Important Notes
Make sure your data file columns or keys match the variable names in your tests.
Use Collection Runner in Postman to load and run data files easily.
Data-driven tests help find bugs that happen only with certain inputs.
Summary
Data file integration lets you run tests many times with different data.
Use CSV for simple tables and JSON for complex data structures.
Postman's Collection Runner uses data files to automate repeated tests.
Practice
1. What is the main purpose of using data files like CSV or JSON in Postman's Collection Runner?
easy
Solution
Step 1: Understand data file role in Postman
Data files provide different sets of input data for tests.Step 2: Connect data files to Collection Runner
Collection Runner uses these files to repeat tests with varied inputs.Final Answer:
To run the same test multiple times with different input data -> Option AQuick Check:
Data files = multiple test runs [OK]
Hint: Data files feed tests with many inputs [OK]
Common Mistakes:
- Thinking data files create APIs
- Confusing data files with UI settings
- Assuming data files store results
2. Which of the following is the correct way to reference a CSV data file variable named
username in a Postman test script?easy
Solution
Step 1: Identify how Postman accesses data file variables
Postman usespm.iterationData.get('variableName')to get data from CSV or JSON files.Step 2: Match the correct syntax for
The correct method isusernamepm.iterationData.get('username').Final Answer:
pm.iterationData.get('username') -> Option CQuick Check:
Use pm.iterationData.get() for data file variables [OK]
Hint: Use pm.iterationData.get('var') for CSV/JSON data [OK]
Common Mistakes:
- Using pm.variables.get() which accesses environment variables
- Trying to access data as object properties
- Confusing request body with data file variables
3. Given this CSV data file content:
And this test script snippet:
What will be the result of running the Collection Runner with this data file?
email,password user1@example.com,pass123 user2@example.com,pass456
And this test script snippet:
const email = pm.iterationData.get('email');
const password = pm.iterationData.get('password');
pm.test('Check email format', () => {
pm.expect(email).to.include('@');
});What will be the result of running the Collection Runner with this data file?
medium
Solution
Step 1: Analyze CSV data values
Both emails contain '@' symbol: 'user1@example.com' and 'user2@example.com'.Step 2: Check test condition for each iteration
The test checks if email includes '@', which is true for both rows.Final Answer:
Both iterations pass the test -> Option AQuick Check:
Email includes '@' = true for all data [OK]
Hint: Check data values against test condition carefully [OK]
Common Mistakes:
- Assuming test fails without checking data
- Confusing syntax error with logic error
- Ignoring multiple iterations in Collection Runner
4. You have a JSON data file with this content:
When running tests that expect
[
{"user": "alice", "age": 30},
{"user": "bob", "age": "twenty-five"}
]When running tests that expect
age to be a number, you get unexpected failures. What is the most likely cause?medium
Solution
Step 1: Inspect JSON data values
The first age is 30 (number), second is "twenty-five" (string).Step 2: Understand test expectation
Tests expect age to be a number, but second value is text, causing failure.Final Answer:
The second age value is a string, not a number -> Option BQuick Check:
Data type mismatch causes test failure [OK]
Hint: Check data types in JSON carefully [OK]
Common Mistakes:
- Assuming JSON format is invalid
- Blaming Postman for reading JSON
- Ignoring data type differences
5. You want to run a Postman test that uses a JSON data file with nested objects like:
Which is the correct way to access the
[
{"user": {"name": "John", "id": 101}, "active": true},
{"user": {"name": "Jane", "id": 102}, "active": false}
]Which is the correct way to access the
name property inside the test script?hard
Solution
Step 1: Understand how Postman accesses nested JSON data
Postman requires getting the parent object first withpm.iterationData.get('user'), then access nested properties using JavaScript dot notation.Step 2: Identify correct syntax for nested property
Usingpm.iterationData.get('user').namecorrectly accesses the nestedname.Final Answer:
pm.iterationData.get('user').name -> Option DQuick Check:
Get parent object first, then .name [OK]
Hint: Get parent object first, then .name [OK]
Common Mistakes:
- Trying to access nested objects as JS objects directly
- Using .get() on returned object
- Using bracket notation inside pm.iterationData.get()
