How to use variables in Leapwork?

How to use variables in Leapwork?

Introduction

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 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 exists.

Scope

Set the scope in which to load this variable.

Example 1: Get and Set Variable Block

Here is an example to use get and set blocks to add two variables Variable1 and Variable2.

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: Schedule Variables

You can define variables in the schedule and run the schedule based on that.

It is 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, see Cross-Browser Testing.

Example 3: Accessing variables 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 that can be used dynamically:

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.

For any clarification, contact our Priority Support.