The variables building blocks are used to Get and Set variable values for later use. Variables can be temporary or be persisted forever.
Get Variable: A Get variable building block is used to get the value of a variable and pass it on to other building blocks. Variables can be scoped to be available only in the same run of a case, across all cases in a run, and even permanently for as long as the Project, it is stored in exists.
Set Variable: A Set variable building block is used to set the value of a variable. Variables can be scoped to be available only in the same run of a case, across all cases in a run, and even permanently for as long as the Project, it is stored in exists.
Set the scope in which to load this variable.
- “Only this case” means that the variable only exists during the execution of this one case, i.e. scope of the variable is only fixed in that particular flow where it is been used. This is the by default value for both variable blocks.
- “Schedule” means the variable will exist across all cases defined in a schedule during the same run. It is beneficial when the user wants to pass the value at schedule run time under the variable category. The finest example of this scope will be doing cross-browser testing using Leapwork.
- “Permanent” means the variable will continue to exist permanently. These variables will hold the value event after the flow is completed and also across the multiple flows. i.e. once the variable with the permanent scope is set with a value, then that variable can be used across all the flows with permanent scope.
Let's go thru some examples of variable blocks usage:
Example 1: A simple way to use Get and Set the variable block
For more details please visit the Use Numbers and Variables lesson on how to use variables.
Note: Variable name is case sensitive so please use the correct case while accessing it.
Example 2: Using Schedule Variables
Users can define variables in the schedule and run schedule base on that
And it's also possible to get or set schedule variables in the flow, by changing their scope to schedule:
To get more information on schedule variables and their usage please go through the following article Cross-Browser Testing
Example 3: Accessing variable using Variable Endpoints in REST API
Users can also use Leapwork REST API endpoints, to manipulate the variables. There are 3 variable endpoints in Leapwork which can be used dynamically:
- Get All Variables: This endpoint returns a list of all permanent variables and their corresponding values.
- Edit Variable by Name: This endpoint is used to update the value of a permanent variable.
- Get Variable By Name: This endpoint is used when the user wants the detail of a specific permanent variable.
Example 4: Passing Variable as Parameters in RunScheduleNow Endpoint
User can also specify the variable directly in the Run Schedule Now endpoint where values can be assigned to the variables as shown in the screenshot below
For any clarification, please contact our Priority Support.