Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
introduce
Postman supports variable reference, facilitating centralized maintenance and management.
Like many request http://127.0.0.1:8080/xxx/xxx using local 127.0.0.1:8080 environment, when want to go to the environmental test on the cable interface, have to be a a host of changes, when has dozens of hundreds of requests will be very painful.
At this point, you can use variables to maintain the value of host, just maintain the value of the variable inside the variable, and reference it everywhere, just like the magic value inside the code
Variable scope
Postman supports the following variable scope ranges:
- Global: Global variable
- Collection: Collection variable
- Environment: Indicates the Environment variable
- Data: Data variable
- Local: Local variable
For example, if there is a global variable and an environment variable named username, the environment variable will be used when the request is made.
In the following example, the Demo env environment overrides the username in the global variable
The global variable
A variable that is available to all collections and all requests
Set the variable
Applies to only the current collection available
The environment variable
Environment variables are similar to global variables, but you can select the current environment, suitable for environment differentiation
You can add an environment when No environment is available
After adding, you can choose different environments to execute requests, such as local and development environments
other
A local variable
These are local variables in pre-request Script and Tests
The data variable
Variables in Runner to provide automated test case data
reference
Using variables | Postman Learning Center
The Postman version is 9.1.x