Postman Tutorial Part 12 – Understand Environment & Variables in Postman

Let’s start with Variables first:-

A variable is a container which holds information that could be changed. If you have basic programming knowledge, you must have used variables in your programs.

Suppose you are developing a banking application. There are some values which will be used throughout the application or some values unique to a functionality. If you hardcode those values everywhere, just imagine if you need to change value. So we should use variables here. Define it as per need i.e. locally or globally and use its referenced name rather than actual value. If you are required to update value of a variable, just update the value where you have declared. Everywhere updated value will be used.

The same way variables works in Postman. We have many usage of variables in Postman. Below are some usages:

  1. In my previous posts, you would have seen that we are hardcoded domain name in each URI.

https://gorest.co.in/public-api/users/
https://gorest.co.in/public-api/users/123/

This domain name may change or can be different for each environment like QA, Dev , Staging etc. Here variables make our job easier. We can store domain name as per environment in a variable and can call that variable here.

2. We can use variables at several places to make it parameterized such as
URI, URI parameters, headers, authorization, request body, and header presets.

3. Variables can be used to chain request. Extracting data from response , storing and using it for another request as input are possible by using variables.

4. Variables can also be used in pre and post scripts. We can log variables as well.

Now Understand Environment:

Let me try to relate it an example. We create configuration files for different environment. It helps us to call required configuration file whenever needed. If we use .properties file, it stores values as key value pairs. Just call the key, it will give you required value. Similar type of things could be achieved in Postman using Environment.

An Environment in Postman is a set of key-value pairs. The key represents the name of the variable and value is information that key holds.

We can create, share, duplicate, export, and delete an environment. You can download it as json and pass it to run collection through newman.

Variables defined in an Environment are Local variables. It means you can use variables of an environment in another environment. So we have another type of variables called Global variables.

Global variables are also a set of key value pair which does not belong to specific environment. It is available in all scopes. You can not select multiple environments at the same time. In that case Global variables save you.

We will see Environments and Global variables in details in upcoming posts. Stay tuned.

More about API Testing in upcoming posts. Stay tuned.

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

Leave a Reply

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