Postman Tutorial Part 48 – All Types of Variables in Postman

We have already learnt about all types of variables in Postman in Postman Series on my blog. This post will bring all concepts of variables together so that you can learn or revise your concepts at one place.

A variable is a named memory space which is used to store and manipulate values. You can read more about variables here.

There are five types (Infact six) of variables available in Postman:-

  1. Environment Variable
  2. Global Variable
  3. Collection Variable
  4. Data Variable
  5. Local or Logging or Temporary or Debugging variable

There is one more variable called “Dynamic Variable” which is predefined. I kept it separately from above categorization as it is related to generate random data or value for other variable. For example :- Getting current timestamp as value for a field. You can not change it every time before running. So dynamic variable makes your life easier. You just need to use predefined variable {{$timestamp}} . It will always use current timestamp as a value. You can read more about Dynamic variables here.

Environment Variable:-

As the name says “Environment” , you can configure variables as per different environments like testing, development , UAT or etc environment to use in API. Just select the environment you want and variables value will be used based on selected environment. Read more about environment variables here.

Global Variables:-

“Global” terms defines its purpose. A variable which is defined outside of any environment is called a global variable. The scope of global variable is within workspace. It is available for each environment in workspace. In fact global variable is independent of environment variables. You can access global variables irrespective of selection of any or no environment. Read more about global variable here.

Collection Variables:-

Collection variables are exclusive to single collection which is created within Collection. This is useful to store constants. I am using word “Constant” here as you can not set or update it through scripts. Read more about it here.

Data Variables:-

Postman allows you to read data from csv and JSON in request and scripts. Apart from this the major usage of data variable is to achieve data driven testing of an API which means running a script for multiple set of data. Like collection variable you can not update or create data variables through script. You can learn about reading data from csv in Postman here and reading data from a JSON file here. You can also read about Achieving data driven testing using csv in Postman here and Achieving data driven testing using csv in Postman here.

Local or Logging or Temporary or Debugging variable:-

Local variables are something which remains in memory or scope till the execution is happening. We can create local variables only using scripts in Postman. We can use JavaScript way to create a variable (Using var or let) or pm api ( pm.variables.set(<varname>,<varvalue>). We can access local variable directly using reference if created using JavaScript way. If local variable is created using pm api reference, we can access them by using pm API reference as pm.variables.get(<varname>). Read more about Local variables here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

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.

1 thought on “Postman Tutorial Part 48 – All Types of Variables in Postman

Leave a Reply

Your email address will not be published. Required fields are marked *