Variables in Postman
Environment in PostmanA collection of key-value pairs is called an environment. Each name of the variable represents its keys. And referencing the name of the variable allows you to access its value. It is a set of variables that differentiate among the requests. Such as, we can have an environment for testing, one for development and another for production. We can change the value of the variables to pass the data between requests and tests. Creating an EnvironmentTo create an environment, follow the following steps:
Now select Add. Enter the name of the Environment and click on Add. We can also download, share, delete, duplicate, or import the environment. Sharing an environment will help you to run your requests against the same set of data. Environment Variable in PostmanThe postman variable is similar to the programming language variable. As we know, a variable is an entity, which stores value. You can change the value of the variable. In Postman, a variable is a set of key-value pairs. Here the key is the variable and value is the value of the variable. Creating an Environment Variable in PostmanTo create an environment variable follow the following steps:
Then select the Update button and close the Manage Environment window. Now you have an environment variable with the name 'url', and the value of the variable is the http://restapi.demoqa.com. Using an Environment Variable in Postman
So, the environment is created with a variable named "url". This means we can now use the variable instead of the actual URL. Global Variables in PostmanHere we will see how to create global variables. Unlike the environment variable, in the case of global variables, we don't need to create an environment first. Creating a Global Variable in Postman
Using a Global Variable in PostmanSelect the No Environment from the drop-down of Postman, from the top right corner of Postman.
Variable ScopesVariable scope is the boundary within which these variables can be accessed and executed. The following variable scopes are supported by Postman, which is used for different tasks. The narrowest variable scope is Local, and then next is Data, Environment, Collection, and the broadest one is Global. In case, the variable name is the same, in two scopes with a different value, then the value of the narrowest variable scope will be used while running the request. Let's say the name of both local and global variables is My Variable. Then Postman will use a local variable value to run the request, as a local variable is the narrowest variable scope. Let's see these variable scopes one by one:
Next TopicDynamic Variables
|