SetVar
Overview
The SetVar function is used to define and set variables within a scenario. Variables can be classified as either global or local, each serving distinct purposes within the execution of scenarios.
- variable_name: The name of the variable to be set.
- value: The value to assign to the variable.
- global (optional): A boolean flag indicating whether the variable should be global. Defaults to False.
Parameters
- variable_name: (Type: string) The unique identifier for the variable.
- value: (Type: any) The value to assign to the variable.
- global: (Type: boolean, Optional) Specifies whether the variable is global or local. Defaults to False.
Usage
Example 1: Setting a Local Variable
This sets a local variable named "local_variable" with a value of 42. Local variables are only accessible within the current scenario.
Example 2: Setting a Global Variable
This sets a global variable named "global_variable" with the value "hello". Global variables can be accessed from the parent scenario.
Retrieving Variable Values
To retrieve the value of a variable, use the GetVar function:
variable_name: The name of the variable whose value you want to retrieve.
Note
If global is set to true, the variable will be considered global. Omitting the global parameter or setting it to false makes the variable local.
Conclusion
The SetVar function provides a flexible way to manage variables within scenarios, allowing you to control their scope and access them as needed.