Variables:
Same like other programming languages and tools , variables are elements that stores values or information for re-usability and preventing repetitive work.
How to call variables in Postman:
The syntax to call variable is to call variable name using double curly bracket {{<variable_name>}}
For instance let the variable name be ‘Page_no‘ so to call this variable we use
https://www.facebook.com/somepage/{{Page_no }}

Note: we can call variables in request, request header or body.
Variable scope:

The variable scope in postman is as given below:
- Global
- Collection
- Environment
- Data
- Local
Note: This image representation may look confusing because environmental variables have more scope than collection, because an environmental variable will be available across all the collections but a collection variable will be available only for the specific collection.
So this list and hierarchy image is arranged more on precedence level than scope, with precedence increasing from top to bottom.
For instance if Collection variable and Environment variable has the same ‘name’ then ‘value’ of Environment variable will be considered.
Global:
Global variables are available across all the collections ( But not across all work-spaces, workspaces are considered as isolated from eachother so variables are not shared among workspaces )
To add global variables click the enviroment management icon :

Click Globals button at bottom of the window
provide the global variable name and value.

Note: Initial value is the value shared with all the members in the workspace. If you want to try with different values without affecting all members in the workspace then edit current value, this will ensure that tests are run with the value you provided in the current value field but only on your local system.
You can synchronize this changes using persist or reset, persist sets initial value to the current value that you set and will reflect across the workspace, reset will make current value same as initial.
Collection:
Collections, as discussed before is a logical way of grouping requests.
To create collection variable , click the meatball menu and select edit and navigate to variables.
Now add the variable and the value

This variable and value will be available only for the requests/folders within the specific collection.
Environment:
Environment is a way of logically grouping variables. For instance, imagine you want to use the same set of tests in two different environments say ‘Production’ and ‘Testing’ .
The variables ‘url’, ‘username’ and ‘password’, will have different values depending upon where we are running these tests.
So we can create two environments , ‘Production‘ and ‘Test‘ and add these variables and their corresponding values.
To create ‘environment’ click ‘manage environment’ icon and click the add button on the window.


And give environment name and add the variables

Now select the variable from drop down.

Select the variable from the drop down list as shown and click the eye icon to see the variable details of the specific environment.

Now when we call these variables in our request we get these values.If we change the environment, then the value changes accordingly.
Data:
Postman allows to store and use variables as key value pairs from CSV or JSON file. This helps in data driven testing.
Data variables are available only through Collection runner. To open collection runner , click the collection you want to run , click play icon and click run.
Select the csv file or json file , the iteration will be automatically set to number values in the file
https://learning.getpostman.com/docs/postman/collection_runs/working_with_data_files/#working-with-the-sample-files , this links helps you to know how to create a data file
Clicking the preview will show whether the file was parsed correctly into key and value.

So page is the key and {1,2,3,4} are the values.

One running the test, it will get executed 4 times . That is with value 1,2,3, and 4.

Local:
Local variable are specific to the request, it will be set through prerequisite- scripts ( which runs before executing requests) or tests ( which run after the response is received)
pm.variables.set('myVariable', MY_VALUE);
They are accessible only with in the request.
Running Data driven test from cmd:
Get the collection link and pass the data file using -d command line argument
newman run https://www.getpostman.com/collections/xxxxx -d t.csv
output will be

Note: Tests are written in the test tab of requests, and as we have not mentioned any validation test scripts, the test failed and pass number will be zero. We will see in next session how to write tests.