-
Variables Scopes
-
Global Variables
- It is used to access data between collections, requests, scripts, and environments
-
Collection Variables
- It is available throughout the requests in a collection and are independent of environments
-
Environment Variables
- It is used to scope your work to different environments
-
Data Variables
- It comes from external CSV and JSON files to define data sets you can use when running collections
-
Local Variables
- It is temporary variables that are accessed in your request scripts
-
Priority
- 05-Global Variables
- 04-Collection Variables
- 03-Environment Variables
- 02-Data Variables
- 01-Local Variables
-
Get the variable
-
use method ".get"
- Example =>
pm.globals.set("variable_key", "variable_value");
pm.environment.set("variable_key", "variable_value");
pm.collectionVariables.set("variable_key", "variable_value");
-
variable scope
- Global => pm.globals.get()
- Collection=> pm.collectionVariables.get()
- Environment => pm.environment.get()
- Local => pm.variables.get()
-
Set the variable
-
use method ".set"
- Example =>
pm.environment.get("variable_key");
pm.globals.get("variable_key");
pm.variables.get("variable_key");
pm.collectionVariables.get("variable_key");
-
variable scope
- Global => pm.globals.set()
- Collection=> pm.collectionVariables.set()
- Environment => pm.environment.set()
- Local => pm.variables.set()
-
delete the variable
-
use method ".unset"
- Example =>
pm.environment.unset("variable_key");
pm.globals.unset("variable_key");
pm.collectionVariables.unset("variable_key");
-
variable scope
- Global => pm.globals.unset()
- Collection=> pm.collectionVariables.unset()
- Environment => pm.environment.unset()
- Local => pm.variables.unset()