The Wayback Machine - https://web.archive.org/web/20240624090348/https://www.geeksforgeeks.org/use-of-data-files-csv-json-in-postman-for-data-driven-testing/
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


Similar Reads

How to link data files to requests in Postman for iterative testing?
Postman may be beneficial when trying out APIs that require file uploads or while sending complicated JSON payloads. In this article, you will explore the way to upload documents in Postman and alternative approaches to make it well. Let's dive in. In the area of API testing and development, managing file uploads is a fundamental duty. Postman, a u
2 min read
How to Write Postman Test to Compare the Response JSON against another JSON?
In the era of API-driven development, testing the API responses to ensure their correctness is of paramount importance. One such test includes comparing the JSON response of an API against a predefined JSON. In this article, we will delve into how to write a Postman test for this purpose. Table of Content What is Postman?JSON and its Role in APIsWh
4 min read
How to use variables and data files together in Postman ?
In this article, we are going to learn the process of using variables and data files together in the Postman. Postman is a powerful tool for API testing, offering extensive capabilities for automating tests and handling various API request types. One of its key features is the ability to use variables and data files together, which greatly enhances
6 min read
How to use cURL to Get JSON Data and Decode JSON Data in PHP ?
In this article, we are going to see how to use cURL to Get JSON data and Decode JSON data in PHP. cURL: It stands for Client URL.It is a command line tool for sending and getting files using URL syntax.cURL allows communicating with other servers using HTTP, FTP, Telnet, and more. Approach: We are going to fetch JSON data from one of free website,
2 min read
Difference between package.json and package-lock.json files
In this article, we will learn the major differences between package.json and package.lock.json and their needs in Node. In Node, package.json is a versioning file used to install multiple packages in your project. As you initialize your node application, you will see three files installed in your app that is node_modules, package.json, and package
3 min read
How to use postman for testing express application
Testing an Express app is very important to ensure its capability and reliability in different use cases. There are many options available like Thunder client, PAW, etc but we will use Postman here for the testing of the Express application. It provides a great user interface and numerous tools which makes API testing very easy. Postman is an API(u
3 min read
Create and use mock servers for API testing or development in Postman
Postman, a comprehensive API platform, includes a robust API client for exploring, testing and defining requests. Its notable feature is the ability to create mock servers, simulating API responses for testing and development purposes. Developers can organize requests in collections, generate mock servers, and customize settings to mimic desired AP
4 min read
How to Upload File and JSON Data in Postman?
Postman is a very famous API development tool used to test APIs. Postman simplifies the process of the API lifecycle to create and test better APIs. Now, while we are working with APIs sometimes we need to send JSON as data or upload a file through API. There may be a scenario where we have to do both tasks in a single API. Prerequisites:Express Js
4 min read
Convert JSON file into CSV file and displaying the data using Node.js
There are so many ways to store data for better understanding for individual purposes, in few cases, JSON files will be more suitable in few cases, CSV files, and there are also lots of other types as well like XML, etc. In this article, we will convert the JSON file data into CSV file data and also display that through Node.js. JSON stands for Jav
3 min read
How to Count Records in JSON array using JavaScript and Postman ?
In this article, we are going to explore how JavaScript and Postman are used to count the number of records returned in a JSON array. Send a Request: Send a request to fetch the JSON array from your API endpoint in Postman.Access JSON Response: In the Postman test scripts tab, you can access the JSON response body using the pm.response.json() metho
2 min read
three90RightbarBannerImg