0
0
Postmantesting~5 mins

Data file integration (CSV, JSON) in Postman

Choose your learning style9 modes available
Introduction

Data file integration helps you run the same test many times with different data. It saves time and finds more problems.

Testing login with many usernames and passwords.
Checking an API with different input values.
Running a test that needs many sets of data like user details.
Validating form submissions with various inputs.
Automating repetitive tests with changing data.
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
This CSV has two sets of username and password for testing login.
Postman
CSV file example:
username,password
user1,pass1
user2,pass2
This JSON array has two objects with username and password for tests.
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);
});
OutputSuccess
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.