Open In App

Use of data files (CSV, JSON) in Postman for data-driven testing

Last Updated : 19 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

It is a software testing method having all test input data stored or documented in a single CSV/JSON file and using a single test script for testing the API request with various input scenarios. It separates the test script logic from the test data. In Postman, we can perform this using variables and data files (CSV or JSON).

Key Features of Data-Driven Testing:

  • Efficient: It saves our time as we do not have to manually add data for different cases.
  • Reusable: We can use our single test script for multiple input test cases.
  • Maintainability: We can update the test scripts/ test data whenever without their dependency on each other.

Steps to Implement data files(CSV, JSON) in Postman:

Step 1: Open any request from a collection and add variables. Here, I have added two variables – username and password in the body enclosed in double curly braces whose value will be fetched from files (CSV or JSON).

Screenshot-2024-03-11-154753

Step 2 : Create a data file (csv or json). Each row in the file represents the set of input values.

Screenshot-2024-03-11-161107

csv file

Step 3 : Under tests tab , choose scripts that we want to add like “Status code: Code is 200“. Script will be added and then save the request.

pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

Screenshot-2024-03-11-154846

Step 4 : Click on “Run Collection” option and a runner tab will get open.

Screenshot-2024-03-11-155141

Step 5 : Choose the requests we want to execute. Click on “select file” to upload data file. We can also update the configuration.

Screenshot-2024-03-11-155417-(1)

Step 6 : We can also preview our uploaded data file. Click on preview button.

Screenshot-2024-03-11-155431

Step 7 : Run the collection by clicking on “Run Collection Name” and we will get the summary of different test cases as per the data in data files.

Screenshot-2024-03-11-155552

Output:
lv_0_20240311180836


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads