We have already learnt to create parameterized request body by reading data from a CSV and JSON file. If you have not gone through them yet, you must go now.

Creating parameterized request by reading data from a CSV

Creating parameterized request by reading data from a JSON

Achieving Data driven testing using CSV in Postman

Achieving Data driven testing using JSON in Postman

We can store and use data from csv and json for validation or expected results as well. For this we must be able to read those data (variables) in scripts. We will going to learn the same in this post.

Postman Sandbox provides an API reference named “pm“. “pm.iterationData” API can be used to play around data variables. This iterationData object contains data from the data file provided during a collection run.

You must be thinking that there will be multiple rows in csv or JSON Objects in JSON, so which row data it will return? It is a valid question. We know that mostly CSV or JSON data files are used to achieve data driven testing of API in Postman. Each row is considered as an iteration. So iterationData Object always contains data from currently executing iteration row.

To get value of a data variable, we need to use get() method as below:-

pm.iterationData.get(variableName)

Example:-

Let’s add below codes in to Pre-request Script and Tests for API used in Creating parameterized request by reading data from a CSV . You can use example of JSON as well.

Let’s run above API using data file with one row and multiple rows :-

For data file with single row:-

For data file with multiple rows:-

Please note all above concepts are same for both CSV and JSON data files.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply