We have already seen what are Global and Environment variables in Postman and its usage in creating parameterized requests. In this post, we will see another type of variables called Collection variables.

Let’s consider some scenarios first:-

  1. If you have followed my posts in sequence, you must have seen that when we import a Collection , it does not include environment and global variables. We explicitly need to download variables file as JSON and share.
  2. If you have multiple collections in workspace, you may confuse with required environment variable file to select.
  3. You may expose critical data which belongs to other collections to wrong recipient while sharing variable files.
  4. You have some data which is not unique to particular environment or say constant value.

All above problems can be solved to a great extent if we use Collection variables. A collection variable only belong to single collection for which it has been created. So when you share a collection, all required variables will also be exported with collection.

You can add variables in Variables tab while creating collection or edit collection to add variables. To edit a collection, Click ellipsis (…) next to the collection name, and select “Edit” to open the EDIT COLLECTION modal.

This variables can be used in same manner as we use normal environment and global variables.

I have added a variable named “BookingID” as collection variable.

I am using above created variable in script as :-

You can see variable usage is same as we do environment and global variables. Scope is changed to Collection.

When you share this collection to anyone, they will get all collection variables as well. This feature helps you to keep variables segregated as per collection.

You can import above example collection from below link:-

https://www.getpostman.com/collections/64c6a38fe95a577ce033

But Collection variable has some major demerits which restricts you to use this variable specifically. Demerits are:-

  1. Collection variables are read only. You can not set its value through scripts.
  2. We can not create Collection variable through scripts.
  3. We can not update value of Collection variable as it is ready only.

#ThanksForReading

Have you tested your Selenium knowledge ? Try below Selenium Quiz:-

Learn Selenium with Quiz

Be master in Selenium-WebDriver

API Testing – Basics

API Testing – Postman

API Testing – Rest Assured

Learn Protractor Step by Step

Frequently Asked Java Programs in Interview

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