Robot Framework Variables

Variables are used to store values, that can be referred to by other elements. Variables can also be used in test cases and user-defined keywords.

Example: {Var1}=Bag

There are three types of variables in the robot framework

Web Elements of Robot Framework

Scalar Variable in Robot Framework

A Scalar variable holds a single value at a time, and it is a single component that assumes the range of numbers.

The Scalar variable is used to store the Strings, Objects, List, etc..

The syntax for the scalar variable is


Let us know how to create a scalar variable and make use of it.

In the Features Of Ride article, we have created a First Test Case, let us create a scalar variable by using the below command open the Ride Editor

Click on the project you have created, or if you want to create a new project, refer to the article Creating a New Project. Click on the Test Suite, which you have created, and then, you can see the test cases.

Right-click on the test suite(Demo1) and then select the New Scalar

Once you select the new scalar, the below popup will appear on the UI, enter the variable name inside the curly braces ${var}. I gave the value as 4 and we can provide any comment describing why we have this variable, I am passing the comment as This is my first scalar variable and then click ok.

If the scalar variable has created successfully, it will be displayed below the test suite.

I am creating another scalar variable ${var2}

Now go to the First Test Case and instead of values 4 and 4, I am going to give as ${var1} and ${var2}

Click on the Run tab on the top of the editor and then select the First Test Case and then click on the Start button.

The output is

Click on the log report, and the log report is as shown below

Test Execution log is as shown below

Suite Demo and test case is as shown below

Locators in Selenium

List Variables in Robot Framework

The List variable will have an array of values, The values in the list are enclosed with the square brackets and separated by a comma.

The syntax for the list variable is

@{user}=["Jaanu", "Jhanvi"]

Let us see how to create a List Variable

Right-click on the test suite(Demo1) and select the new list variable.

Fill the required parts, and here I am giving the name as a user and select the column number as one and then enter two values as jaanu and jhanvi and then click, ok.

You can see list variable displayed below the test suite

Create a test case called the second test case and add an assertion to compare the arguments with the index value. Here we are using assertion Should Not Be Equal As Strings

Now, click on the Run tab, and then select the second test case and click on the start button.

Basics of CSS Selector

Dictionary Variables in Robot Framework

The dictionary variables are similar to the List variables wherein we pass the index as an argument. However, in the case of the dictionary variable, we can store the details in the key-value pairs.

The syntax for the Dictionary variable is:

&{variablename}=['key1': 'value1' 'key2': 'value2',.......]
&{user}=['name' : 'Rakul', 'age' : '21']

Let us create a dictionary variable before that create a new test case to explain the dictionary variable.

Create the keyword as Should Be Equal As String in the Third test case

Right-click on the Demo suite and then select the New Dictionary Variables

Once the dictionary popup opens, enter the dictionary name and then the individual items in the format of key=value format.

Now, go back to the Third test case and enter the arguments as shown below

Click on the Run tab and then select the Third Test Case and then click on the start button.

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions