Robot Framework Variables

Variables are elements 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 is a variable that 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.

Click on the First Test Case , and you will see the should be equal keyword in the tabular column. Right-click on the test suite and then select the new scalar option


Once you select the new scalar, the below page will appear on the UI, enter the variable name inside the curly braces ${var}. I gave the value as, because we are using the should be equal keyword and 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 one scalar variable


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 button on the top of the editor and then select the First Test
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, to get the value, the list item is passed as the argument to the list variable. The individual list items are passed in arguments separately

The syntax for the list variable is

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

Let us see how to create a List Variable

Go the Ride editor, and here I have already created another test case called the second test case, so right-click on it, once it open, in the tabular column, press ctrl+alt+space and select the should not be equal as strings And then right-click on the test suite 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


Now, go back to the second test case and pass the arguments with an index value, as shown below.


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


Demo Log :


Test execution log is as shown below


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:

&{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 a string in the Third test case


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


Once the dictionary page will open, 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 button and then select the Third Test Case and then click on the start button.


Once you open the log report, then you will see the below report


The Test Execution log


Data-Driven Test case

Supported File Formats for Robot Framework

The Robot framework test data can be defined in two different formats

Plain Text Format in Robot Framework

The plain text format is the base for all supported robot framework data formats. It can be edit by using the normal text editor and IDE's. Test Data can be parsed line by line. In single-line arguments and keywords are separated by a separator.

The most commonly used separator is space separator

Space separator : Two or more spaces acts as a separator between the two different data items. The minimum spaces should be two.

Let us see how to write the test cases in plain text format. Open the Ride editor and then click on any test case, here I am opening the First Test case.

You can see the three options Edit, Text Edit, and Run, click on the Text Edit to write the test case in the plain text format.


Create another test case in the plain text format as the Fourth test case and selected the keyword as Should Be Equal and pass the arguments as 4 and 4 by giving the two spaces between them.


We entered the test case in the text editor, and the same will be reflected in the Editor as well.


Keyword Rewind Functionality

Tab Separated Format(TSV)

The files in the TSV format are typically edited in the spreadsheet programs because the syntax is so simple, and they are easy to generate programmatically. They are pretty easy to edit by using the normal editor, and also they work well in version control.

In the case of Plain text format, we will use the spaces to separate the arguments, but in the case of TSV, we use tabs to separate the arguments.

We can create and edit the TSV files in any spreadsheet program, such as Microsoft Excel. The TSV file containing non-ASCII characters must be saved using UTF-8 encoding.

The files in the TSV format are commonly saved by using the .tsv extension. But starting from the framework 3.1, the --extension is used explicitly to tell that these files should be parsed. We can also save the TSV files with .robot extension, but this requires the files to be fully compatible with the plain text syntax.

The supported text formats are:

reStructured Text format: it is easy to read plain text markup syntax that is commonly used for documentation of python projects.

The reStructured documents are most often compiled to HTML, but still, other output formats are supported.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions