Use of data files (CSV, JSON) in Postman for data-driven testing
Last Updated :
19 Mar, 2024
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).
Step 2 : Create a data file (csv or json). Each row in the file represents the set of input values.
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);
});
Step 4 : Click on “Run Collection” option and a runner tab will get open.
Step 5 : Choose the requests we want to execute. Click on “select file” to upload data file. We can also update the configuration.
Step 6 : We can also preview our uploaded data file. Click on preview button.
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.
Output:
Share your thoughts in the comments
Please Login to comment...