Robot Framework User Guide

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 263

DownloadRobot Framework User Guide
Open PDF In BrowserView PDF
6/24/2018

Robot Framework User Guide

Robot Framework User Guide
Version 3.0.4
Copyright © 2008-2015 Nokia Networks
Copyright © 2016- Robot Framework Foundation
Licensed under the Creative Commons Attribution 3.0 Unported license
Table of Contents
1 Getting started
1.1 Introduction
1.2 Copyright and license
1.3 Installation instructions
1.4 Demonstrations
2 Creating test data
2.1 Test data syntax
2.2 Creating test cases
2.3 Creating test suites
2.4 Using test libraries
2.5 Variables
2.6 Creating user keywords
2.7 Resource and variable files
2.8 Advanced features
3 Executing test cases
3.1 Basic usage
3.2 Test execution
3.3 Post-processing outputs
3.4 Configuring execution
3.5 Created outputs
4 Extending Robot Framework
4.1 Creating test libraries
4.2 Remote library interface
4.3 Listener interface
4.4 Extending the Robot Framework Jar
5 Supporting Tools
5.1 Library documentation tool (Libdoc)
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

1/263

6/24/2018

Robot Framework User Guide

5.2 Test data documentation tool (Testdoc)
5.3 Test data clean-up tool (Tidy)
5.4 External tools
6 Appendices
6.1 All available settings in test data
6.2 All command line options
6.3 Test data templates
6.4 Documentation formatting
6.5 Time format
6.6 Boolean arguments
6.7 Internal API

1 Getting started
1.1
1.2
1.3
1.4

Introduction
Copyright and license
Installation instructions
Demonstrations

1.1 Introduction
Robot Framework is a Python-based, extensible keyword-driven test automation framework for end-to-end acceptance testing and acceptance-test-driven
development (ATDD). It can be used for testing distributed, heterogeneous applications, where verification requires touching several technologies and
interfaces.
The framework has a rich ecosystem around it consisting of various generic test libraries and tools that are developed as separate projects. For more
information about Robot Framework and the ecosystem, see http://robotframework.org.
Robot Framework is open source software released under the Apache License 2.0. Its development is sponsored by the Robot Framework Foundation.
1.1.1
1.1.2
1.1.3
1.1.4

Why Robot Framework?
High-level architecture
Screenshots
Getting more information
Project pages
Mailing lists

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

2/263

6/24/2018

Robot Framework User Guide

1.1.1 Why Robot Framework?
Enables easy-to-use tabular syntax for creating test cases in a uniform way.
Provides ability to create reusable higher-level keywords from the existing keywords.
Provides easy-to-read result reports and logs in HTML format.
Is platform and application independent.
Provides a simple library API for creating customized test libraries which can be implemented natively with either Python or Java.
Provides a command line interface and XML based output files for integration into existing build infrastructure (continuous integration systems).
Provides support for Selenium for web testing, Java GUI testing, running processes, Telnet, SSH, and so on.
Supports creating data-driven test cases.
Has built-in support for variables, practical particularly for testing in different environments.
Provides tagging to categorize and select test cases to be executed.
Enables easy integration with source control: test suites are just files and directories that can be versioned with the production code.
Provides test-case and test-suite -level setup and teardown.
The modular architecture supports creating tests even for applications with several diverse interfaces.

1.1.2 High-level architecture
Robot Framework is a generic, application and technology independent framework. It has a highly modular architecture illustrated in the diagram below.

Robot Framework architecture

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

3/263

6/24/2018

Robot Framework User Guide

The test data is in simple, easy-to-edit tabular format. When Robot Framework is started, it processes the test data, executes test cases and generates logs
and reports. The core framework does not know anything about the target under test, and the interaction with it is handled by test libraries. Libraries can
either use application interfaces directly or use lower level test tools as drivers.

1.1.3 Screenshots
Following screenshots show examples of the test data and created reports and logs.

Test case files

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

4/263

6/24/2018

Robot Framework User Guide

Reports and logs

1.1.4 Getting more information
Project pages
The number one place to find more information about Robot Framework and the rich ecosystem around it is http://robotframework.org. Robot
Framework itself is hosted on GitHub.

Mailing lists
There are several Robot Framework mailing lists where to ask and search for more information. The mailing list archives are open for everyone
(including the search engines) and everyone can also join these lists freely. Only list members can send mails, though, and to prevent spam new users are
moderated which means that it might take a little time before your first message goes through. Do not be afraid to send question to mailing lists but
remember How To Ask Questions The Smart Way.
robotframework-users
General discussion about all Robot Framework related issues. Questions and problems can be sent to this list. Used also for information sharing for
all users.
robotframework-announce
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

5/263

6/24/2018

Robot Framework User Guide

An announcements-only mailing list where only moderators can send messages. All announcements are sent also to the robotframework-users
mailing list so there is no need to join both lists.
robotframework-devel
Discussion about Robot Framework development.

1.2 Copyright and license
Robot Framework is open source software provided under the Apache License 2.0. Robot Framework documentation such as this User Guide use the
Creative Commons Attribution 3.0 Unported license. Most libraries and tools in the larger ecosystem around the framework are also open source, but
they may use different licenses.
The full Robot Framework copyright notice is included below:
Copyright 2008-2015 Nokia Networks
Copyright 2016Robot Framework Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

1.3 Installation instructions
These instructions cover installing and uninstalling Robot Framework and its preconditions on different operating systems. If you already have pip
installed, it is enough to run:
pip install robotframework

1.3.1 Introduction
1.3.2 Preconditions
Python 2 vs Python 3
Python installation
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

6/263

6/24/2018

Robot Framework User Guide

Jython installation
IronPython installation
PyPy installation
Configuring PATH
Setting https_proxy
1.3.3 Installing with pip
Installing pip for Python
Installing pip for Jython
Installing pip for IronPython
Installing pip for PyPy
Using pip
1.3.4 Installing from source
Getting source code
Installation
1.3.5 Standalone JAR distribution
1.3.6 Manual installation
1.3.7 Verifying installation
Where files are installed
1.3.8 Uninstallation
1.3.9 Upgrading
1.3.10 Executing Robot Framework
Using robot and rebot scripts
Executing installed robot module
Executing installed robot directory
1.3.11 Using virtual environments

1.3.1 Introduction
Robot Framework is implemented with Python and supports also Jython (JVM), IronPython (.NET) and PyPy. Before installing the framework, an
obvious precondition is installing at least one of these interpreters.
Different ways to install Robot Framework itself are listed below and explained more thoroughly in the subsequent sections.
Installing with pip
Using pip is the recommended way to install Robot Framework. As the standard Python package manager it is included in the latest Python,
Jython and IronPython versions. If you already have pip available, you can simply execute:
pip install robotframework

Installing from source
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

7/263

6/24/2018

Robot Framework User Guide

This approach works regardless the operating system and the Python interpreter used. You can get the source code either by downloading a source
distribution from PyPI and extracting it, or by cloning the GitHub repository .
Standalone JAR distribution
If running tests with Jython is enough, the easiest approach is downloading the standalone robotframework-.jar from Maven
central. The JAR distribution contains both Jython and Robot Framework and thus only requires having Java installed.
Manual installation
If you have special needs and nothing else works, you can always do a custom manual installation.
Note
Prior to Robot Framework 3.0, there were also separate Windows installers for 32bit and 64bit Python versions. Because Python 2.7.9 and newer contain pip
on Windows and Python 3 would have needed two more installers, it was decided that Windows installers are not created anymore. The recommend
installation approach also on Windows is using pip.

1.3.2 Preconditions
Robot Framework is supported on Python (both Python 2 and Python 3), Jython (JVM) and IronPython (.NET) and PyPy. The interpreter you want to
use should be installed before installing the framework itself.
Which interpreter to use depends on the needed test libraries and test environment in general. Some libraries use tools or modules that only work with
Python, while others may use Java tools that require Jython or need .NET and thus IronPython. There are also many tools and libraries that run fine with
all interpreters.
If you do not have special needs or just want to try out the framework, it is recommended to use Python. It is the most mature implementation,
considerably faster than Jython or IronPython (especially start-up time is faster), and also readily available on most UNIX-like operating systems.
Another good alternative is using the standalone JAR distribution that only has Java as a precondition.

Python 2 vs Python 3
Python 2 and Python 3 are mostly the same language, but they are not fully compatible with each others. The main difference is that in Python 3 all
strings are Unicode while in Python 2 strings are bytes by default, but there are also several other backwards incompatible changes. The last Python 2
release is Python 2.7 that was released in 2010 and will be supported until 2020. See Should I use Python 2 or 3? for more information about the
differences, which version to use, how to write code that works with both versions, and so on.
Robot Framework 3.0 is the first Robot Framework version to support Python 3. It supports also Python 2, and the plan is to continue Python 2 support
as long as Python 2 itself is officially supported. We hope that authors of the libraries and tools in the wider Robot Framework ecosystem also start
looking at Python 3 support now that the core framework supports it.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

8/263

6/24/2018

Robot Framework User Guide

Python installation
On most UNIX-like systems such as Linux and OS X you have Python installed by default. If you are on Windows or otherwise need to install Python
yourself, a good place to start is http://python.org. There you can download a suitable installer and get more information about the installation process
and Python in general.
Robot Framework 3.0 supports Python 2.6, 2.7, 3.3 and newer, but the plan is to drop Python 2.6 support in RF 3.1. If you need to use older versions,
Robot Framework 2.5-2.8 support Python 2.5 and Robot Framework 2.0-2.1 support Python 2.3 and 2.4.
After installing Python, you probably still want to configure PATH to make Python itself as well as the robot and rebot runner scripts executable on the
command line.
Tip
Latest Python Windows installers allow setting PATH as part of the installation. This is disabled by default, but Add python.exe to Path can be enabled on
the Customize Python screen.

Jython installation
Using test libraries implemented with Java or that use Java tools internally requires running Robot Framework on Jython, which in turn requires Java
Runtime Environment (JRE) or Java Development Kit (JDK). Installing either of these Java distributions is out of the scope of these instructions, but you
can find more information, for example, from http://java.com.
Installing Jython is a fairly easy procedure, and the first step is getting an installer from http://jython.org. The installer is an executable JAR package,
which you can run from the command line like java -jar jython_installer-.jar. Depending on the system configuration, it may also
be possible to just double-click the installer.
Robot Framework 3.0 supports Jython 2.7 which requires Java 7 or newer. If older Jython or Java versions are needed, Robot Framework 2.5-2.8
support Jython 2.5 (requires Java 5 or newer) and Robot Framework 2.0-2.1 support Jython 2.2.
After installing Jython, you probably still want to configure PATH to make Jython itself as well as the robot and rebot runner scripts executable on the
command line.

IronPython installation
IronPython allows running Robot Framework on the .NET platform and interacting with C# and other .NET languages and APIs. Only IronPython 2.7
is supported.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

9/263

6/24/2018

Robot Framework User Guide

When using IronPython, an additional dependency is installing elementtree module 1.2.7 preview release. This is required because the elementtree
module distributed with IronPython is broken. You can install the package by downloading the source distribution, unzipping it, and running ipy
setup.py install on the command prompt in the created directory.
After installing IronPython, you probably still want to configure PATH to make IronPython itself as well as the robot and rebot runner scripts
executable on the command line.

PyPy installation
PyPy is an alternative implementation of the Python language with both Python 2 and Python 3 compatible versions available. Its main advantage over
the standard Python implementation is that it can be faster and use less memory, but this depends on the context where and how it is used. If execution
speed is important, at least testing PyPY is probably a good idea.
Installing PyPy is a straightforward procedure and you can find both installers and installation instructions at http://pypy.org. After installation you
probably still want to configure PATH to make PyPy itself as well as the robot and rebot runner scripts executable on the command line.

Configuring PATH
The PATH environment variable lists locations where commands executed in a system are searched from. To make using Robot Framework easier from
the command prompt, it is recommended to add the locations where the runner scripts are installed into the PATH. It is also often useful to have the
interpreter itself in the PATH to make executing it easy.
When using Python on UNIX-like machines both Python itself and scripts installed with should be automatically in the PATH and no extra actions
needed. On Windows and with other interpreters the PATH must be configured separately.
Tip
Latest Python Windows installers allow setting PATH as part of the installation. This is disabled by default, but Add python.exe to Path can be enabled on
the Customize Python screen. It will add both the Python installation directory and the Scripts directory to the PATH.

What directories to add to PATH
What directories you need to add to the PATH depends on the interpreter and the operating system. The first location is the installation directory of the
interpreter (e.g. C:\Python27) and the other is the location where scripts are installed with that interpreter. Both Python and IronPython install scripts to
Scripts directory under the installation directory on Windows (e.g. C:\Python27\Scripts) and Jython uses bin directory regardless the operating system
(e.g. C:\jython2.7.0\bin).
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

10/263

6/24/2018

Robot Framework User Guide

Notice that the Scripts and bin directories may not be created as part of the interpreter installation, but only later when Robot Framework or some other
third party module is installed.
Setting PATH on Windows
On Windows you can configure PATH by following the steps below. Notice that the exact setting names may be different on different Windows versions,
but the basic approach should still be the same.
1. Open Control Panel > System > Advanced > Environment Variables. There are User variables and System variables, and the
difference between them is that user variables affect only the current users, whereas system variables affect all users.
2. To edit an existing PATH value, select Edit and add ;; at the end of the value (e.g.
;C:\Python27;C:\Python27\Scripts). Note that the semicolons (;) are important as they separate the different entries. To add a new PATH
value, select New and set both the name and the value, this time without the leading semicolon.
3. Exit the dialog with Ok to save the changes.
4. Start a new command prompt for the changes to take effect.
Notice that if you have multiple Python versions installed, the executed robot or rebot runner script will always use the one that is first in the PATH
regardless under what Python version that script is installed. To avoid that, you can always execute the installed robot module directly like
C:\Python27\python.exe -m robot.
Notice also that you should not add quotes around directories you add into the PATH (e.g. "C:\Python27\Scripts"). Quotes can cause problems with
Python programs and they are not needed in this context even if the directory path would contain spaces.
Setting PATH on UNIX-like systems
On UNIX-like systems you typically need to edit either some system wide or user specific configuration file. Which file to edit and how depends on the
system, and you need to consult your operating system documentation for more details.

Setting https_proxy
If you are installing with pip and are behind a proxy, you need to set the https_proxy environment variable. It is needed both when installing pip itself
and when using it to install Robot Framework and other Python packages.
How to set the https_proxy depends on the operating system similarly as configuring PATH. The value of this variable must be an URL of the proxy,
for example, http://10.0.0.42:8080.

1.3.3 Installing with pip
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

11/263

6/24/2018

Robot Framework User Guide

The standard Python package manager is pip, but there are also other alternatives such as Buildout and easy_install. These instructions only cover using
pip, but other package managers ought be able to install Robot Framework as well.
Latest Python, Jython, IronPython and PyPy versions contain pip bundled in. Which versions contain it and how to possibly activate it is discussed in
sections below. See pip project pages if for the latest installation instructions if you need to install it.
Note
Only Robot Framework 2.7 and newer can be installed using pip. If you need an older version, you must use other installation approaches.

Installing pip for Python
Starting from Python 2.7.9, the standard Windows installer by default installs and activates pip. Assuming you also have configured PATH and possibly
set https_proxy, you can run pip install robotframework right after Python installation. With Python 3.4 and newer pip is officially part of the
interpreter and should be automatically available.
Outside Windows and with older Python versions you need to install pip yourself. You may be able to do it using system package managers like Apt or
Yum on Linux, but you can always use the manual installation instructions found from the pip project pages.
If you have multiple Python versions with pip installed, the version that is used when the pip command is executed depends on which pip is first in the
PATH. An alternative is executing the pip module using the selected Python version directly:
python -m pip install robotframework
python3 -m pip install robotframework

Installing pip for Jython
Jython 2.7 contain pip bundled in, but it needs to be activated before using it by running the following command:
jython -m ensurepip

Jython installs its pip into /bin directory. Does running pip install robotframework actually use it or possibly some other pip
version depends on which pip is first in the PATH. An alternative is executing the pip module using Jython directly:
jython -m pip install robotframework

Installing pip for IronPython
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

12/263

6/24/2018

Robot Framework User Guide

IronPython contains bundled pip starting from version 2.7.5. Similarly as with Jython, it needs to be activated first:
ipy -X:Frames -m ensurepip

Notice that with IronPython -X:Frames command line option is needed both when activating and when using pip.
IronPython installs pip into /Scripts directory. Does running pip install robotframework actually use it or possibly some
other pip version depends on which pip is first in the PATH. An alternative is executing the pip module using IronPython directly:
ipy -X:Frames -m pip install robotframework

IronPython versions prior to 2.7.5 do not officially support pip.

Installing pip for PyPy
Also PyPy contains pip bundled in. It is not activated by default, but it can be activated similarly as with the other interpreters:
pypy -m ensurepip
pypy3 -m ensurepip

If you have multiple Python versions with pip installed, the version that is used when the pip command is executed depends on which pip is first in the
PATH. An alternative is executing the pip module using PyPy directly:
pypy -m pip
pypy3 -m pip

Using pip
Once you have pip installed, and have set https_proxy if you are behind a proxy, using pip on the command line is very easy. The easiest way to use pip
is by letting it find and download packages it installs from the Python Package Index (PyPI), but it can also install packages downloaded from the PyPI
separately. The most common usages are shown below and pip documentation has more information and examples.
# Install the latest version (does not upgrade)
pip install robotframework
# Upgrade to the latest version
pip install --upgrade robotframework
# Install a specific version
pip install robotframework==2.9.2
# Install separately downloaded package (no network connection needed)
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

13/263

6/24/2018

Robot Framework User Guide

pip install robotframework-3.0.tar.gz
# Install latest (possibly unreleased) code directly from GitHub
pip install git+https://github.com/robotframework/RobotFramework.git
# Uninstall
pip uninstall robotframework

Notice that pip 1.4 and newer will only install stable releases by default. If you want to install an alpha, beta or release candidate, you need to either
specify the version explicitly or use the --pre option:
# Install 3.0 beta 1
pip install robotframework==3.0b1
# Upgrade to the latest version even if it is a pre-release
pip install --pre --upgrade robotframework

Notice that on Windows pip, by default, does not recreate robot.bat and rebot.bat start-up scripts if the same Robot Framework version is installed
multiple times using the same Python version. This mainly causes problems when using virtual environments, but is something to take into account also if
doing custom installations using pip. A workaround if using the --no-cache-dir option like pip install --no-cache-dir robotframework.
Alternatively it is possible to ignore the start-up scripts altogether and just use python -m robot and python -m robot.rebot commands instead.

1.3.4 Installing from source
This installation method can be used on any operating system with any of the supported interpreters. Installing from source can sound a bit scary, but the
procedure is actually pretty straightforward.

Getting source code
You typically get the source by downloading a source distribution from PyPI as a .tar.gz package. Once you have downloaded the package, you need
to extract it somewhere and, as a result, you get a directory named robotframework-. The directory contains the source code and a
setup.py script needed for installing it.
An alternative approach for getting the source code is cloning project's GitHub repository directly. By default you will get the latest code, but you can
easily switch to different released versions or other tags.

Installation
Robot Framework is installed from source using Python's standard setup.py script. The script is in the directory containing the sources and you can run
it from the command line using any of the supported interpreters:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

14/263

6/24/2018

Robot Framework User Guide

python setup.py install
jython setup.py install
ipy setup.py install
pypy setup.py install

The setup.py script accepts several arguments allowing, for example, installation into a non-default location that does not require administrative rights.
It is also used for creating different distribution packages. Run python setup.py --help for more details.

1.3.5 Standalone JAR distribution
Robot Framework is also distributed as a standalone Java archive that contains both Jython and Robot Framework and only requires Java a dependency.
It is an easy way to get everything in one package that requires no installation, but has a downside that it does not work with the normal Python
interpreter.
The package is named robotframework-.jar and it is available on the Maven central. After downloading the package, you can execute
tests with it like:
java -jar robotframework-3.0.jar mytests.robot
java -jar robotframework-3.0.jar --variable name:value mytests.robot

If you want to post-process outputs using Rebot or use other built-in supporting tools, you need to give the command name rebot, libdoc, testdoc or
tidy as the first argument to the JAR file:
java -jar robotframework-3.0.jar rebot output.xml
java -jar robotframework-3.0.jar libdoc MyLibrary list

For more information about the different commands, execute the JAR without arguments.
In addition to the Python standard library and Robot Framework modules, the standalone JAR versions starting from 2.9.2 also contain the PyYAML
dependency needed to handle yaml variable files.

1.3.6 Manual installation
If you do not want to use any automatic way of installing Robot Framework, you can always install it manually following these steps:
1. Get the source code. All the code is in a directory (a package in Python) called robot. If you have a source distribution or a version control
checkout, you can find it from the src directory, but you can also get it from an earlier installation.
2. Copy the source code where you want to.
3. Decide how to run tests.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

15/263

6/24/2018

Robot Framework User Guide

1.3.7 Verifying installation
After a successful installation, you should be able to execute the created runner scripts with --version option and get both Robot Framework and
interpreter versions as a result:
$ robot --version
Robot Framework 3.0 (Python 2.7.10 on linux2)
$ rebot --version
Rebot 3.0 (Python 2.7.10 on linux2)

If running the runner scripts fails with a message saying that the command is not found or recognized, a good first step is double-checking the PATH
configuration. If that does not help, it is a good idea to re-read relevant sections from these instructions before searching help from the Internet or as
asking help on robotframework-users mailing list or elsewhere.

Where files are installed
When an automatic installer is used, Robot Framework source code is copied into a directory containing external Python modules. On UNIX-like
operating systems where Python is pre-installed the location of this directory varies. If you have installed the interpreter yourself, it is normally Lib/sitepackages under the interpreter installation directory, for example, C:\Python27\Lib\site-packages. The actual Robot Framework code is in a directory
named robot.
Robot Framework runner scripts are created and copied into another platform-specific location. When using Python on UNIX-like systems, they
normally go to /usr/bin or /usr/local/bin. On Windows and with Jython and IronPython, the scripts are typically either in Scripts or bin directory under
the interpreter installation directory.

1.3.8 Uninstallation
The easiest way to uninstall Robot Framework is using pip:
pip uninstall robotframework

A nice feature in pip is that it can uninstall packages even if they are installed from the source. If you do not have pip available or have done a manual
installation to a custom location, you need to find where files are installed and remove them manually.
If you have set PATH or configured the environment otherwise, you need to undo those changes separately.

1.3.9 Upgrading
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

16/263

6/24/2018

Robot Framework User Guide

If you are using pip, upgrading to a new version requires either specifying the version explicitly or using the --upgrade option. If upgrading to a
preview release, --pre option is needed as well.
# Upgrade to the latest stable version. This is the most common method.
pip install --upgrade robotframework
# Upgrade to the latest version even if it would be a preview release.
pip install --upgrade --pre robotframework
# Upgrade to the specified version.
pip install robotframework==2.9.2

When using pip, it automatically uninstalls previous versions before installation. If you are installing from source, it should be safe to just install over an
existing installation. If you encounter problems, uninstallation before installation may help.
When upgrading Robot Framework, there is always a change that the new version contains backwards incompatible changes affecting existing tests or
test infrastructure. Such changes are very rare in minor versions like 2.8.7 or 2.9.2, but more common in major versions like 2.9 and 3.0. Backwards
incompatible changes and deprecated features are explained in the release notes, and it is a good idea to study them especially when upgrading to a new
major version.

1.3.10 Executing Robot Framework
Using robot and rebot scripts
Starting from Robot Framework 3.0, tests are executed using the robot script and results post-processed with the rebot script:
robot tests.robot
rebot output.xml

Both of these scripts are installed as part of the normal installation and can be executed directly from the command line if PATH is set correctly. They are
implemented using Python except on Windows where they are batch files.
Older Robot Framework versions do not have the robot script and the rebot script is installed only with Python. Instead they have interpreter specific
scripts pybot, jybot and ipybot for test execution and jyrebot and ipyrebot for post-processing outputs. These scripts still work, but they will be
deprecated and removed in the future.

Executing installed robot module
An alternative way to run tests is executing the installed robot module or its sub module robot.run directly using Python's -m command line option.
This is especially useful if Robot Framework is used with multiple Python versions:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

17/263

6/24/2018

Robot Framework User Guide

python -m robot tests.robot
python3 -m robot.run tests.robot
jython -m robot tests.robot
/opt/jython/jython -m robot tests.robot

The support for python -m robot approach is a new feature in Robot Framework 3.0, but the older versions support python -m robot.run. The
latter must also be used with Python 2.6.
Post-processing outputs using the same approach works too, but the module to execute is robot.rebot:
python -m robot.rebot output.xml

Executing installed robot directory
If you know where Robot Framework is installed, you can also execute the installed robot directory or the run.py file inside it directly:
python path/to/robot/ tests.robot
jython path/to/robot/run.py tests.robot

Running the directory is a new feature in Robot Framework 3.0, but the older versions support running the robot/run.py file.
Post-processing outputs using the robot/rebot.py file works the same way too:
python path/to/robot/rebot.py output.xml

Executing Robot Framework this way is especially handy if you have done a manual installation.

1.3.11 Using virtual environments
Python virtual environments allow Python packages to be installed in an isolated location for a particular system or application, rather than installing all
packages into the same global location. Virtual environments can be created using the virtualenv tool or, starting from Python 3.3, using the standard
venv module.
Robot Framework in general works fine with virtual environments. The only problem is that when using pip on Windows, robot.bat and rebot.bat
scripts are not recreated by default. This means that if Robot Framework is installed into multiple virtual environments, the robot.bat and rebot.bat
scripts in the latter ones refer to the Python installation in the first virtual environment. A workaround is using the --no-cache-dir option when
installing. Alternatively the start-up scripts can be ignored and python -m robot and python -m robot.rebot commands used instead.

1.4 Demonstrations
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

18/263

6/24/2018

Robot Framework User Guide

There are several demo projects that introduce Robot Framework and help getting started with it.
Quick Start Guide
Introduces the most important features of Robot Framework and acts as an executable demo.
Robot Framework demo
Simple example test cases. Demonstrates also creating custom test libraries.
Web testing demo
Demonstrates how to create tests and higher level keywords. The system under test is a simple web page that is tested using SeleniumLibrary.
SwingLibrary demo
Demonstrates using SwingLibrary for testing Java GUI applications.
ATDD with Robot Framework
Demonstrates how to use Robot Framework when following Acceptance Test Driven Development (ATDD) process.

2 Creating test data
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8

Test data syntax
Creating test cases
Creating test suites
Using test libraries
Variables
Creating user keywords
Resource and variable files
Advanced features

2.1 Test data syntax
This section covers Robot Framework's overall test data syntax. The following sections will explain how to actually create test cases, test suites and so
on.
2.1.1 Files and directories
2.1.2 Supported file formats
HTML format
TSV format
Plain text format
reStructuredText format
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

19/263

6/24/2018

Robot Framework User Guide

2.1.3 Test data tables
2.1.4 Rules for parsing the data
Ignored data
Handling whitespace
Escaping
Dividing test data to several rows

2.1.1 Files and directories
The hierarchical structure for arranging test cases is built as follows:
Test cases are created in test case files.
A test case file automatically creates a test suite containing the test cases in that file.
A directory containing test case files forms a higher-level test suite. Such a test suite directory has suites created from test case files as its sub test
suites.
A test suite directory can also contain other test suite directories, and this hierarchical structure can be as deeply nested as needed.
Test suite directories can have a special initialization file.
In addition to this, there are:
Test libraries containing the lowest-level keywords.
Resource files with variables and higher-level user keywords.
Variable files to provide more flexible ways to create variables than resource files.

2.1.2 Supported file formats
Robot Framework test data is defined in tabular format, using either hypertext markup language (HTML), tab-separated values (TSV), plain text, or
reStructuredText (reST) formats. The details of these formats, as well as the main benefits and problems with them, are explained in the subsequent
sections. Which format to use depends on the context, but the plain text format is recommended if there are no special needs.
Robot Framework selects a parser for the test data based on the file extension. The extension is case-insensitive, and the recognized extensions are .html,
.htm and .xhtml for HTML, .tsv for TSV, .txt and special .robot for plain text, and .rst and .rest for reStructuredText.
Different test data templates are available for HTML and TSV formats to make it easier to get started writing tests.
Note
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

20/263

6/24/2018

Robot Framework User Guide

The special .robot extension with plain text files is supported starting from Robot Framework 2.7.6.

HTML format
HTML files support formatting and free text around tables. This makes it possible to add additional information into test case files and allows creating test
case files that look like formal test specifications. The main problem with HTML format is that editing these files using normal text editors is not that
easy. Another problem is that HTML does not work as well with version control systems because the diffs resulting from changes contain HTML syntax
in addition to changes to the actual test data.
In HTML files, the test data is defined in separate tables (see the example below). Robot Framework recognizes these test data tables based on the text in
their first cell. Everything outside recognized tables is ignored.
Using the HTML format
Setting
Library

Value
OperatingSystem

Value

Value

Variable
${MESSAGE}

Value
Hello, world!

Value

Value

Test Case
My Test

Action
[Documentation]
Log
My Keyword

Argument
Example test
${MESSAGE}
/tmp

Another Test

Should Be Equal

${MESSAGE}

Keyword
My Keyword

Action
[Arguments]
Directory Should Exist

Argument

Hello, world!

Argument
${path}
${path}

Argument

Editing test data
Test data in HTML files can be edited with whichever editor you prefer, but a graphic editor, where you can actually see the tables, is recommended.
RIDE can read and write HTML files, but unfortunately it loses all HTML formatting and also possible data outside test case tables.
Encoding and entity references
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

21/263

6/24/2018

Robot Framework User Guide

HTML entity references (for example, ä) are supported. Additionally, any encoding can be used, assuming that it is specified in the data file.
Normal HTML files must use the META element as in the example below:


XHTML files should use the XML preamble as in this example:


If no encoding is specified, Robot Framework uses ISO-8859-1 by default.

TSV format
TSV files can be edited in spreadsheet programs and, because the syntax is so simple, they are easy to generate programmatically. They are also pretty
easy to edit using normal text editors and they work well in version control, but the plain text format is even better suited for these purposes.
The TSV format can be used in Robot Framework's test data for all the same purposes as HTML. In a TSV file, all the data is in one large table. Test
data tables are recognized from one or more asterisks (*), followed by a normal table name and an optional closing asterisks. Everything before the first
recognized table is ignored similarly as data outside tables in HTML data.
Using the TSV format
*Setting*
Library

*Value*
OperatingSystem

*Value*

*Value*

*Variable*
${MESSAGE}

*Value*
Hello, world!

*Value*

*Value*

*Test Case*
My Test

*Action*
[Documentation]
Log
My Keyword

*Argument*
Example test
${MESSAGE}
/tmp

*Argument*

Another Test

Should Be Equal

${MESSAGE}

Hello, world!

*Keyword*
My Keyword

*Action*
[Arguments]
Directory Should Exist

*Argument*
${path}
${path}

*Argument*

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

22/263

6/24/2018

Robot Framework User Guide

Editing test data
You can create and edit TSV files in any spreadsheet program, such as Microsoft Excel. Select the tab-separated format when you save the file and
remember to set the file extension to .tsv. It is also a good idea to turn all automatic corrections off and configure the tool to treat all values in the file as
plain text.
TSV files are relatively easy to edit with any text editor, especially if the editor supports visually separating tabs from spaces. The TSV format is also
supported by RIDE.
Robot Framework parses TSV data by first splitting all the content into rows and then rows into cells on the basis of the tabular characters. Spreadsheet
programs sometimes surround cells with quotes (for example, "my value") and Robot Framework removes them. Possible quotes inside the data are
doubled (for example, "my ""quoted"" value") and also this is handled correctly. If you are using a spreadsheet program to create TSV data, you
should not need to pay attention to this, but if you create data programmatically, you have to follow the same quoting conventions as spreadsheets.
Encoding
TSV files are always expected to use UTF-8 encoding. Because ASCII is a subset of UTF-8, plain ASCII is naturally supported too.

Plain text format
The plain texts format is very easy to edit using any text editor and they also work very well in version control. Because of these benefits it has became
the most used data format with Robot Framework.
The plain text format is technically otherwise similar to the TSV format but the separator between the cells is different. The TSV format uses tabs, but in
the plain text format you can use either two or more spaces or a pipe character surrounded with spaces (|).
The test data tables must have one or more asterisk before their names similarly as in the TSV format. Otherwise asterisks and possible spaces in the table
header are ignored so, for example, *** Settings *** and *Settings work the same way. Also similarly as in the TSV format, everything before the
first table is ignored.
In plain text files tabs are automatically converted to two spaces. This allows using a single tab as a separator similarly as in the TSV format. Notice,
however, that in the plain text format multiple tabs are considered to be a single separator whereas in the TSV format every tab would be a separator.
Space separated format
The number of spaces used as separator can vary, as long as there are at least two spaces, and it is thus possible to align the data nicely. This is a clear
benefit over editing the TSV format in a text editor because with TSV the alignment cannot be controlled.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

23/263

6/24/2018

Robot Framework User Guide

*** Settings ***
Library
OperatingSystem
*** Variables ***
${MESSAGE}
Hello, world!
*** Test Cases ***
My Test
[Documentation]
Example test
Log
${MESSAGE}
My Keyword
/tmp
Another Test
Should Be Equal

${MESSAGE}

*** Keywords ***
My Keyword
[Arguments]
${path}
Directory Should Exist

Hello, world!

${path}

Because space is used as separator, all empty cells must be escaped with ${EMPTY} variable or a single backslash. Otherwise handling whitespace is not
different than in other test data because leading, trailing, and consecutive spaces must always be escaped.
Tip
It is recommend to use four spaces between keywords and arguments.

Pipe and space separated format
The biggest problem of the space delimited format is that visually separating keywords from arguments can be tricky. This is a problem especially if
keywords take a lot of arguments and/or arguments contain spaces. In such cases the pipe and space delimited variant can work better because it makes
the cell boundary more visible.
| *Setting*
| Library

|
*Value*
|
| OperatingSystem |

| *Variable* |
*Value*
| ${MESSAGE} | Hello, world!
| *Test Case*
| My Test
|
|
| Another Test

|
|
|
|
|

|
|

*Action*
[Documentation]
Log
My Keyword
Should Be Equal

|
|
|
|
|

*Argument*
Example test
${MESSAGE}
/tmp
${MESSAGE}

|
|
|
|
| Hello, world!

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

24/263

6/24/2018

Robot Framework User Guide

| *Keyword* |
| My Keyword | [Arguments] | ${path}
|
| Directory Should Exist | ${path}

A plain text file can contain test data in both space-only and space-and-pipe separated formats, but a single line must always use the same separator. Pipe
and space separated lines are recognized by the mandatory leading pipe, but the pipe at the end of the line is optional. There must always be at least one
space on both sides of the pipe (except at the beginning and end) but there is no need to align the pipes other than if it makes the data more clear.
There is no need to escape empty cells (other than the trailing empty cells) when using the pipe and space separated format. The only thing to take into
account is that possible pipes surrounded by spaces in the actual test data must be escaped with a backslash:
| *** Test Cases *** |
|
|
|
| Escaping Pipe
| ${file count} = | Execute Command | ls -1 *.txt \| wc -l |
|
| Should Be Equal | ${file count}
| 42
|

Editing and encoding
One of the biggest benefit of the plain text format over HTML and TSV is that editing it using normal text editors is very easy. Many editors and IDEs
(at least Eclipse, Emacs, Vim, and TextMate) also have plugins that support syntax highlighting Robot Framework test data and may also provide other
features such as keyword completion. The plain text format is also supported by RIDE.
Similarly as with the TSV test data, plain text files are always expected to use UTF-8 encoding. As a consequence also ASCII files are supported.
Recognized extensions
Starting from Robot Framework 2.7.6, it is possible to save plain text test data files using a special .robot extension in addition to the normal .txt
extension. The new extension makes it easier to distinguish test data files from other plain text files.

reStructuredText format
reStructuredText (reST) is an easy-to-read plain text markup syntax that is commonly used for documentation of Python projects (including Python itself,
as well as this User Guide). reST documents are most often compiled to HTML, but also other output formats are supported.
Using reST with Robot Framework allows you to mix richly formatted documents and test data in a concise text format that is easy to work with using
simple text editors, diff tools, and source control systems. In practice it combines many of the benefits of plain text and HTML formats.
When using reST files with Robot Framework, there are two ways to define the test data. Either you can use code blocks and define test cases in them
using the plain text format or alternatively you can use tables exactly like you would with the HTML format.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

25/263

6/24/2018

Robot Framework User Guide

Note
Using reST files with Robot Framework requires the Python docutils module to be installed.

Using code blocks
reStructuredText documents can contain code examples in so called code blocks. When these documents are compiled into HTML or other formats, the
code blocks are syntax highlighted using Pygments. In standard reST code blocks are started using the code directive, but Sphinx uses code-block or
sourcecode instead. The name of the programming language in the code block is given as an argument to the directive. For example, following code
blocks contain Python and Robot Framework examples, respectively:
.. code:: python
def example_keyword():
print 'Hello, world!'
.. code:: robotframework
*** Test Cases ***
Example Test
Example Keyword

When Robot Framework parses reStructuredText files, it first searches for possible code, code-block or sourcecode blocks containing Robot
Framework test data. If such code blocks are found, data they contain is written into an in-memory file and executed. All data outside the code blocks is
ignored.
The test data in the code blocks must be defined using the plain text format. As the example below illustrates, both space and pipe separated variants are
supported:
Example
------This text is outside code blocks and thus ignored.
.. code:: robotframework
*** Settings ***
Library
OperatingSystem
*** Variables ***
${MESSAGE}
Hello, world!
*** Test Cases ***
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

26/263

6/24/2018

Robot Framework User Guide

My Test
[Documentation]
Example test
Log
${MESSAGE}
My Keyword
/tmp
Another Test
Should Be Equal

${MESSAGE}

Hello, world!

Also this text is outside code blocks and ignored. Above block used
the space separated plain text format and the block below uses the pipe
separated variant.
.. code:: robotframework
| *** Keyword ***
| My Keyword
|

|
|
|
| [Arguments]
| ${path} |
| Directory Should Exist | ${path} |

Note
Escaping using the backslash character works normally in this format. No double escaping is needed like when using reST tables.
Note
Support for test data in code blocks is a new feature in Robot Framework 2.8.2.

Using tables
If a reStructuredText document contains no code blocks with Robot Framework data, it is expected to contain the data in tables similarly as in the HTML
format. In this case Robot Framework compiles the document to HTML in memory and parses it exactly like it would parse a normal HTML file.
Robot Framework identifies test data tables based on the text in the first cell and all content outside of the recognized table types is ignored. An example
of each of the four test data tables is shown below using both simple table and grid table syntax:
Example
------This text is outside tables and thus ignored.
============
Setting
============
Library

================
Value
================
OperatingSystem

=======
Value
=======

=======
Value
=======

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

27/263

6/24/2018

Robot Framework User Guide

============

================

=======

=======

============
Variable
============
${MESSAGE}
============

================
Value
================
Hello, world!
================

=======
Value
=======

=======
Value
=======

=======

=======

=============
Test Case
=============
My Test
\
\
\
Another Test
=============

==================
Action
==================
[Documentation]
Log
My Keyword

============
Argument
============
Example test
${MESSAGE}
/tmp

=============
Argument
=============

Should Be Equal
==================

${MESSAGE}
============

Hello, world!
=============

Also this text is outside tables and ignored. Above tables are created
using the simple table syntax and the table below uses the grid table
approach.
+-------------+------------------------+------------+------------+
|
Keyword
|
Action
| Argument | Argument |
+-------------+------------------------+------------+------------+
| My Keyword | [Arguments]
| ${path}
|
|
+-------------+------------------------+------------+------------+
|
| Directory Should Exist | ${path}
|
|
+-------------+------------------------+------------+------------+

Note
Empty cells in the first column of simple tables need to be escaped. The above example uses \ but .. could also be used.
Note
Because the backslash character is an escape character in reST, specifying a backslash so that Robot Framework will see it requires escaping it with an other
backslash like \\. For example, a new line character must be written like \\n. Because the backslash is used for escaping also in Robot Framework data,
specifying a literal backslash when using reST tables requires double escaping like c:\\\\temp.

Generating HTML files based on reST files every time tests are run obviously adds some overhead. If this is a problem, it can be a good idea to convert
reST files to HTML using external tools separately, and let Robot Framework use the generated files only.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

28/263

6/24/2018

Robot Framework User Guide

Editing and encoding
Test data in reStructuredText files can be edited with any text editor, and many editors also provide automatic syntax highlighting for it. reST format is
not supported by RIDE, though.
Robot Framework requires reST files containing non-ASCII characters to be saved using UTF-8 encoding.
Syntax errors in reST source files
If a reStructuredText document is not syntactically correct (a malformed table for example), parsing it will fail and no test cases can be found from that
file. When executing a single reST file, Robot Framework will show the error on the console. When executing a directory, such parsing errors will
generally be ignored.
Starting from Robot Framework 2.9.2, errors below level SEVERE are ignored when running tests to avoid noise about non-standard directives and other
such markup. This may hide also real errors, but they can be seen when processing files normally.

2.1.3 Test data tables
Test data is structured in four types of tables listed below. These test data tables are identified by the first cell of the table. Recognized table names are
Settings, Variables, Test Cases, and Keywords. Matching is case-insensitive and also singular variants like Setting and Test Case are accepted.
Different test data tables
Table
Settings
Variables
Test Cases
Keywords

Used for
1) Importing test libraries, resource files and variable files.
2) Defining metadata for test suites and test cases.
Defining variables that can be used elsewhere in the test
data.
Creating test cases from available keywords.
Creating user keywords from existing lower-level keywords

2.1.4 Rules for parsing the data
Ignored data
When Robot Framework parses the test data, it ignores:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

29/263

6/24/2018

Robot Framework User Guide

All tables that do not start with a recognized table name in the first cell.
Everything else on the first row of a table apart from the first cell.
All data before the first table. If the data format allows data between tables, also that is ignored.
All empty rows, which means these kinds of rows can be used to make the tables more readable.
All empty cells at the end of rows, unless they are escaped.
All single backslashes (\) when not used for escaping.
All characters following the hash character (#), when it is the first character of a cell. This means that hash marks can be used to enter comments in
the test data.
All formatting in the HTML/reST test data.
When Robot Framework ignores some data, this data is not available in any resulting reports and, additionally, most tools used with Robot Framework
also ignore them. To add information that is visible in Robot Framework outputs, place it to the documentation or other metadata of test cases or suites, or
log it with the BuiltIn keywords Log or Comment.

Handling whitespace
Robot Framework handles whitespace the same way as they are handled in HTML source code:
Newlines, carriage returns, and tabs are converted to spaces.
Leading and trailing whitespace in all cells is ignored.
Multiple consecutive spaces are collapsed into a single space.
In addition to that, non-breaking spaces are replaced with normal spaces. This is done to avoid hard-to-debug errors when a non-breaking space is
accidentally used instead of a normal space.
If leading, trailing, or consecutive spaces are needed, they must be escaped. Newlines, carriage returns, tabs, and non-breaking spaces can be created
using escape sequences \n, \r, \t, and \xA0 respectively.

Escaping
The escape character in Robot Framework test data is the backslash (\) and additionally built-in variables ${EMPTY} and ${SPACE} can often be used for
escaping. Different escaping mechanisms are discussed in the sections below.
Escaping special characters
The backslash character can be used to escape special characters so that their literal values are used.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

30/263

6/24/2018

Robot Framework User Guide

Escaping special characters
Character
\$
\@
\%
\#
\=
\|
\\

Meaning
Dollar sign, never starts a scalar variable.
At sign, never starts a list variable.
Percent sign, never starts an environment variable.
Hash sign, never starts a comment.
Equal sign, never part of named argument syntax.
Pipe character, not a separator in the pipe separated format.
Backslash character, never escapes anything.

Examples
\${notvar}
\@{notvar}
\%{notvar}
\# not comment
not\=named
| Run | ps \| grep xxx |
c:\\temp, \\${var}

Forming escape sequences
The backslash character also allows creating special escape sequences that are recognized as characters that would otherwise be hard or impossible to
create in the test data.
Escape sequences
Sequence
\n
\r
\t
\xhh
\uhhhh
\Uhhhhhhhh

Meaning
Newline character.
Carriage return character
Tab character.
Character with hex value hh.
Character with hex value hhhh.
Character with hex value hhhhhhhh.

Examples
first line\n2nd line
text\rmore text
text\tmore text
null byte: \x00, ä:
\xE4
snowman: \u2603
love hotel: \U0001f3e9

Note
All strings created in the test data, including characters like \x02, are Unicode and must be explicitly converted to byte strings if needed. This can be done,
for example, using Convert To Bytes or Encode String To Bytes keywords in BuiltIn and String libraries, respectively, or with something like str(value) or
value.encode('UTF-8') in Python code.
Note
If invalid hexadecimal values are used with \x, \u or \U escapes, the end result is the original value without the backslash character. For example, \xAX (not
hex) and \U00110000 (too large value) result with xAX and U00110000, respectively. This behavior may change in the future, though.
Note
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

31/263

6/24/2018

Robot Framework User Guide

Built-in variable ${\n} can be used if operating system dependent line terminator is needed (\r\n on Windows and \n elsewhere).
Note
Possible un-escaped whitespace character after the \n is ignored. This means that two lines\nhere and two lines\n here are equivalent. The motivation
for this is to allow wrapping long lines containing newlines when using the HTML format, but the same logic is used also with other formats. An exception
to this rule is that the whitespace character is not ignored inside the extended variable syntax.
Note
\x, \u

and \U escape sequences are new in Robot Framework 2.8.2.

Prevent ignoring empty cells
If empty values are needed as arguments for keywords or otherwise, they often need to be escaped to prevent them from being ignored. Empty trailing
cells must be escaped regardless of the test data format, and when using the space separated format all empty values must be escaped.
Empty cells can be escaped either with the backslash character or with built-in variable ${EMPTY}. The latter is typically recommended as it is easier to
understand. An exception to this recommendation is escaping the indented cells in for loops with a backslash when using the space separated format. All
these cases are illustrated in the following examples first in HTML and then in the space separated plain text format:
Test Case
Using backslash
Using ${EMPTY}
Non-trailing empty
For loop

Action
Do Something
Do Something
Do Something
:FOR

Argument
first arg
first arg
${var}
Log

*** Test Cases ***
Using backslash
Do Something
first arg
\
Using ${EMPTY}
Do Something
first arg
${EMPTY}
Non-trailing empty
Do Something
${EMPTY}
second arg
For loop
:FOR
${var}
IN
@{VALUES}
\
Log
${var}

Argument
\
${EMPTY}
second arg
IN
${var}

Argument

# No escaping needed in HTML
@{VALUES}
# No escaping needed here either

# Escaping needed in space separated format
# Escaping needed here too

Prevent ignoring spaces
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

32/263

6/24/2018

Robot Framework User Guide

Because leading, trailing, and consecutive spaces in cells are ignored, they need to be escaped if they are needed as arguments to keywords or otherwise.
Similarly as when preventing ignoring empty cells, it is possible to do that either using the backslash character or using built-in variable ${SPACE}.
Escaping spaces examples
Escaping with backslash

Escaping with ${SPACE}

\ leading space

${SPACE}leading space

trailing space \

trailing space${SPACE}

Notes

Backslash must be after the space.
${SPACE}
Backslash needed on both sides.
consecutive${SPACE * 3}spaces Using extended variable syntax.

\ \
consecutive \ \ spaces

As the above examples show, using the ${SPACE} variable often makes the test data easier to understand. It is especially handy in combination with the
extended variable syntax when more than one space is needed.

Dividing test data to several rows
If there is more data than readily fits a row, it possible to use ellipsis (...) to continue the previous line. In test case and keyword tables, the ellipsis must
be preceded by at least one empty cell. In settings and variable tables, it can be placed directly under the setting or variable name. In all tables, all empty
cells before the ellipsis are ignored.
Additionally, values of settings that take only one value (mainly documentations) can be split to several columns. These values will be then catenated
together with spaces when the test data is parsed. Starting from Robot Framework 2.7, documentation and test suite metadata split into multiple rows will
be catenated together with newlines.
All the syntax discussed above is illustrated in the following examples. In the first three tables test data has not been split, and the following three
illustrate how fewer columns are needed after splitting the data to several rows.
Test data that has not been split
Setting
Default Tags
Variable
@{LIST}

Value
tag-1
Value
this

Test Case
Example

Value
tag-2
Value
list

Value
tag-3
Value
has

Action
[Documentation]

[Tags]
Do X
${var} =

Value
tag-4
Value
quite

Value
tag-5

Value
tag-6

Value
many

Value
items

Argument
Documentation for this test
case.\n This can get quite
long...
t-1
one
Get X

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

Arg

t-2
two
1

Arg

t-3
three
2

Arg

t-4
four
3

Arg

t-5
five
4

Arg

six
5

Arg

6
33/263

6/24/2018

Robot Framework User Guide

Test data split to several rows
Setting
Default Tags
...
Variable
@{LIST}
...
Test Case
Example

Value
tag-1
tag-4
Value
this
quite

Value
tag-2
tag-5
Value
list
many

Action
[Documentation]
...
[Tags]
...
Do X
...
${var} =

Value
tag-3
tag-6
Value
has
items
Argument
Documentation
This can get
t-1
t-4
one
four
Get X
...
...

Argument
for this
quite
t-2
t-5
two
five
1
3
5

Argument
test case.
long...
t-3
three
six
2
4
6

2.2 Creating test cases
This section describes the overall test case syntax. Organizing test cases into test suites using test case files and test suite directories is discussed in the
next section.
2.2.1 Test case syntax
Basic syntax
Settings in the Test Case table
Test case related settings in the Setting table
2.2.2 Using arguments
Mandatory arguments
Default values
Variable number of arguments
Named arguments
Free keyword arguments
Arguments embedded to keyword names
2.2.3 Failures
When test case fails
Error messages
2.2.4 Test case name and documentation
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

34/263

6/24/2018

Robot Framework User Guide

2.2.5 Tagging test cases
Reserved tags
2.2.6 Test setup and teardown
2.2.7 Test templates
Basic usage
Templates with embedded arguments
Templates with for loops
2.2.8 Different test case styles
Keyword-driven style
Data-driven style
Behavior-driven style

2.2.1 Test case syntax
Basic syntax
Test cases are constructed in test case tables from the available keywords. Keywords can be imported from test libraries or resource files, or created in the
keyword table of the test case file itself.
The first column in the test case table contains test case names. A test case starts from the row with something in this column and continues to the next
test case name or to the end of the table. It is an error to have something between the table headers and the first test.
The second column normally has keyword names. An exception to this rule is setting variables from keyword return values, when the second and
possibly also the subsequent columns contain variable names and a keyword name is located after them. In either case, columns after the keyword name
contain possible arguments to the specified keyword.
*** Test Cases ***
Valid Login
Open Login Page
Input Username
demo
Input Password
mode
Submit Credentials
Welcome Page Should Be Open
Setting Variables
Do Something
first argument
second argument
${value} =
Get Some Value
Should Be Equal
${value}
Expected value

Note
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

35/263

6/24/2018

Robot Framework User Guide

Although test case names can contain any character, using ? and especially * is not generally recommended because they are considered to be wildcards when
selecting test cases. For example, trying to run only a test with name Example * like --test 'Example *' will actually run any test starting with Example.

Settings in the Test Case table
Test cases can also have their own settings. Setting names are always in the second column, where keywords normally are, and their values are in the
subsequent columns. Setting names have square brackets around them to distinguish them from keywords. The available settings are listed below and
explained later in this section.
[Documentation]
Used for specifying a test case documentation.
[Tags]
Used for tagging test cases.
[Setup], [Teardown]
Specify test setup and teardown.
[Template]
Specifies the template keyword to use. The test itself will contain only data to use as arguments to that keyword.
[Timeout]
Used for setting a test case timeout. Timeouts are discussed in their own section.
Example test case with settings:
*** Test Cases ***
Test With Settings
[Documentation]
Another dummy test
[Tags]
dummy
owner-johndoe
Log
Hello, world!

Test case related settings in the Setting table
The Setting table can have the following test case related settings. These settings are mainly default values for the test case specific settings listed earlier.
Force Tags, Default Tags
The forced and default values for tags.
Test Setup, Test Teardown
The default values for test setup and teardown.
Test Template
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

36/263

6/24/2018

Robot Framework User Guide

The default template keyword to use.
Test Timeout
The default value for test case timeout. Timeouts are discussed in their own section.

2.2.2 Using arguments
The earlier examples have already demonstrated keywords taking different arguments, and this section discusses this important functionality more
thoroughly. How to actually implement user keywords and library keywords with different arguments is discussed in separate sections.
Keywords can accept zero or more arguments, and some arguments may have default values. What arguments a keyword accepts depends on its
implementation, and typically the best place to search this information is keyword's documentation. In the examples in this section the documentation is
expected to be generated using the Libdoc tool, but the same information is available on documentation generated by generic documentation tools such
as javadoc.

Mandatory arguments
Most keywords have a certain number of arguments that must always be given. In the keyword documentation this is denoted by specifying the argument
names separated with a comma like first, second, third. The argument names actually do not matter in this case, except that they should explain
what the argument does, but it is important to have exactly the same number of arguments as specified in the documentation. Using too few or too many
arguments will result in an error.
The test below uses keywords Create Directory and Copy File from the OperatingSystem library. Their arguments are specified as path and source,
destination, which means that they take one and two arguments, respectively. The last keyword, No Operation from BuiltIn, takes no arguments.
*** Test Cases ***
Example
Create Directory
${TEMPDIR}/stuff
Copy File
${CURDIR}/file.txt
${TEMPDIR}/stuff
No Operation

Default values
Arguments often have default values which can either be given or not. In the documentation the default value is typically separated from the argument
name with an equal sign like name=default value, but with keywords implemented using Java there may be multiple implementations of the same
keyword with different arguments instead. It is possible that all the arguments have default values, but there cannot be any positional arguments after
arguments with default values.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

37/263

6/24/2018

Robot Framework User Guide

Using default values is illustrated by the example below that uses Create File keyword which has arguments path, content=, encoding=UTF-8.
Trying to use it without any arguments or more than three arguments would not work.
*** Test Cases ***
Example
Create File
${TEMPDIR}/empty.txt
Create File
${TEMPDIR}/utf-8.txt
Create File
${TEMPDIR}/iso-8859-1.txt

Hyvä esimerkki
Hyvä esimerkki

ISO-8859-1

Variable number of arguments
It is also possible that a keyword accepts any number of arguments. These so called varargs can be combined with mandatory arguments and arguments
with default values, but they are always given after them. In the documentation they have an asterisk before the argument name like *varargs.
For example, Remove Files and Join Paths keywords from the OperatingSystem library have arguments *paths and base, *parts, respectively. The
former can be used with any number of arguments, but the latter requires at least one argument.
*** Test Cases ***
Example
Remove Files
${TEMPDIR}/f1.txt
${TEMPDIR}/f2.txt
${TEMPDIR}/f3.txt
@{paths} =
Join Paths
${TEMPDIR}
f1.txt
f2.txt
f3.txt
f4.txt

Named arguments
The named argument syntax makes using arguments with default values more flexible, and allows explicitly labeling what a certain argument value
means. Technically named arguments work exactly like keyword arguments in Python.
Basic syntax
It is possible to name an argument given to a keyword by prefixing the value with the name of the argument like arg=value. This is especially useful
when multiple arguments have default values, as it is possible to name only some the arguments and let others use their defaults. For example, if a
keyword accepts arguments arg1=a, arg2=b, arg3=c, and it is called with one argument arg3=override, arguments arg1 and arg2 get their default
values, but arg3 gets value override. If this sounds complicated, the named arguments example below hopefully makes it more clear.
The named argument syntax is both case and space sensitive. The former means that if you have an argument arg, you must use it like arg=value, and
neither Arg=value nor ARG=value works. The latter means that spaces are not allowed before the = sign, and possible spaces after it are considered part
of the given value.
When the named argument syntax is used with user keywords, the argument names must be given without the ${} decoration. For example, user
keyword with arguments ${arg1}=first, ${arg2}=second must be used like arg2=override.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

38/263

6/24/2018

Robot Framework User Guide

Using normal positional arguments after named arguments like, for example, | Keyword | arg=value | positional |, does not work. Starting from
Robot Framework 2.8 this causes an explicit error. The relative order of the named arguments does not matter.
Note
Prior to Robot Framework 2.8 it was not possible to name arguments that did not have a default value.

Named arguments with variables
It is possible to use variables in both named argument names and values. If the value is a single scalar variable, it is passed to the keyword as-is. This
allows using any objects, not only strings, as values also when using the named argument syntax. For example, calling a keyword like arg=${object}
will pass the variable ${object} to the keyword without converting it to a string.
If variables are used in named argument names, variables are resolved before matching them against argument names. This is a new feature in Robot
Framework 2.8.6.
The named argument syntax requires the equal sign to be written literally in the keyword call. This means that variable alone can never trigger the named
argument syntax, not even if it has a value like foo=bar. This is important to remember especially when wrapping keywords into other keywords. If, for
example, a keyword takes a variable number of arguments like @{args} and passes all of them to another keyword using the same @{args} syntax,
possible named=arg syntax used in the calling side is not recognized. This is illustrated by the example below.
*** Test Cases ***
Example
Run Program
shell=True

# This will not come as a named argument to Run Process

*** Keywords ***
Run Program
[Arguments]
Run Process

@{args}

@{args}
program.py

# Named arguments are not recognized from inside @{args}

If keyword needs to accept and pass forward any named arguments, it must be changed to accept free keyword arguments. See kwargs examples for a
wrapper keyword version that can pass both positional and named arguments forward.
Escaping named arguments syntax
The named argument syntax is used only when the part of the argument before the equal sign matches one of the keyword's arguments. It is possible that
there is a positional argument with a literal value like foo=quux, and also an unrelated argument with name foo. In this case the argument foo either
incorrectly gets the value quux or, more likely, there is a syntax error.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

39/263

6/24/2018

Robot Framework User Guide

In these rare cases where there are accidental matches, it is possible to use the backslash character to escape the syntax like foo\=quux. Now the
argument will get a literal value foo=quux. Note that escaping is not needed if there are no arguments with name foo, but because it makes the situation
more explicit, it may nevertheless be a good idea.
Where named arguments are supported
As already explained, the named argument syntax works with keywords. In addition to that, it also works when importing libraries.
Naming arguments is supported by user keywords and by most test libraries. The only exception are Java based libraries that use the static library API.
Library documentation generated with Libdoc has a note does the library support named arguments or not.
Note
Prior to Robot Framework 2.8 named argument syntax did not work with test libraries using the dynamic library API.

Named arguments example
The following example demonstrates using the named arguments syntax with library keywords, user keywords, and when importing the Telnet test
library.
*** Settings ***
Library
Telnet
*** Test
Example
Open
List
List

prompt=$

default_log_level=DEBUG

Cases ***
connection
10.0.0.42
port=${PORT}
files
options=-lh
files
path=/tmp
options=-l

alias=example

*** Keywords ***
List files
[Arguments]
${path}=.
${options}=
Execute command
ls ${options} ${path}

Free keyword arguments
Robot Framework 2.8 added support for Python style free keyword arguments (**kwargs). What this means is that keywords can receive all arguments
that use the name=value syntax and do not match any other arguments as kwargs.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

40/263

6/24/2018

Robot Framework User Guide

Free keyword arguments support variables similarly as named arguments. In practice that means that variables can be used both in names and values, but
the escape sign must always be visible literally. For example, both foo=${bar} and ${foo}=${bar} are valid, as long as the variables that are used exist.
An extra limitation is that free keyword argument names must always be strings. Support for variables in names is a new feature in Robot Framework
2.8.6, prior to that possible variables were left un-resolved.
Initially free keyword arguments only worked with Python based libraries, but Robot Framework 2.8.2 extended the support to the dynamic library API
and Robot Framework 2.8.3 extended it further to Java based libraries and to the remote library interface. Finally, user keywords got kwargs support in
Robot Framework 2.9. In other words, all keywords can nowadays support kwargs.
Kwargs examples
As the first example of using kwargs, let's take a look at Run Process keyword in the Process library. It has a signature command, *arguments,
**configuration, which means that it takes the command to execute (command), its arguments as variable number of arguments (*arguments) and
finally optional configuration parameters as free keyword arguments (**configuration). The example below also shows that variables work with free
keyword arguments exactly like when using the named argument syntax.
*** Test Cases ***
Using Kwargs
Run Process
program.py
Run Process
program.py

arg1
arg2
cwd=/home/user
argument
shell=True
env=${ENVIRON}

See Free keyword arguments (**kwargs) section under Creating test libraries for more information about using the kwargs syntax in your custom test
libraries.
As the second example, let's create a wrapper user keyword for running the program.py in the above example. The wrapper keyword Run Program
accepts any number of arguments and kwargs, and passes them forward for Run Process along with the name of the command to execute.
*** Test Cases ***
Using Kwargs
Run Program
arg1
arg2
cwd=/home/user
Run Program
argument
shell=True
env=${ENVIRON}
*** Keywords ***
Run Program
[Arguments]
Run Process

@{arguments}
program.py

&{configuration}
@{arguments}
&{configuration}

Arguments embedded to keyword names
A totally different approach to specify arguments is embedding them into keyword names. This syntax is supported by both test library keywords and
user keywords.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

41/263

6/24/2018

Robot Framework User Guide

2.2.3 Failures
When test case fails
A test case fails if any of the keyword it uses fails. Normally this means that execution of that test case is stopped, possible test teardown is executed, and
then execution continues from the next test case. It is also possible to use special continuable failures if stopping test execution is not desired.

Error messages
The error message assigned to a failed test case is got directly from the failed keyword. Often the error message is created by the keyword itself, but some
keywords allow configuring them.
In some circumstances, for example when continuable failures are used, a test case can fail multiple times. In that case the final error message is got by
combining the individual errors. Very long error messages are automatically cut from the middle to keep reports easier to read. Full error messages are
always visible in log file as a message of the failed keyword.
By default error messages are normal text, but starting from Robot Framework 2.8 they can contain HTML formatting. This is enabled by starting the
error message with marker string *HTML*. This marker will be removed from the final error message shown in reports and logs. Using HTML in a
custom message is shown in the second example below.
*** Test Cases ***
Normal Error
Fail
This is a rather boring example...
HTML Error
${number} =
Get Number
Should Be Equal
${number}

42

*HTML* Number is not my MAGIC number.

2.2.4 Test case name and documentation
The test case name comes directly from the Test Case table: it is exactly what is entered into the test case column. Test cases in one test suite should have
unique names. Pertaining to this, you can also use the automatic variable ${TEST_NAME} within the test itself to refer to the test name. It is available
whenever a test is being executed, including all user keywords, as well as the test setup and the test teardown.
The [Documentation] setting allows you to set a free documentation for a test case. That text is shown in the command line output, as well as the
resulting test logs and test reports. It is possible to use simple HTML formatting in documentation and variables can be used to make the documentation
dynamic.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

42/263

6/24/2018

Robot Framework User Guide

If documentation is split into multiple columns, cells in one row are concatenated together with spaces. This is mainly be useful when using the HTML
format and columns are narrow. If documentation is split into multiple rows, the created documentation lines themselves are concatenated using newlines.
Newlines are not added if a line already ends with a newline or an escaping backslash.
*** Test Cases ***
Simple
[Documentation]
No Operation

Simple documentation

Formatting
[Documentation]
No Operation

*This is bold*, _this is italic_

Variables
[Documentation]
No Operation

Executed at ${HOST} by ${USER}

Splitting
[Documentation]
No Operation

This documentation

Many lines
[Documentation]
...
No Operation

Here we have
an automatic newline

is split

and here is a link: http://robotframework.org

into multiple columns

It is important that test cases have clear and descriptive names, and in that case they normally do not need any documentation. If the logic of the test case
needs documenting, it is often a sign that keywords in the test case need better names and they are to be enhanced, instead of adding extra
documentation. Finally, metadata, such as the environment and user information in the last example above, is often better specified using tags.

2.2.5 Tagging test cases
Using tags in Robot Framework is a simple, yet powerful mechanism for classifying test cases. Tags are free text and they can be used at least for the
following purposes:
Tags are shown in test reports, logs and, of course, in the test data, so they provide metadata to test cases.
Statistics about test cases (total, passed, failed are automatically collected based on tags).
With tags, you can include or exclude test cases to be executed.
With tags, you can specify which test cases are considered critical.
In this section it is only explained how to set tags for test cases, and different ways to do it are listed below. These approaches can naturally be used
together.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

43/263

6/24/2018

Robot Framework User Guide

Force Tags in the Setting table
All test cases in a test case file with this setting always get specified tags. If it is used in the test suite initialization file, all test cases in
sub test suites get these tags.
Default Tags in the Setting table
Test cases that do not have a [Tags] setting of their own get these tags. Default tags are not supported in test suite initialization files.
[Tags] in the Test Case table
A test case always gets these tags. Additionally, it does not get the possible tags specified with Default Tags, so it is possible to override the
Default Tags by using empty value. It is also possible to use value NONE to override default tags.
command line option
All executed test cases get tags set with this option in addition to tags they got elsewhere.

--settag

Set Tags, Remove Tags, Fail and Pass Execution keywords
These BuiltIn keywords can be used to manipulate tags dynamically during the test execution.
Tags are free text, but they are normalized so that they are converted to lowercase and all spaces are removed. If a test case gets the same tag several
times, other occurrences than the first one are removed. Tags can be created using variables, assuming that those variables exist.
*** Settings ***
Force Tags
req-42
Default Tags
owner-john

smoke

*** Variables ***
${HOST}
10.0.1.42
*** Test Cases ***
No own tags
[Documentation]
No Operation

This test has tags owner-john, smoke and req-42.

With own tags
[Documentation]
This test has tags not_ready, owner-mrx and req-42.
[Tags]
owner-mrx
not_ready
No Operation
Own tags with variables
[Documentation]
This test has tags host-10.0.1.42 and req-42.
[Tags]
host-${HOST}
No Operation
Empty own tags
[Documentation]
[Tags]
No Operation

This test has only tag req-42.

Set Tags and Remove Tags Keywords
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

44/263

6/24/2018

Robot Framework User Guide

[Documentation]
This test has tags mytag and owner-john.
Set Tags
mytag
Remove Tags
smoke
req-*

Reserved tags
Users are generally free to use whatever tags that work in their context. There are, however, certain tags that have a predefined meaning for Robot
Framework itself, and using them for other purposes can have unexpected results. All special tags Robot Framework has and will have in the future have
either robot- or robot: prefix. To avoid problems, users should thus not use any tag with these prefixes unless actually activating the special
functionality.
At the time of writing, the only special tags are robot-exit, that is automatically added to tests when stopping test execution gracefully, and robot:nodry-run, that can be used to disable the dry run mode. More usages are likely to be added in the future.
Note
The plan is to unify reserved prefixes in the future. Most likely the robot: prefix will be used with all reserved tags, but it best to avoid both of these
prefixes at the moment. See issue #2539 for details.

2.2.6 Test setup and teardown
Robot Framework has similar test setup and teardown functionality as many other test automation frameworks. In short, a test setup is something that is
executed before a test case, and a test teardown is executed after a test case. In Robot Framework setups and teardowns are just normal keywords with
possible arguments.
Setup and teardown are always a single keyword. If they need to take care of multiple separate tasks, it is possible to create higher-level user keywords
for that purpose. An alternative solution is executing multiple keywords using the BuiltIn keyword Run Keywords.
The test teardown is special in two ways. First of all, it is executed also when a test case fails, so it can be used for clean-up activities that must be done
regardless of the test case status. In addition, all the keywords in the teardown are also executed even if one of them fails. This continue on failure
functionality can be used also with normal keywords, but inside teardowns it is on by default.
The easiest way to specify a setup or a teardown for test cases in a test case file is using the Test Setup and Test Teardown settings in the Setting table.
Individual test cases can also have their own setup or teardown. They are defined with the [Setup] or [Teardown] settings in the test case table and they
override possible Test Setup and Test Teardown settings. Having no keyword after a [Setup] or [Teardown] setting means having no setup or teardown. It
is also possible to use value NONE to indicate that a test has no setup/teardown.
*** Settings ***
Test Setup
Open Application

App A

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

45/263

6/24/2018

Test Teardown

Robot Framework User Guide

Close Application

*** Test Cases ***
Default values
[Documentation]
Do Something

Setup and teardown from setting table

Overridden setup
[Documentation]
Own setup, teardown from setting table
[Setup]
Open Application
App B
Do Something
No teardown
[Documentation]
Do Something
[Teardown]

Default setup, no teardown at all

No teardown 2
[Documentation]
Setup and teardown can be disabled also with special value NONE
Do Something
[Teardown]
NONE
Using variables
[Documentation]
Setup and teardown specified using variables
[Setup]
${SETUP}
Do Something
[Teardown]
${TEARDOWN}

The name of the keyword to be executed as a setup or a teardown can be a variable. This facilitates having different setups or teardowns in different
environments by giving the keyword name as a variable from the command line.
Note
Test suites can have a setup and teardown of their own. A suite setup is executed before any test cases or sub test suites in that test suite, and similarly a suite
teardown is executed after them.

2.2.7 Test templates
Test templates convert normal keyword-driven test cases into data-driven tests. Whereas the body of a keyword-driven test case is constructed from
keywords and their possible arguments, test cases with template contain only the arguments for the template keyword. Instead of repeating the same
keyword multiple times per test and/or with all tests in a file, it is possible to use it only per test or just once per file.
Template keywords can accept both normal positional and named arguments, as well as arguments embedded to the keyword name. Unlike with other
settings, it is not possible to define a template using a variable.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

46/263

6/24/2018

Robot Framework User Guide

Basic usage
How a keyword accepting normal positional arguments can be used as a template is illustrated by the following example test cases. These two tests are
functionally fully identical.
*** Test Cases **
Normal test case
Example keyword

first argument

second argument

Templated test case
[Template]
Example keyword
first argument
second argument

As the example illustrates, it is possible to specify the template for an individual test case using the [Template] setting. An alternative approach is using
the Test Template setting in the Setting table, in which case the template is applied for all test cases in that test case file. The [Template] setting overrides
the possible template set in the Setting table, and an empty value for [Template] means that the test has no template even when Test Template is used. It is
also possible to use value NONE to indicate that a test has no template.
If a templated test case has multiple data rows in its body, the template is applied for all the rows one by one. This means that the same keyword is
executed multiple times, once with data on each row. Templated tests are also special so that all the rounds are executed even if one or more of them fails.
It is possible to use this kind of continue on failure mode with normal tests too, but with the templated tests the mode is on automatically.
*** Settings ***
Test Template
Example keyword
*** Test Cases ***
Templated test case
first round 1
second round 1
third round 1

first round 2
second round 2
third round 2

Using arguments with default values or varargs, as well as using named arguments and free keyword arguments, work with templates exactly like they
work otherwise. Using variables in arguments is also supported normally.

Templates with embedded arguments
Starting from Robot Framework 2.8.2, templates support a variation of the embedded argument syntax. With templates this syntax works so that if the
template keyword has variables in its name, they are considered placeholders for arguments and replaced with the actual arguments used with the
template. The resulting keyword is then used without positional arguments. This is best illustrated with an example:
*** Test Cases ***
Normal test case with embedded arguments
The result of 1 + 1 should be 2
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

47/263

6/24/2018

Robot Framework User Guide

The result of 1 + 2 should be 3
Template with embedded arguments
[Template]
The result of ${calculation} should be ${expected}
1 + 1
2
1 + 2
3
*** Keywords ***
The result of ${calculation} should be ${expected}
${result} =
Calculate
${calculation}
Should Be Equal
${result}
${expected}

When embedded arguments are used with templates, the number of arguments in the template keyword name must match the number of arguments it is
used with. The argument names do not need to match the arguments of the original keyword, though, and it is also possible to use different arguments
altogether:
*** Test Cases ***
Different argument names
[Template]
The result of ${foo} should be ${bar}
1 + 1
2
1 + 2
3
Only some arguments
[Template]
The result of ${calculation} should be 3
1 + 2
4 - 1
New arguments
[Template]
The ${meaning} of ${life} should be 42
result
21 * 2

The main benefit of using embedded arguments with templates is that argument names are specified explicitly. When using normal arguments, the same
effect can be achieved by naming the columns that contain arguments. This is illustrated by the data-driven style example in the next section.

Templates with for loops
If templates are used with for loops, the template is applied for all the steps inside the loop. The continue on failure mode is in use also in this case, which
means that all the steps are executed with all the looped elements even if there are failures.
*** Test Cases ***
Template and for
[Template]
Example keyword
:FOR
${item}
IN
@{ITEMS}
\
${item}
2nd arg
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

48/263

6/24/2018

Robot Framework User Guide

:FOR
${index}
IN RANGE
\
1st arg
${index}

42

2.2.8 Different test case styles
There are several different ways in which test cases may be written. Test cases that describe some kind of workflow may be written either in keyworddriven or behavior-driven style. Data-driven style can be used to test the same workflow with varying input data.

Keyword-driven style
Workflow tests, such as the Valid Login test described earlier, are constructed from several keywords and their possible arguments. Their normal structure
is that first the system is taken into the initial state (Open Login Page in the Valid Login example), then something is done to the system (Input Name,
Input Password, Submit Credentials), and finally it is verified that the system behaved as expected (Welcome Page Should Be Open).

Data-driven style
Another style to write test cases is the data-driven approach where test cases use only one higher-level keyword, normally created as a user keyword,
that hides the actual test workflow. These tests are very useful when there is a need to test the same scenario with different input and/or output data. It
would be possible to repeat the same keyword with every test, but the test template functionality allows specifying the keyword to use only once.
*** Settings ***
Test Template
Login with invalid credentials should fail
*** Test Cases ***
Invalid User Name
Invalid Password
Invalid User Name and Password
Empty User Name
Empty Password
Empty User Name and Password

USERNAME
invalid
${VALID USER}
invalid
${EMPTY}
${VALID USER}
${EMPTY}

PASSWORD
${VALID PASSWORD}
invalid
invalid
${VALID PASSWORD}
${EMPTY}
${EMPTY}

Tip
Naming columns like in the example above makes tests easier to understand. This is possible because on the header row other cells except the first one are
ignored.

The above example has six separate tests, one for each invalid user/password combination, and the example below illustrates how to have only one test
with all the combinations. When using test templates, all the rounds in a test are executed even if there are failures, so there is no real functional
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

49/263

6/24/2018

Robot Framework User Guide

difference between these two styles. In the above example separate combinations are named so it is easier to see what they test, but having potentially
large number of these tests may mess-up statistics. Which style to use depends on the context and personal preferences.
*** Test Cases ***
Invalid Password
[Template]
Login with invalid credentials should fail
invalid
${VALID PASSWORD}
${VALID USER}
invalid
invalid
whatever
${EMPTY}
${VALID PASSWORD}
${VALID USER}
${EMPTY}
${EMPTY}
${EMPTY}

Behavior-driven style
It is also possible to write test cases as requirements that also non-technical project stakeholders must understand. These executable requirements are a
corner stone of a process commonly called Acceptance Test Driven Development (ATDD) or Specification by Example.
One way to write these requirements/tests is Given-When-Then style popularized by Behavior Driven Development (BDD). When writing test cases in
this style, the initial state is usually expressed with a keyword starting with word Given, the actions are described with keyword starting with When and
the expectations with a keyword starting with Then. Keyword starting with And or But may be used if a step has more than one action.
*** Test Cases ***
Valid Login
Given login page is open
When valid username and password are inserted
and credentials are submitted
Then welcome page should be open

Ignoring Given/When/Then/And/But prefixes
Prefixes Given, When, Then, And and But are dropped when matching keywords are searched, if no match with the full name is found. This works for
both user keywords and library keywords. For example, Given login page is open in the above example can be implemented as user keyword either with
or without the word Given. Ignoring prefixes also allows using the same keyword with different prefixes. For example Welcome page should be open
could also used as And welcome page should be open.
Note
Ignoring But prefix is new in Robot Framework 2.8.7.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

50/263

6/24/2018

Robot Framework User Guide

Embedding data to keywords
When writing concrete examples it is useful to be able pass actual data to keyword implementations. User keywords support this by allowing embedding
arguments into keyword name.

2.3 Creating test suites
Robot Framework test cases are created in test case files, which can be organized into directories. These files and directories create a hierarchical test
suite structure.
2.3.1 Test case files
2.3.2 Test suite directories
Warning on invalid files
Initialization files
2.3.3 Test suite name and documentation
2.3.4 Free test suite metadata
2.3.5 Suite setup and teardown

2.3.1 Test case files
Robot Framework test cases are created using test case tables in test case files. Such a file automatically creates a test suite from all the test cases it
contains. There is no upper limit for how many test cases there can be, but it is recommended to have less than ten, unless the data-driven approach is
used, where one test case consists of only one high-level keyword.
The following settings in the Setting table can be used to customize the test suite:
Documentation
Used for specifying a test suite documentation
Metadata
Used for setting free test suite metadata as name-value pairs.
Suite Setup, Suite Teardown
Specify suite setup and teardown.
Note

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

51/263

6/24/2018

Robot Framework User Guide

All setting names can optionally include a colon at the end, for example Documentation:. This can make reading the settings easier especially when using the
plain text format.

2.3.2 Test suite directories
Test case files can be organized into directories, and these directories create higher-level test suites. A test suite created from a directory cannot have any
test cases directly, but it contains other test suites with test cases, instead. These directories can then be placed into other directories creating an even
higher-level suite. There are no limits for the structure, so test cases can be organized as needed.
When a test directory is executed, the files and directories it contains are processed recursively as follows:
Files and directories with names starting with a dot (.) or an underscore (_) are ignored.
Directories with the name CVS are ignored (case-sensitive).
Files not having one of the recognized extensions (.html, .xhtml, .htm, .tsv, .txt, .rst, .rest or .robot) are ignored (case-insensitive).
Other files and directories are processed.
If a file or directory that is processed does not contain any test cases, it is silently ignored (a message is written to the syslog) and the processing
continues.

Warning on invalid files
Normally files that do not have a valid test case table are silently ignored with a message written to the syslog. It is possible to use a command line option
--warnonskippedfiles, which turns the message into a warning shown in test execution errors.

Initialization files
A test suite created from a directory can have similar settings as a suite created from a test case file. Because a directory alone cannot have that kind of
information, it must be placed into a special test suite initialization file. An initialization file name must always be of the format __init__.ext, where the
extension must be one of the supported file formats (for example, __init__.robot or __init__.html). The name format is borrowed from Python, where
files named in this manner denote that a directory is a module.
Initialization files have the same structure and syntax as test case files, except that they cannot have test case tables and not all settings are supported.
Variables and keywords created or imported in initialization files are not available in the lower level test suites. If you need to share variables or
keywords, you can put them into resource files that can be imported both by initialization and test case files.
The main usage for initialization files is specifying test suite related settings similarly as in test case files, but setting some test case related settings is also
possible. How to use different settings in the initialization files is explained below.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

52/263

6/24/2018

Robot Framework User Guide

Documentation, Metadata, Suite Setup, Suite Teardown
These test suite specific settings work the same way as in test case files.
Force Tags
Specified tags are unconditionally set to all test cases in all test case files this directory contains directly or recursively.
Test Setup, Test Teardown, Test Timeout
Set the default value for test setup/teardown or test timeout to all test cases this directory contains. Can be overridden on lower level. Support for
defining test timeout in initialization files was added in Robot Framework 2.7.
Default Tags, Test Template
Not supported in initialization files.
*** Settings ***
Documentation
Suite Setup
Force Tags
Library

Example suite
Do Something
example
SomeLibrary

${MESSAGE}

*** Variables ***
${MESSAGE}
Hello, world!
*** Keywords ***
Do Something
[Arguments]
${args}
Some Keyword
${arg}
Another Keyword

2.3.3 Test suite name and documentation
The test suite name is constructed from the file or directory name. The name is created so that the extension is ignored, possible underscores are replaced
with spaces, and names fully in lower case are title cased. For example, some_tests.html becomes Some Tests and My_test_directory becomes My test
directory.
The file or directory name can contain a prefix to control the execution order of the suites. The prefix is separated from the base name by two
underscores and, when constructing the actual test suite name, both the prefix and underscores are removed. For example files 01__some_tests.txt and
02__more_tests.txt create test suites Some Tests and More Tests, respectively, and the former is executed before the latter.
The documentation for a test suite is set using the Documentation setting in the Setting table. It can be used in test case files or, with higher-level suites,
in test suite initialization files. Test suite documentation has exactly the same characteristics regarding to where it is shown and how it can be created as
test case documentation.
*** Settings ***
Documentation
An example test suite documentation with *some* _formatting_.
...
See test documentation for more documentation examples.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

53/263

6/24/2018

Robot Framework User Guide

Both the name and documentation of the top-level test suite can be overridden in test execution. This can be done with the command line options --name
and --doc, respectively, as explained in section Setting metadata.

2.3.4 Free test suite metadata
Test suites can also have other metadata than the documentation. This metadata is defined in the Setting table using the Metadata setting. Metadata set in
this manner is shown in test reports and logs.
The name and value for the metadata are located in the columns following Metadata. The value is handled similarly as documentation, which means that
it can be split into several cells (joined together with spaces) or into several rows (joined together with newlines), simple HTML formatting works and
even variables can be used.
*** Settings ***
Metadata
Version
Metadata
More Info
Metadata
Executed At

2.0
For more information about *Robot Framework* see http://robotframework.org
${HOST}

For top-level test suites, it is possible to set metadata also with the --metadata command line option. This is discussed in more detail in section Setting
metadata.

2.3.5 Suite setup and teardown
Not only test cases but also test suites can have a setup and a teardown. A suite setup is executed before running any of the suite's test cases or child test
suites, and a test teardown is executed after them. All test suites can have a setup and a teardown; with suites created from a directory they must be
specified in a test suite initialization file.
Similarly as with test cases, a suite setup and teardown are keywords that may take arguments. They are defined in the Setting table with Suite Setup and
Suite Teardown settings, respectively. Keyword names and possible arguments are located in the columns after the setting name.
If a suite setup fails, all test cases in it and its child test suites are immediately assigned a fail status and they are not actually executed. This makes suite
setups ideal for checking preconditions that must be met before running test cases is possible.
A suite teardown is normally used for cleaning up after all the test cases have been executed. It is executed even if the setup of the same suite fails. If the
suite teardown fails, all test cases in the suite are marked failed, regardless of their original execution status. Note that all the keywords in suite teardowns
are executed even if one of them fails.
The name of the keyword to be executed as a setup or a teardown can be a variable. This facilitates having different setups or teardowns in different
environments by giving the keyword name as a variable from the command line.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

54/263

6/24/2018

Robot Framework User Guide

2.4 Using test libraries
Test libraries contain those lowest-level keywords, often called library keywords, which actually interact with the system under test. All test cases always
use keywords from some library, often through higher-level user keywords. This section explains how to take test libraries into use and how to use the
keywords they provide. Creating test libraries is described in a separate section.
2.4.1 Importing libraries
Using Library setting
Using Import Library keyword
2.4.2 Specifying library to import
Using library name
Using physical path to library
2.4.3 Setting custom name to test library
2.4.4 Standard libraries
Normal standard libraries
Remote library
2.4.5 External libraries

2.4.1 Importing libraries
Test libraries are typically imported using the Library setting, but it is also possible to use the Import Library keyword.

Using Library setting
Test libraries are normally imported using the Library setting in the Setting table and having the library name in the subsequent column. Unlike most of
the other data, the library name is both case- and space-sensitive. If a library is in a package, the full name including the package name must be used.
In those cases where the library needs arguments, they are listed in the columns after the library name. It is possible to use default values, variable number
of arguments, and named arguments in test library imports similarly as with arguments to keywords. Both the library name and arguments can be set
using variables.
*** Settings ***
Library
OperatingSystem
Library
my.package.TestLibrary
Library
MyLibrary
arg1
arg2
Library
${LIBRARY}

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

55/263

6/24/2018

Robot Framework User Guide

It is possible to import test libraries in test case files, resource files and test suite initialization files. In all these cases, all the keywords in the imported
library are available in that file. With resource files, those keywords are also available in other files using them.

Using Import Library keyword
Another possibility to take a test library into use is using the keyword Import Library from the BuiltIn library. This keyword takes the library name and
possible arguments similarly as the Library setting. Keywords from the imported library are available in the test suite where the Import Library keyword
was used. This approach is useful in cases where the library is not available when the test execution starts and only some other keywords make it
available.
*** Test Cases ***
Example
Do Something
Import Library
MyLibrary
KW From MyLibrary

arg1

arg2

2.4.2 Specifying library to import
Libraries to import can be specified either by using the library name or the path to the library. These approaches work the same way regardless is the
library imported using the Library setting or the Import Library keyword.

Using library name
The most common way to specify a test library to import is using its name, like it has been done in all the examples in this section. In these cases Robot
Framework tries to find the class or module implementing the library from the module search path. Libraries that are installed somehow ought to be in the
module search path automatically, but with other libraries the search path may need to be configured separately.
The biggest benefit of this approach is that when the module search path has been configured, often using a custom start-up script, normal users do not
need to think where libraries actually are installed. The drawback is that getting your own, possible very simple, libraries into the search path may require
some additional configuration.

Using physical path to library
Another mechanism for specifying the library to import is using a path to it in the file system. This path is considered relative to the directory where
current test data file is situated similarly as paths to resource and variable files. The main benefit of this approach is that there is no need to configure the
module search path.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

56/263

6/24/2018

Robot Framework User Guide

If the library is a file, the path to it must contain extension. For Python libraries the extension is naturally .py and for Java libraries it can either be .class or
.java, but the class file must always be available. If Python library is implemented as a directory, the path to it must have a trailing forward slash (/).
Following examples demonstrate these different usages.
*** Settings ***
Library
PythonLibrary.py
Library
/absolute/path/JavaLibrary.java
Library
relative/path/PythonDirLib/
possible
Library
${RESOURCES}/Example.class

arguments

A limitation of this approach is that libraries implemented as Python classes must be in a module with the same name as the class. Additionally, importing
libraries distributed in JAR or ZIP packages is not possible with this mechanism.

2.4.3 Setting custom name to test library
The library name is shown in test logs before keyword names, and if multiple keywords have the same name, they must be used so that the keyword
name is prefixed with the library name. The library name is got normally from the module or class name implementing it, but there are some situations
where changing it is desirable:
There is a need to import the same library several times with different arguments. This is not possible otherwise.
The library name is inconveniently long. This can happen, for example, if a Java library has a long package name.
You want to use variables to import different libraries in different environments, but refer to them with the same name.
The library name is misleading or otherwise poor. In this case, changing the actual name is, of course, a better solution.
The basic syntax for specifying the new name is having the text WITH NAME (case-sensitive) after the library name and then having the new name in the
next cell. The specified name is shown in logs and must be used in the test data when using keywords' full name (LibraryName.Keyword Name).
*** Settings ***
Library
com.company.TestLib
Library
${LIBRARY}

WITH NAME
WITH NAME

TestLib
MyName

Possible arguments to the library are placed into cells between the original library name and the WITH NAME text. The following example illustrates how
the same library can be imported several times with different arguments:
*** Settings ***
Library
SomeLibrary
Library
SomeLibrary
*** Test Cases ***
My Test
LocalLib.Some Keyword

localhost
server.domain

some arg

1234
8080

WITH NAME
WITH NAME

LocalLib
RemoteLib

second arg

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

57/263

6/24/2018

Robot Framework User Guide

RemoteLib.Some Keyword
LocalLib.Another Keyword

another arg

whatever

Setting a custom name to a test library works both when importing a library in the Setting table and when using the Import Library keyword.

2.4.4 Standard libraries
Some test libraries are distributed with Robot Framework and these libraries are called standard libraries. The BuiltIn library is special, because it is
taken into use automatically and thus its keywords are always available. Other standard libraries need to be imported in the same way as any other
libraries, but there is no need to install them.

Normal standard libraries
The available normal standard libraries are listed below with links to their documentations:
BuiltIn
Collections
DateTime
Dialogs
OperatingSystem
Process
Screenshot
String
Telnet
XML

Remote library
In addition to the normal standard libraries listed above, there is also Remote library that is totally different than the other standard libraries. It does not
have any keywords of its own but it works as a proxy between Robot Framework and actual test library implementations. These libraries can be running
on other machines than the core framework and can even be implemented using languages not supported by Robot Framework natively.
See separate Remote library interface section for more information about this concept.

2.4.5 External libraries
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

58/263

6/24/2018

Robot Framework User Guide

Any test library that is not one of the standard libraries is, by definition, an external library. The Robot Framework open source community has
implemented several generic libraries, such as SeleniumLibrary and SwingLibrary, which are not packaged with the core framework. A list of publicly
available libraries can be found from http://robotframework.org.
Generic and custom libraries can obviously also be implemented by teams using Robot Framework. See Creating test libraries section for more
information about that topic.
Different external libraries can have a totally different mechanism for installing them and taking them into use. Sometimes they may also require some
other dependencies to be installed separately. All libraries should have clear installation and usage documentation and they should preferably automate
the installation process.

2.5 Variables
2.5.1 Introduction
2.5.2 Variable types
Scalar variables
List variables
Dictionary variables
Environment variables
Java system properties
2.5.3 Creating variables
Variable table
Variable file
Setting variables in command line
Return values from keywords
Using Set Test/Suite/Global Variable keywords
2.5.4 Built-in variables
Operating-system variables
Number variables
Boolean and None/null variables
Space and empty variables
Automatic variables
2.5.5 Variable priorities and scopes
Variable priorities
Variable scopes
2.5.6 Advanced variable features
Extended variable syntax
Extended variable assignment
Variables inside variables
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

59/263

6/24/2018

Robot Framework User Guide

2.5.1 Introduction
Variables are an integral feature of Robot Framework, and they can be used in most places in test data. Most commonly, they are used in arguments for
keywords in test case tables and keyword tables, but also all settings allow variables in their values. A normal keyword name cannot be specified with a
variable, but the BuiltIn keyword Run Keyword can be used to get the same effect.
Robot Framework has its own variables that can be used as scalars, lists or dictionaries using syntax ${SCALAR}, @{LIST} and &{DICT}, respectively. In
addition to this, environment variables can be used directly with syntax %{ENV_VAR}.
Variables are useful, for example, in these cases:
When strings change often in the test data. With variables you only need to make these changes in one place.
When creating system-independent and operating-system-independent test data. Using variables instead of hard-coded strings eases that
considerably (for example, ${RESOURCES} instead of c:\resources, or ${HOST} instead of 10.0.0.1:8080). Because variables can be set from
the command line when tests are started, changing system-specific variables is easy (for example, --variable HOST:10.0.0.2:1234 -variable RESOURCES:/opt/resources). This also facilitates localization testing, which often involves running the same tests with different
strings.
When there is a need to have objects other than strings as arguments for keywords. This is not possible without variables.
When different keywords, even in different test libraries, need to communicate. You can assign a return value from one keyword to a variable and
pass it as an argument to another.
When values in the test data are long or otherwise complicated. For example, ${URL} is shorter than
http://long.domain.name:8080/path/to/service?foo=1&bar=2&zap=42.
If a non-existent variable is used in the test data, the keyword using it fails. If the same syntax that is used for variables is needed as a literal string, it must
be escaped with a backslash as in \${NAME}.

2.5.2 Variable types
Different variable types are explained in this section. How variables can be created is discussed in subsequent sections.
Robot Framework variables, similarly as keywords, are case-insensitive, and also spaces and underscores are ignored. However, it is recommended to
use capital letters with global variables (for example, ${PATH} or ${TWO WORDS}) and small letters with variables that are only available in certain test
cases or user keywords (for example, ${my var} or ${myVar}). Much more importantly, though, cases should be used consistently.
Variable name consists of the variable type identifier ($, @, &, %), curly braces ({, }) and actual variable name between the braces. Unlike in some
programming languages where similar variable syntax is used, curly braces are always mandatory. Variable names can basically have any characters
between the curly braces. However, using only alphabetic characters from a to z, numbers, underscore and space is recommended, and it is even a
requirement for using the extended variable syntax.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

60/263

6/24/2018

Robot Framework User Guide

Scalar variables
When scalar variables are used in the test data, they are replaced with the value they are assigned to. While scalar variables are most commonly used for
simple strings, you can assign any objects, including lists, to them. The scalar variable syntax, for example ${NAME}, should be familiar to most users, as
it is also used, for example, in shell scripts and Perl programming language.
The example below illustrates the usage of scalar variables. Assuming that the variables ${GREET} and ${NAME} are available and assigned to strings
Hello and world, respectively, both the example test cases are equivalent.
*** Test Cases ***
Constants
Log
Hello
Log
Hello, world!!
Variables
Log
Log

${GREET}
${GREET}, ${NAME}!!

When a scalar variable is used as the only value in a test data cell, the scalar variable is replaced with the value it has. The value may be any object.
When a scalar variable is used in a test data cell with anything else (constant strings or other variables), its value is first converted into a Unicode string
and then catenated to whatever is in that cell. Converting the value into a string means that the object's method __unicode__ (in Python, with __str__
as a fallback) or toString (in Java) is called.
Note
Variable values are used as-is without conversions also when passing arguments to keywords using the named arguments syntax like argname=${var}.

The example below demonstrates the difference between having a variable in a cell alone or with other content. First, let us assume that we have a
variable ${STR} set to a string Hello, world! and ${OBJ} set to an instance of the following Java object:
public class MyObj {

}

public String toString() {
return "Hi, tellus!";
}

With these two variables set, we then have the following test data:
*** Test Cases ***
Objects
KW 1
${STR}
KW 2
${OBJ}
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

61/263

6/24/2018

Robot Framework User Guide

KW 3
KW 4

I said "${STR}"
You said "${OBJ}"

Finally, when this test data is executed, different keywords receive the arguments as explained below:
KW 1 gets a string Hello, world!
KW 2 gets an object stored to variable ${OBJ}
KW 3 gets a string I said "Hello, world!"
KW 4 gets a string You said "Hi, tellus!"
Note
Converting variables to Unicode obviously fails if the variable cannot be represented as Unicode. This can happen, for example, if you try to use byte
sequences as arguments to keywords so that you catenate the values together like ${byte1}${byte2}. A workaround is creating a variable that contains the
whole value and using it alone in the cell (e.g. ${bytes}) because then the value is used as-is.

List variables
When a variable is used as a scalar like ${EXAMPLE}, its value will be used as-is. If a variable value is a list or list-like, it is also possible to use as a list
variable like @{EXAMPLE}. In this case individual list items are passed in as arguments separately. This is easiest to explain with an example. Assuming
that a variable @{USER} has value ['robot', 'secret'], the following two test cases are equivalent:
*** Test Cases ***
Constants
Login
robot

secret

List Variable
Login
@{USER}

Robot Framework stores its own variables in one internal storage and allows using them as scalars, lists or dictionaries. Using a variable as a list requires
its value to be a Python list or list-like object. Robot Framework does not allow strings to be used as lists, but other iterable objects such as tuples or
dictionaries are accepted.
Prior to Robot Framework 2.9, scalar and list variables were stored separately, but it was possible to use list variables as scalars and scalar variables as
lists. This caused lot of confusion when there accidentally was a scalar variable and a list variable with same name but different value.
Using list variables with other data
It is possible to use list variables with other arguments, including other list variables.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

62/263

6/24/2018

*** Test Cases
Example
Keyword
Keyword
Keyword

Robot Framework User Guide

***
@{LIST}
${SCALAR}
@{LIST}

more
args
@{LIST}
constant
@{ANOTHER}
@{ONE MORE}

If a list variable is used in a cell with other data (constant strings or other variables), the final value will contain a string representation of the variable
value. The end result is thus exactly the same as when using the variable as a scalar with other data in the same cell.
Accessing individual list items
It is possible to access a certain value of a list variable with the syntax @{NAME}[index], where index is the index of the selected value. Indices start
from zero, negative indices can be used to access items from the end, and trying to access a value with too large an index causes an error. Indices are
automatically converted to integers, and it is also possible to use variables as indices. List items accessed in this manner can be used similarly as scalar
variables.
*** Test Cases ***
List Variable Item
Login
@{USER}[0]
@{USER}[1]
Title Should Be
Welcome @{USER}[0]!
Negative Index
Log
@{LIST}[-1]
Index As Variable
Log
@{LIST}[${INDEX}]

Using list variables with settings
List variables can be used only with some of the settings. They can be used in arguments to imported libraries and variable files, but library and variable
file names themselves cannot be list variables. Also with setups and teardowns list variable can not be used as the name of the keyword, but can be used
in arguments. With tag related settings they can be used freely. Using scalar variables is possible in those places where list variables are not supported.
*** Settings ***
Library
ExampleLibrary
Library
${LIBRARY}
Library
@{NAME AND ARGS}
Suite Setup
Some Keyword
Suite Setup
${KEYWORD}
Suite Setup
@{KEYWORD}
Default Tags
@{TAGS}

@{LIB ARGS}
@{LIB ARGS}
@{KW ARGS}
@{KW ARGS}

#
#
#
#
#
#
#

This
This
This
This
This
This
This

works
works
does not work
works
works
does not work
works

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

63/263

6/24/2018

Robot Framework User Guide

Dictionary variables
As discussed above, a variable containing a list can be used as a list variable to pass list items to a keyword as individual arguments. Similarly a variable
containing a Python dictionary or a dictionary-like object can be used as a dictionary variable like &{EXAMPLE}. In practice this means that individual
items of the dictionary are passed as named arguments to the keyword. Assuming that a variable &{USER} has value {'name': 'robot', 'password':
'secret'}, the following two test cases are equivalent.
*** Test Cases ***
Constants
Login
name=robot

password=secret

Dict Variable
Login
&{USER}

Dictionary variables are new in Robot Framework 2.9.
Using dictionary variables with other data
It is possible to use dictionary variables with other arguments, including other dictionary variables. Because named argument syntax requires positional
arguments to be before named argument, dictionaries can only be followed by named arguments or other dictionaries.
*** Test Cases
Example
Keyword
Keyword
Keyword

***
&{DICT}
named=arg
positional
@{LIST}
&{DICT}
&{ANOTHER}

&{DICT}
&{ONE MORE}

If a dictionary variable is used in a cell with other data (constant strings or other variables), the final value will contain a string representation of the
variable value. The end result is thus exactly the same as when using the variable as a scalar with other data in the same cell.
Accessing individual dictionary items
It is possible to access a certain value of a dictionary variable with the syntax &{NAME}[key], where key is the name of the selected value. Keys are
considered to be strings, but non-strings keys can be used as variables. Dictionary values accessed in this manner can be used similarly as scalar
variables.
If a key is a string, it is possible to access its value also using attribute access syntax ${NAME.key}. See Creating dictionary variables for more details
about this syntax.
*** Test Cases ***
Dict Variable Item
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

64/263

6/24/2018

Robot Framework User Guide

Login
&{USER}[name]
&{USER}[password]
Title Should Be
Welcome &{USER}[name]!
Key As Variable
Log Many
&{DICT}[${KEY}]

&{DICT}[${42}]

Attribute Access
Login
${USER.name}
${USER.password}
Title Should Be
Welcome ${USER.name}!

Using dictionary variables with settings
Dictionary variables cannot generally be used with settings. The only exception are imports, setups and teardowns where dictionaries can be used as
arguments.
*** Settings ***
Library
ExampleLibrary
Suite Setup
Some Keyword

&{LIB ARGS}
&{KW ARGS}

named=arg

Environment variables
Robot Framework allows using environment variables in the test data using the syntax %{ENV_VAR_NAME}. They are limited to string values.
Environment variables set in the operating system before the test execution are available during it, and it is possible to create new ones with the keyword
Set Environment Variable or delete existing ones with the keyword Delete Environment Variable, both available in the OperatingSystem library. Because
environment variables are global, environment variables set in one test case can be used in other test cases executed after it. However, changes to
environment variables are not effective after the test execution.
*** Test Cases ***
Env Variables
Log
Current user: %{USER}
Run
%{JAVA_HOME}${/}javac

Java system properties
When running tests with Jython, it is possible to access Java system properties using same syntax as environment variables. If an environment variable
and a system property with same name exist, the environment variable will be used.
*** Test Cases ***
System Properties
Log
%{user.name} running tests on %{os.name}
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

65/263

6/24/2018

Robot Framework User Guide

2.5.3 Creating variables
Variables can spring into existence from different sources.

Variable table
The most common source for variables are Variable tables in test case files and resource files. Variable tables are convenient, because they allow creating
variables in the same place as the rest of the test data, and the needed syntax is very simple. Their main disadvantages are that values are always strings
and they cannot be created dynamically. If either of these is a problem, variable files can be used instead.
Creating scalar variables
The simplest possible variable assignment is setting a string into a scalar variable. This is done by giving the variable name (including ${}) in the first
column of the Variable table and the value in the second one. If the second column is empty, an empty string is set as a value. Also an already defined
variable can be used in the value.
*** Variables ***
${NAME}
Robot Framework
${VERSION}
2.0
${ROBOT}
${NAME} ${VERSION}

It is also possible, but not obligatory, to use the equals sign = after the variable name to make assigning variables slightly more explicit.
*** Variables ***
${NAME} =
Robot Framework
${VERSION} =
2.0

If a scalar variable has a long value, it can be split to multiple columns and rows. By default cells are catenated together using a space, but this can be
changed by having SEPARATOR= in the first cell.
*** Variables ***
${EXAMPLE}
This value is joined
together with a space
${MULTILINE}
SEPARATOR=\n
First line
...
Second line
Third line

Joining long values like above is a new feature in Robot Framework 2.9. Creating a scalar variable with multiple values was a syntax error in Robot
Framework 2.8 and with earlier versions it created a variable with a list value.
Creating list variables
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

66/263

6/24/2018

Robot Framework User Guide

Creating list variables is as easy as creating scalar variables. Again, the variable name is in the first column of the Variable table and values in the
subsequent columns. A list variable can have any number of values, starting from zero, and if many values are needed, they can be split into several
rows.
*** Variables ***
@{NAMES}
Matti
@{NAMES2}
@{NAMES}
@{NOTHING}
@{MANY}
one
...
five

Teppo
Seppo
two
six

three
seven

four

Creating dictionary variables
Dictionary variables can be created in the variable table similarly as list variables. The difference is that items need to be created using name=value
syntax or existing dictionary variables. If there are multiple items with same name, the last value has precedence. If a name contains a literal equal sign, it
can be escaped with a backslash like \=.
*** Variables ***
&{USER 1}
name=Matti
&{USER 2}
name=Teppo
&{MANY}
first=1
&{EVEN MORE}
&{MANY}
...
=empty

address=xxx
address=yyy
second=${2}
first=override
key\=here=value

phone=123
phone=456
${3}=third
empty=

Dictionary variables have two extra properties compared to normal Python dictionaries. First of all, values of these dictionaries can be accessed like
attributes, which means that it is possible to use extended variable syntax like ${VAR.key}. This only works if the key is a valid attribute name and does
not match any normal attribute Python dictionaries have. For example, individual value &{USER}[name] can also be accessed like ${USER.name} (notice
that $ is needed in this context), but using ${MANY.3} is not possible.
Note
Starting from Robot Framework 3.0.3, dictionary variable keys are accessible recursively like ${VAR.nested.key}. This eases working with nested data
structures.

Another special property of dictionary variables is that they are ordered. This means that if these dictionaries are iterated, their items always come in the
order they are defined. This can be useful if dictionaries are used as list variables with for loops or otherwise. When a dictionary is used as a list variable,
the actual value contains dictionary keys. For example, @{MANY} variable would have value ['first', 'second', 3].

Variable file
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

67/263

6/24/2018

Robot Framework User Guide

Variable files are the most powerful mechanism for creating different kind of variables. It is possible to assign variables to any object using them, and
they also enable creating variables dynamically. The variable file syntax and taking variable files into use is explained in section Resource and variable
files.

Setting variables in command line
Variables can be set from the command line either individually with the --variable (-v) option or using a variable file with the
--variablefile (-V) option. Variables set from the command line are globally available for all executed test data files, and they also override possible
variables with the same names in the Variable table and in variable files imported in the test data.
The syntax for setting individual variables is --variable name:value, where name is the name of the variable without ${} and value is its value.
Several variables can be set by using this option several times. Only scalar variables can be set using this syntax and they can only get string values.
Many special characters are difficult to represent in the command line, but they can be escaped with the --escape option.
--variable EXAMPLE:value
--variable HOST:localhost:7272 --variable USER:robot
--variable ESCAPED:Qquotes_and_spacesQ --escape quot:Q --escape space:_

In the examples above, variables are set so that
gets the value value
${HOST} and ${USER} get the values localhost:7272 and robot
${ESCAPED} gets the value "quotes and spaces"
${EXAMPLE}

The basic syntax for taking variable files into use from the command line is --variablefile path/to/variables.py, and Taking variable files into
use section has more details. What variables actually are created depends on what variables there are in the referenced variable file.
If both variable files and individual variables are given from the command line, the latter have higher priority.

Return values from keywords
Return values from keywords can also be set into variables. This allows communication between different keywords even in different test libraries.
Variables set in this manner are otherwise similar to any other variables, but they are available only in the local scope where they are created. Thus it is
not possible, for example, to set a variable like this in one test case and use it in another. This is because, in general, automated test cases should not
depend on each other, and accidentally setting a variable that is used elsewhere could cause hard-to-debug errors. If there is a genuine need for setting a
variable in one test case and using it in another, it is possible to use BuiltIn keywords as explained in the next section.
Assigning scalar variables
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

68/263

6/24/2018

Robot Framework User Guide

Any value returned by a keyword can be assigned to a scalar variable. As illustrated by the example below, the required syntax is very simple:
*** Test Cases ***
Returning
${x} =
Get X
an argument
Log
We got ${x}!

In the above example the value returned by the Get X keyword is first set into the variable ${x} and then used by the Log keyword. Having the equals
sign = after the variable name is not obligatory, but it makes the assignment more explicit. Creating local variables like this works both in test case and
user keyword level.
Notice that although a value is assigned to a scalar variable, it can be used as a list variable if it has a list-like value and as a dictionary variable if it has a
dictionary-like value.
*** Test Cases ***
Example
${list} =
Create List
first
Length Should Be
${list}
3
Log Many
@{list}

second

third

Assigning list variables
If a keyword returns a list or any list-like object, it is possible to assign it to a list variable:
*** Test Cases ***
Example
@{list} =
Create List
first
Length Should Be
${list}
3
Log Many
@{list}

second

third

Because all Robot Framework variables are stored in the same namespace, there is not much difference between assigning a value to a scalar variable or
a list variable. This can be seen by comparing the last two examples above. The main differences are that when creating a list variable, Robot Framework
automatically verifies that the value is a list or list-like, and the stored variable value will be a new list created from the return value. When assigning to a
scalar variable, the return value is not verified and the stored value will be the exact same object that was returned.
Assigning dictionary variables
If a keyword returns a dictionary or any dictionary-like object, it is possible to assign it to a dictionary variable:
*** Test Cases ***
Example
&{dict} =
Create Dictionary

first=1

second=${2}

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

${3}=third
69/263

6/24/2018

Robot Framework User Guide

Length Should Be
${dict}
Do Something
&{dict}
Log
${dict.first}

3

Because all Robot Framework variables are stored in the same namespace, it would also be possible to assign a dictionary into a scalar variable and use it
later as a dictionary when needed. There are, however, some actual benefits in creating a dictionary variable explicitly. First of all, Robot Framework
verifies that the returned value is a dictionary or dictionary-like similarly as it verifies that list variables can only get a list-like value.
A bigger benefit is that the value is converted into a special dictionary that it uses also when creating dictionary variables in the variable table. Values in
these dictionaries can be accessed using attribute access like ${dict.first} in the above example. These dictionaries are also ordered, but if the original
dictionary was not ordered, the resulting order is arbitrary.
Assigning multiple variables
If a keyword returns a list or a list-like object, it is possible to assign individual values into multiple scalar variables or into scalar variables and a list
variable.
*** Test Cases ***
Assign Multiple
${a}
${b}
${c} =
${first}
@{rest} =
@{before}
${last} =
${begin}
@{middle}

Get Three
Get Three
Get Three
${end} =

Get Three

Assuming that the keyword Get Three returns a list [1, 2, 3], the following variables are created:
${a}, ${b}

and ${c} with values 1, 2, and 3, respectively.
${first} with value 1, and @{rest} with value [2, 3].
@{before} with value [1, 2] and ${last} with value 3.
${begin} with value 1, @{middle} with value [2] and ${end} with value 3.
It is an error if the returned list has more or less values than there are scalar variables to assign. Additionally, only one list variable is allowed and
dictionary variables can only be assigned alone.
The support for assigning multiple variables was slightly changed in Robot Framework 2.9. Prior to it a list variable was only allowed as the last assigned
variable, but nowadays it can be used anywhere. Additionally, it was possible to return more values than scalar variables. In that case the last scalar
variable was magically turned into a list containing the extra values.

Using Set Test/Suite/Global Variable keywords
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

70/263

6/24/2018

Robot Framework User Guide

The BuiltIn library has keywords Set Test Variable, Set Suite Variable and Set Global Variable which can be used for setting variables dynamically
during the test execution. If a variable already exists within the new scope, its value will be overwritten, and otherwise a new variable is created.
Variables set with Set Test Variable keyword are available everywhere within the scope of the currently executed test case. For example, if you set a
variable in a user keyword, it is available both in the test case level and also in all other user keywords used in the current test. Other test cases will not
see variables set with this keyword.
Variables set with Set Suite Variable keyword are available everywhere within the scope of the currently executed test suite. Setting variables with this
keyword thus has the same effect as creating them using the Variable table in the test data file or importing them from variable files. Other test suites,
including possible child test suites, will not see variables set with this keyword.
Variables set with Set Global Variable keyword are globally available in all test cases and suites executed after setting them. Setting variables with this
keyword thus has the same effect as creating from the command line using the options --variable or --variablefile. Because this keyword can
change variables everywhere, it should be used with care.
Note
Set Test/Suite/Global Variable keywords set named variables directly into test, suite or global variable scope and return nothing. On the other hand, another
BuiltIn keyword Set Variable sets local variables using return values.

2.5.4 Built-in variables
Robot Framework provides some built-in variables that are available automatically.

Operating-system variables
Built-in variables related to the operating system ease making the test data operating-system-agnostic.
Available operating-system-related built-in variables
Variable
${CURDIR}
${TEMPDIR}
${EXECDIR}
${/}
${:}
${\n}

Explanation
An absolute path to the directory where the test data file is located. This variable is case-sensitive.
An absolute path to the system temporary directory. In UNIX-like systems this is typically /tmp, and in Windows c:\Documents and
Settings\\Local Settings\Temp.
An absolute path to the directory where test execution was started from.
The system directory path separator. / in UNIX-like systems and \ in Windows.
The system path element separator. : in UNIX-like systems and ; in Windows.
The system line separator. \n in UNIX-like systems and \r\n in Windows. New in version 2.7.5.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

71/263

6/24/2018

Robot Framework User Guide

*** Test Cases ***
Example
Create Binary File
${CURDIR}${/}input.data
Some text here${\n}on two lines
Set Environment Variable
CLASSPATH
${TEMPDIR}${:}${CURDIR}${/}foo.jar

Number variables
The variable syntax can be used for creating both integers and floating point numbers, as illustrated in the example below. This is useful when a keyword
expects to get an actual number, and not a string that just looks like a number, as an argument.
*** Test Cases ***
Example 1A
Connect
example.com

80

# Connect gets two strings as arguments

Example 1B
Connect

${80}

# Connect gets a string and an integer

Example 2
Do X

example.com
${3.14}

${-1e-4}

# Do X gets floating point numbers 3.14 and -0.0001

It is possible to create integers also from binary, octal, and hexadecimal values using 0b, 0o and 0x prefixes, respectively. The syntax is case insensitive.
*** Test Cases ***
Example
Should Be Equal
Should Be Equal
Should Be Equal
Should Be Equal

${0b1011}
${0o10}
${0xff}
${0B1010}

${11}
${8}
${255}
${0XA}

Boolean and None/null variables
Also Boolean values and Python None and Java null can be created using the variable syntax similarly as numbers.
*** Test Cases ***
Boolean
Set Status
${true}
Create Y
something
None
Null

Do XYZ

${None}

${false}

# Set Status gets Boolean true as an argument
# Create Y gets a string and Boolean false
# Do XYZ gets Python None as an argument

${ret} =
Get Value
arg
# Checking that Get Value returns Java null
Should Be Equal
${ret}
${null}

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

72/263

6/24/2018

Robot Framework User Guide

These variables are case-insensitive, so for example ${True} and ${true} are equivalent. Additionally, ${None} and ${null} are synonyms, because
when running tests on the Jython interpreter, Jython automatically converts None and null to the correct format when necessary.

Space and empty variables
It is possible to create spaces and empty strings using variables ${SPACE} and ${EMPTY}, respectively. These variables are useful, for example, when
there would otherwise be a need to escape spaces or empty cells with a backslash. If more than one space is needed, it is possible to use the extended
variable syntax like ${SPACE * 5}. In the following example, Should Be Equal keyword gets identical arguments but those using variables are easier to
understand than those using backslashes.
*** Test Cases ***
One Space
Should Be Equal

${SPACE}

\ \

Four Spaces
Should Be Equal

${SPACE * 4}

\ \ \ \ \

Ten Spaces
Should Be Equal

${SPACE * 10}

\ \ \ \ \ \ \ \ \ \ \

Quoted Space
Should Be Equal

"${SPACE}"

" "

Quoted Spaces
Should Be Equal

"${SPACE * 2}"

" \ "

Empty
Should Be Equal

${EMPTY}

\

There is also an empty list variable @{EMPTY} and an empty dictionary variable &{EMPTY}. Because they have no content, they basically vanish when
used somewhere in the test data. They are useful, for example, with test templates when the template keyword is used without arguments or when
overriding list or dictionary variables in different scopes. Modifying the value of @{EMPTY} or &{EMPTY} is not possible.
*** Test Cases ***
Template
[Template]
Some keyword
@{EMPTY}
Override
Set Global Variable
Set Suite Variable

@{LIST}
&{DICT}

@{EMPTY}
&{EMPTY}

Note
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

73/263

6/24/2018

@{EMPTY}

Robot Framework User Guide

is new in Robot Framework 2.7.4 and &{EMPTY} in Robot Framework 2.9.

Automatic variables
Some automatic variables can also be used in the test data. These variables can have different values during the test execution and some of them are not
even available all the time. Altering the value of these variables does not affect the original values, but some values can be changed dynamically using
keywords from the BuiltIn library.
Available automatic variables
Variable
${TEST NAME}
@{TEST TAGS}

Explanation

${SUITE STATUS}
${SUITE MESSAGE}
${KEYWORD STATUS}

The name of the current test case.
Contains the tags of the current test case in alphabetical order. Can be modified dynamically
using Set Tags and Remove Tags keywords.
The documentation of the current test case. Can be set dynamically using using Set Test
Documentation keyword. New in Robot Framework 2.7.
The status of the current test case, either PASS or FAIL.
The message of the current test case.
The name of the previous test case, or an empty string if no tests have been executed yet.
The status of the previous test case: either PASS, FAIL, or an empty string when no tests have
been executed.
The possible error message of the previous test case.
The full name of the current test suite.
An absolute path to the suite file or directory.
The documentation of the current test suite. Can be set dynamically using using Set Suite
Documentation keyword. New in Robot Framework 2.7.
The free metadata of the current test suite. Can be set using Set Suite Metadata keyword. New in
Robot Framework 2.7.4.
The status of the current test suite, either PASS or FAIL.
The full message of the current test suite, including statistics.
The status of the current keyword, either PASS or FAIL. New in Robot Framework 2.7

${KEYWORD MESSAGE}

The possible error message of the current keyword. New in Robot Framework 2.7.

${LOG LEVEL}
${OUTPUT FILE}
${LOG FILE}
${REPORT FILE}

Current log level. New in Robot Framework 2.8.
An absolute path to the output file.
An absolute path to the log file or string NONE when no log file is created.
An absolute path to the report file or string NONE when no report is created.

${TEST DOCUMENTATION}
${TEST STATUS}
${TEST MESSAGE}
${PREV TEST NAME}
${PREV TEST STATUS}
${PREV TEST MESSAGE}
${SUITE NAME}
${SUITE SOURCE}
${SUITE DOCUMENTATION}
&{SUITE METADATA}

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

Available
Test case
Test case
Test case
Test teardown
Test teardown
Everywhere
Everywhere
Everywhere
Everywhere
Everywhere
Everywhere
Everywhere
Suite teardown
Suite teardown
User keyword
teardown
User keyword
teardown
Everywhere
Everywhere
Everywhere
Everywhere
74/263

6/24/2018

Variable
${DEBUG FILE}
${OUTPUT DIR}

Robot Framework User Guide

Explanation
An absolute path to the debug file or string NONE when no debug file is created.
An absolute path to the output directory.

Available
Everywhere
Everywhere

Suite related variables ${SUITE SOURCE}, ${SUITE NAME}, ${SUITE DOCUMENTATION} and &{SUITE METADATA} are available already when test
libraries and variable files are imported, except to Robot Framework 2.8 and 2.8.1 where this support was broken. Possible variables in these automatic
variables are not yet resolved at the import time, though.

2.5.5 Variable priorities and scopes
Variables coming from different sources have different priorities and are available in different scopes.

Variable priorities
Variables from the command line
Variables set in the command line have the highest priority of all variables that can be set before the actual test execution starts. They
override possible variables created in Variable tables in test case files, as well as in resource and variable files imported in the test data.
Individually set variables (--variable option) override the variables set using variable files (--variablefile option). If you specify same
individual variable multiple times, the one specified last will override earlier ones. This allows setting default values for variables in a startup script and overriding them from the command line. Notice, though, that if multiple variable files have same variables, the ones in the file
specified first have the highest priority.
Variable table in a test case file
Variables created using the Variable table in a test case file are available for all the test cases in that file. These variables override possible
variables with same names in imported resource and variable files.
Variables created in the variable tables are available in all other tables in the file where they are created. This means that they can be used
also in the Setting table, for example, for importing more variables from resource and variable files.
Imported resource and variable files
Variables imported from the resource and variable files have the lowest priority of all variables created in the test data. Variables from
resource files and variable files have the same priority. If several resource and/or variable file have same variables, the ones in the file
imported first are taken into use.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

75/263

6/24/2018

Robot Framework User Guide

If a resource file imports resource files or variable files, variables in its own Variable table have a higher priority than variables it imports. All
these variables are available for files that import this resource file.
Note that variables imported from resource and variable files are not available in the Variable table of the file that imports them. This is due
to the Variable table being processed before the Setting table where the resource files and variable files are imported.
Variables set during test execution
Variables set during the test execution either using return values from keywords or using Set Test/Suite/Global Variable keywords always
override possible existing variables in the scope where they are set. In a sense they thus have the highest priority, but on the other hand they
do not affect variables outside the scope they are defined.
Built-in variables
Built-in variables like ${TEMPDIR} and ${TEST_NAME} have the highest priority of all variables. They cannot be overridden using Variable
table or from command line, but even they can be reset during the test execution. An exception to this rule are number variables, which are
resolved dynamically if no variable is found otherwise. They can thus be overridden, but that is generally a bad idea. Additionally
${CURDIR} is special because it is replaced already during the test data processing time.

Variable scopes
Depending on where and how they are created, variables can have a global, test suite, test case or local scope.
Global scope
Global variables are available everywhere in the test data. These variables are normally set from the command line with the --variable and
--variablefile options, but it is also possible to create new global variables or change the existing ones with the BuiltIn keyword Set Global Variable
anywhere in the test data. Additionally also built-in variables are global.
It is recommended to use capital letters with all global variables.
Test suite scope
Variables with the test suite scope are available anywhere in the test suite where they are defined or imported. They can be created in Variable tables,
imported from resource and variable files, or set during the test execution using the BuiltIn keyword Set Suite Variable.
The test suite scope is not recursive, which means that variables available in a higher-level test suite are not available in lower-level suites. If necessary,
resource and variable files can be used for sharing variables.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

76/263

6/24/2018

Robot Framework User Guide

Since these variables can be considered global in the test suite where they are used, it is recommended to use capital letters also with them.
Test case scope
Variables with the test case scope are visible in a test case and in all user keywords the test uses. Initially there are no variables in this scope, but it is
possible to create them by using the BuiltIn keyword Set Test Variable anywhere in a test case.
Also variables in the test case scope are to some extend global. It is thus generally recommended to use capital letters with them too.
Local scope
Test cases and user keywords have a local variable scope that is not seen by other tests or keywords. Local variables can be created using return values
from executed keywords and user keywords also get them as arguments.
It is recommended to use lower-case letters with local variables.
Note
Prior to Robot Framework 2.9 variables in the local scope leaked to lower level user keywords. This was never an intended feature, and variables should be
set or passed explicitly also with earlier versions.

2.5.6 Advanced variable features
Extended variable syntax
Extended variable syntax allows accessing attributes of an object assigned to a variable (for example, ${object.attribute}) and even calling its
methods (for example, ${obj.getName()}). It works both with scalar and list variables, but is mainly useful with the former
Extended variable syntax is a powerful feature, but it should be used with care. Accessing attributes is normally not a problem, on the contrary, because
one variable containing an object with several attributes is often better than having several variables. On the other hand, calling methods, especially when
they are used with arguments, can make the test data pretty complicated to understand. If that happens, it is recommended to move the code into a test
library.
The most common usages of extended variable syntax are illustrated in the example below. First assume that we have the following variable file and test
case:

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

77/263

6/24/2018

Robot Framework User Guide

class MyObject:
def __init__(self, name):
self.name = name
def eat(self, what):
return '%s eats %s' % (self.name, what)
def __str__(self):
return self.name
OBJECT = MyObject('Robot')
DICTIONARY = {1: 'one', 2: 'two', 3: 'three'}
*** Test Cases ***
Example
KW 1
${OBJECT.name}
KW 2
${OBJECT.eat('Cucumber')}
KW 3
${DICTIONARY[2]}

When this test data is executed, the keywords get the arguments as explained below:
KW 1 gets string Robot
KW 2 gets string Robot eats Cucumber
KW 3 gets string two
The extended variable syntax is evaluated in the following order:
1. The variable is searched using the full variable name. The extended variable syntax is evaluated only if no matching variable is found.
2. The name of the base variable is created. The body of the name consists of all the characters after the opening { until the first occurrence of a
character that is not an alphanumeric character or a space. For example, base variables of ${OBJECT.name} and ${DICTIONARY[2]}) are OBJECT
and DICTIONARY, respectively.
3. A variable matching the body is searched. If there is no match, an exception is raised and the test case fails.
4. The expression inside the curly brackets is evaluated as a Python expression, so that the base variable name is replaced with its value. If the
evaluation fails because of an invalid syntax or that the queried attribute does not exist, an exception is raised and the test fails.
5. The whole extended variable is replaced with the value returned from the evaluation.
If the object that is used is implemented with Java, the extended variable syntax allows you to access attributes using so-called bean properties. In
essence, this means that if you have an object with the getName method set into a variable ${OBJ}, then the syntax ${OBJ.name} is equivalent to but
clearer than ${OBJ.getName()}. The Python object used in the previous example could thus be replaced with the following Java implementation:
public class MyObject:

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

78/263

6/24/2018

Robot Framework User Guide

private String name;
public MyObject(String name) {
name = name;
}
public String getName() {
return name;
}
public String eat(String what) {
return name + " eats " + what;
}

}

public String toString() {
return name;
}

Many standard Python objects, including strings and numbers, have methods that can be used with the extended variable syntax either explicitly or
implicitly. Sometimes this can be really useful and reduce the need for setting temporary variables, but it is also easy to overuse it and create really cryptic
test data. Following examples show few pretty good usages.
*** Test Cases ***
String
${string} =
Set Variable
Log
${string.upper()}
Log
${string * 2}

abc
# Logs 'ABC'
# Logs 'abcabc'

Number
${number} =
Set Variable
Log
${number * 10}
Log
${number.__abs__()}

${-2}
# Logs -20
# Logs 2

Note that even though abs(number) is recommended over number.__abs__() in normal Python code, using ${abs(number)} does not work. This is
because the variable name must be in the beginning of the extended syntax. Using __xxx__ methods in the test data like this is already a bit questionable,
and it is normally better to move this kind of logic into test libraries.
Extended variable syntax works also in list variable context. If, for example, an object assigned to a variable ${EXTENDED} has an attribute attribute
that contains a list as a value, it can be used as a list variable @{EXTENDED.attribute}.

Extended variable assignment
Starting from Robot Framework 2.7, it is possible to set attributes of objects stored to scalar variables using keyword return values and a variation of the
extended variable syntax. Assuming we have variable ${OBJECT} from the previous examples, attributes could be set to it like in the example below.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

79/263

6/24/2018

Robot Framework User Guide

*** Test Cases ***
Example
${OBJECT.name} =
Set Variable
New name
${OBJECT.new_attr} =
Set Variable
New attribute

The extended variable assignment syntax is evaluated using the following rules:
1. The assigned variable must be a scalar variable and have at least one dot. Otherwise the extended assignment syntax is not used and the variable is
assigned normally.
2. If there exists a variable with the full name (e.g. ${OBJECT.name} in the example above) that variable will be assigned a new value and the
extended syntax is not used.
3. The name of the base variable is created. The body of the name consists of all the characters between the opening ${ and the last dot, for example,
OBJECT in ${OBJECT.name} and foo.bar in ${foo.bar.zap}. As the second example illustrates, the base name may contain normal extended
variable syntax.
4. The name of the attribute to set is created by taking all the characters between the last dot and the closing }, for example, name in
${OBJECT.name}. If the name does not start with a letter or underscore and contain only these characters and numbers, the attribute is considered
invalid and the extended syntax is not used. A new variable with the full name is created instead.
5. A variable matching the base name is searched. If no variable is found, the extended syntax is not used and, instead, a new variable is created
using the full variable name.
6. If the found variable is a string or a number, the extended syntax is ignored and a new variable created using the full name. This is done because
you cannot add new attributes to Python strings or numbers, and this way the new syntax is also less backwards-incompatible.
7. If all the previous rules match, the attribute is set to the base variable. If setting fails for any reason, an exception is raised and the test fails.
Note
Unlike when assigning variables normally using return values from keywords, changes to variables done using the extended assign syntax are not limited to
the current scope. Because no new variable is created but instead the state of an existing variable is changed, all tests and keywords that see that variable will
also see the changes.

Variables inside variables
Variables are allowed also inside variables, and when this syntax is used, variables are resolved from the inside out. For example, if you have a variable
${var${x}}, then ${x} is resolved first. If it has the value name, the final value is then the value of the variable ${varname}. There can be several
nested variables, but resolving the outermost fails, if any of them does not exist.
In the example below, Do X gets the value ${JOHN HOME} or ${JANE HOME}, depending on if Get Name returns john or jane. If it returns something
else, resolving ${${name} HOME} fails.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

80/263

6/24/2018

Robot Framework User Guide

*** Variables ***
${JOHN HOME}
/home/john
${JANE HOME}
/home/jane
*** Test Cases ***
Example
${name} =
Get Name
Do X
${${name} HOME}

2.6 Creating user keywords
Keyword tables are used to create new higher-level keywords by combining existing keywords together. These keywords are called user keywords to
differentiate them from lowest level library keywords that are implemented in test libraries. The syntax for creating user keywords is very close to the
syntax for creating test cases, which makes it easy to learn.
2.6.1 User keyword syntax
Basic syntax
Settings in the Keyword table
2.6.2 User keyword name and documentation
2.6.3 User keyword tags
2.6.4 User keyword arguments
Positional arguments
Default values with user keywords
Varargs with user keywords
Kwargs with user keywords
2.6.5 Embedding arguments into keyword name
Basic syntax
Embedded arguments matching too much
Using custom regular expressions
Behavior-driven development example
2.6.6 User keyword return values
Using [Return] setting
Using special keywords to return
2.6.7 User keyword teardown

2.6.1 User keyword syntax
Basic syntax
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

81/263

6/24/2018

Robot Framework User Guide

In many ways, the overall user keyword syntax is identical to the test case syntax. User keywords are created in keyword tables which differ from test
case tables only by the name that is used to identify them. User keyword names are in the first column similarly as test cases names. Also user keywords
are created from keywords, either from keywords in test libraries or other user keywords. Keyword names are normally in the second column, but when
setting variables from keyword return values, they are in the subsequent columns.
*** Keywords ***
Open Login Page
Open Browser
http://host/login.html
Title Should Be
Login Page
Title Should Start With
[Arguments]
${expected}
${title} =
Get Title
Should Start With
${title}

${expected}

Most user keywords take some arguments. This important feature is used already in the second example above, and it is explained in detail later in this
section, similarly as user keyword return values.
User keywords can be created in test case files, resource files, and test suite initialization files. Keywords created in resource files are available for files
using them, whereas other keywords are only available in the files where they are created.

Settings in the Keyword table
User keywords can have similar settings as test cases, and they have the same square bracket syntax separating them from keyword names. All available
settings are listed below and explained later in this section.
[Documentation]
Used for setting a user keyword documentation.
[Tags]
Sets tags for the keyword.
[Arguments]
Specifies user keyword arguments.
[Return]
Specifies user keyword return values.
[Teardown]
Specify user keyword teardown.
[Timeout]
Sets the possible user keyword timeout. Timeouts are discussed in a section of their own.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

82/263

6/24/2018

Robot Framework User Guide

2.6.2 User keyword name and documentation
The user keyword name is defined in the first column of the user keyword table. Of course, the name should be descriptive, and it is acceptable to have
quite long keyword names. Actually, when creating use-case-like test cases, the highest-level keywords are often formulated as sentences or even
paragraphs.
User keywords can have a documentation that is set with the [Documentation] setting, exactly as test case documentation. This setting documents the
user keyword in the test data. It is also shown in a more formal keyword documentation, which the Libdoc tool can create from resource files. Finally, the
first row of the documentation is shown as a keyword documentation in test logs.
Sometimes keywords need to be removed, replaced with new ones, or deprecated for other reasons. User keywords can be marked deprecated by starting
the documentation with *DEPRECATED*, which will cause a warning when the keyword is used. For more information, see Deprecating keywords
section.

2.6.3 User keyword tags
Starting from Robot Framework 2.9, keywords can also have tags. User keywords tags can be set with [Tags] setting similarly as test case tags, but
possible Force Tags and Default Tags setting do not affect them. Additionally keyword tags can be specified on the last line of the documentation with
Tags: prefix and separated by a comma. For example, following two keywords would both get same three tags.
*** Keywords ***
Settings tags using separate setting
[Tags]
my
fine
tags
No Operation
Settings tags using documentation
[Documentation]
I have documentation. And my documentation has tags.
...
Tags: my, fine, tags
No Operation

Keyword tags are shown in logs and in documentation generated by Libdoc, where the keywords can also be searched based on tags. The -removekeywords and --flattenkeywords commandline options also support selecting keywords by tag, and new usages for keywords tags are possibly
added in later releases.
Similarly as with test case tags, user keyword tags with robot- and robot: prefixes are reserved for special features by Robot Framework itself. Users
should thus not use any tag with these prefixes unless actually activating the special functionality.

2.6.4 User keyword arguments

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

83/263

6/24/2018

Robot Framework User Guide

Most user keywords need to take some arguments. The syntax for specifying them is probably the most complicated feature normally needed with Robot
Framework, but even that is relatively easy, particularly in most common cases. Arguments are normally specified with the [Arguments] setting, and
argument names use the same syntax as variables, for example ${arg}.

Positional arguments
The simplest way to specify arguments (apart from not having them at all) is using only positional arguments. In most cases, this is all that is needed.
The syntax is such that first the [Arguments] setting is given and then argument names are defined in the subsequent cells. Each argument is in its own
cell, using the same syntax as with variables. The keyword must be used with as many arguments as there are argument names in its signature. The actual
argument names do not matter to the framework, but from users' perspective they should be as descriptive as possible. It is recommended to use lowercase letters in variable names, either as ${my_arg}, ${my arg} or ${myArg}.
*** Keywords ***
One Argument
[Arguments]
${arg_name}
Log
Got argument ${arg_name}
Three Arguments
[Arguments]
${arg1}
${arg2}
Log
1st argument: ${arg1}
Log
2nd argument: ${arg2}
Log
3rd argument: ${arg3}

${arg3}

Default values with user keywords
When creating user keywords, positional arguments are sufficient in most situations. It is, however, sometimes useful that keywords have default values
for some or all of their arguments. Also user keywords support default values, and the needed new syntax does not add very much to the already
discussed basic syntax.
In short, default values are added to arguments, so that first there is the equals sign (=) and then the value, for example ${arg}=default. There can be
many arguments with defaults, but they all must be given after the normal positional arguments. The default value can contain a variable created on test,
suite or global scope, but local variables of the keyword executor cannot be used. Starting from Robot Framework 3.0, default value can also be defined
based on earlier arguments accepted by the keyword.
Note
The syntax for default values is space sensitive. Spaces before the = sign are not allowed, and possible spaces after it are considered part of the default value
itself.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

84/263

6/24/2018

Robot Framework User Guide

*** Keywords ***
One Argument With Default Value
[Arguments]
${arg}=default value
[Documentation]
This keyword takes 0-1 arguments
Log
Got argument ${arg}
Two Arguments With Defaults
[Arguments]
${arg1}=default 1
${arg2}=${VARIABLE}
[Documentation]
This keyword takes 0-2 arguments
Log
1st argument ${arg1}
Log
2nd argument ${arg2}
One Required And One With Default
[Arguments]
${required}
${optional}=default
[Documentation]
This keyword takes 1-2 arguments
Log
Required: ${required}
Log
Optional: ${optional}
Default Based On Earlier Argument
[Arguments]
${a}
${b}=${a}
${c}=${a} and ${b}
Should Be Equal
${a}
${b}
Should Be Equal
${c}
${a} and ${b}

When a keyword accepts several arguments with default values and only some of them needs to be overridden, it is often handy to use the named
arguments syntax. When this syntax is used with user keywords, the arguments are specified without the ${} decoration. For example, the second
keyword above could be used like below and ${arg1} would still get its default value.
*** Test Cases ***
Example
Two Arguments With Defaults

arg2=new value

As all Pythonistas must have already noticed, the syntax for specifying default arguments is heavily inspired by Python syntax for function default
values.

Varargs with user keywords
Sometimes even default values are not enough and there is a need for a keyword accepting variable number of arguments. User keywords support also
this feature. All that is needed is having list variable such as @{varargs} after possible positional arguments in the keyword signature. This syntax can
be combined with the previously described default values, and at the end the list variable gets all the leftover arguments that do not match other
arguments. The list variable can thus have any number of items, even zero.
*** Keywords ***
Any Number Of Arguments
[Arguments]
@{varargs}
Log Many
@{varargs}
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

85/263

6/24/2018

Robot Framework User Guide

One Or More Arguments
[Arguments]
${required}
@{rest}
Log Many
${required}
@{rest}
Required, Default, Varargs
[Arguments]
${req}
Log
Required: ${req}
Log
Optional: ${opt}
Log
Others:
: FOR
${item}
IN
\
Log
${item}

${opt}=42

@{others}

@{others}

Notice that if the last keyword above is used with more than one argument, the second argument ${opt} always gets the given value instead of the
default value. This happens even if the given value is empty. The last example also illustrates how a variable number of arguments accepted by a user
keyword can be used in a for loop. This combination of two rather advanced functions can sometimes be very useful.
The keywords in the examples above could be used, for example, like this:
*** Test Cases ***
Varargs with user keywords
Any Number Of Arguments
Any Number Of Arguments
arg
Any Number Of Arguments
arg1
arg2
arg3
arg4
One Or More Arguments
required
One Or More Arguments
arg1
arg2
arg3
arg4
Required, Default, Varargs
required
Required, Default, Varargs
required
optional
Required, Default, Varargs
arg1
arg2
arg3
arg4

arg5

Again, Pythonistas probably notice that the variable number of arguments syntax is very close to the one in Python.

Kwargs with user keywords
User keywords can also accept free keyword arguments by having a dictionary variable like &{kwargs} as the last argument after possible positional
arguments and varargs. When the keyword is called, this variable will get all named arguments that do not match any positional argument in the keyword
signature.
*** Keywords ***
Kwargs Only
[Arguments]
&{kwargs}
Log
${kwargs}
Log Many
@{kwargs}
Positional And Kwargs
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

86/263

6/24/2018

Robot Framework User Guide

[Arguments]
${required}
&{extra}
Log Many
${required}
@{extra}
Run Program
[Arguments]
Run Process

@{varargs}
program.py

&{kwargs}
@{varargs}

&{kwargs}

The last example above shows how to create a wrapper keyword that accepts any positional or named argument and passes them forward. See kwargs
examples for a full example with same keyword.
Also kwargs support with user keywords works very similarly as kwargs work in Python. In the signature and also when passing arguments forward, &
{kwargs} is pretty much the same as Python's **kwargs.

2.6.5 Embedding arguments into keyword name
Robot Framework has also another approach to pass arguments to user keywords than specifying them in cells after the keyword name as explained in
the previous section. This method is based on embedding the arguments directly into the keyword name, and its main benefit is making it easier to use
real and clear sentences as keywords.

Basic syntax
It has always been possible to use keywords like Select dog from list and Selects cat from list, but all such keywords must have been implemented
separately. The idea of embedding arguments into the keyword name is that all you need is a keyword with name like Select ${animal} from list.
*** Keywords ***
Select ${animal} from list
Open Page
Pet Selection
Select Item From List
animal_list

${animal}

Keywords using embedded arguments cannot take any "normal" arguments (specified with [Arguments] setting) but otherwise they are created just like
other user keywords. The arguments used in the name will naturally be available inside the keyword and they have different value depending on how the
keyword is called. For example, ${animal} in the previous has value dog if the keyword is used like Select dog from list. Obviously it is not mandatory
to use all these arguments inside the keyword, and they can thus be used as wildcards.
These kind of keywords are also used the same way as other keywords except that spaces and underscores are not ignored in their names. They are,
however, case-insensitive like other keywords. For example, the keyword in the example above could be used like select x from list, but not like Select x
fromlist.
Embedded arguments do not support default values or variable number of arguments like normal arguments do. Using variables when calling these
keywords is possible but that can reduce readability. Notice also that embedded arguments only work with user keywords.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

87/263

6/24/2018

Robot Framework User Guide

Embedded arguments matching too much
One tricky part in using embedded arguments is making sure that the values used when calling the keyword match the correct arguments. This is a
problem especially if there are multiple arguments and characters separating them may also appear in the given values. For example, keyword Select
${city} ${team} does not work correctly if used with city containing too parts like Select Los Angeles Lakers.
An easy solution to this problem is quoting the arguments (e.g. Select "${city}" "${team}") and using the keyword in quoted format (e.g. Select "Los
Angeles" "Lakers"). This approach is not enough to resolve all this kind of conflicts, though, but it is still highly recommended because it makes
arguments stand out from rest of the keyword. A more powerful but also more complicated solution, using custom regular expressions when defining
variables, is explained in the next section. Finally, if things get complicated, it might be a better idea to use normal positional arguments instead.
The problem of arguments matching too much occurs often when creating keywords that ignore given/when/then/and/but prefixes . For example,
${name} goes home matches Given Janne goes home so that ${name} gets value Given Janne. Quotes around the argument, like in "${name}" goes
home, resolve this problem easily.

Using custom regular expressions
When keywords with embedded arguments are called, the values are matched internally using regular expressions (regexps for short). The default logic
goes so that every argument in the name is replaced with a pattern .*? that basically matches any string. This logic works fairly well normally, but as just
discussed above, sometimes keywords match more than intended. Quoting or otherwise separating arguments from the other text can help but, for
example, the test below fails because keyword I execute "ls" with "-lh" matches both of the defined keywords.
*** Test Cases ***
Example
I execute "ls"
I execute "ls" with "-lh"
*** Keywords ***
I execute "${cmd}"
Run Process
${cmd}

shell=True

I execute "${cmd}" with "${opts}"
Run Process
${cmd} ${opts}

shell=True

A solution to this problem is using a custom regular expression that makes sure that the keyword matches only what it should in that particular context.
To be able to use this feature, and to fully understand the examples in this section, you need to understand at least the basics of the regular expression
syntax.
A custom embedded argument regular expression is defined after the base name of the argument so that the argument and the regexp are separated with a
colon. For example, an argument that should match only numbers can be defined like ${arg:\d+}. Using custom regular expressions is illustrated by the
examples below.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

88/263

6/24/2018

Robot Framework User Guide

*** Test Cases ***
Example
I execute "ls"
I execute "ls" with "-lh"
I type 1 + 2
I type 53 - 11
Today is 2011-06-27
*** Keywords ***
I execute "${cmd:[^"]+}"
Run Process
${cmd}

shell=True

I execute "${cmd}" with "${opts}"
Run Process
${cmd} ${opts}

shell=True

I type ${a:\d+} ${operator:[+-]} ${b:\d+}
Calculate
${a}
${operator}
${b}
Today is ${date:\d{4\}-\d{2\}-\d{2\}}
Log
${date}

In the above example keyword I execute "ls" with "-lh" matches only I execute "${cmd}" with "${opts}". That is guaranteed because the custom regular
expression [^"]+ in I execute "${cmd:[^"]}" means that a matching argument cannot contain any quotes. In this case there is no need to add custom
regexps to the other I execute variant.
Tip
If you quote arguments, using regular expression [^"]+ guarantees that the argument matches only until the first closing quote.

Supported regular expression syntax
Being implemented with Python, Robot Framework naturally uses Python's re module that has pretty standard regular expressions syntax. This syntax is
otherwise fully supported with embedded arguments, but regexp extensions in format (?...) cannot be used. Notice also that matching embedded
arguments is done case-insensitively. If the regular expression syntax is invalid, creating the keyword fails with an error visible in test execution errors.
Escaping special characters
There are some special characters that need to be escaped when used in the custom embedded arguments regexp. First of all, possible closing curly
braces (}) in the pattern need to be escaped with a single backslash (\}) because otherwise the argument would end already there. This is illustrated in
the previous example with keyword Today is ${date:\d{4\}-\d{2\}-\d{2\}}.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

89/263

6/24/2018

Robot Framework User Guide

Backslash (\) is a special character in Python regular expression syntax and thus needs to be escaped if you want to have a literal backslash character.
The safest escape sequence in this case is four backslashes (\\\\) but, depending on the next character, also two backslashes may be enough.
Notice also that keyword names and possible embedded arguments in them should not be escaped using the normal test data escaping rules. This means
that, for example, backslashes in expressions like ${name:\w+} should not be escaped.
Using variables with custom embedded argument regular expressions
Whenever custom embedded argument regular expressions are used, Robot Framework automatically enhances the specified regexps so that they match
variables in addition to the text matching the pattern. This means that it is always possible to use variables with keywords having embedded arguments.
For example, the following test case would pass using the keywords from the earlier example.
*** Variables ***
${DATE}
2011-06-27
*** Test Cases ***
Example
I type ${1} + ${2}
Today is ${DATE}

A drawback of variables automatically matching custom regular expressions is that it is possible that the value the keyword gets does not actually match
the specified regexp. For example, variable ${DATE} in the above example could contain any value and Today is ${DATE} would still match the same
keyword.

Behavior-driven development example
The biggest benefit of having arguments as part of the keyword name is that it makes it easier to use higher-level sentence-like keywords when writing
test cases in behavior-driven style. The example below illustrates this. Notice also that prefixes Given, When and Then are left out of the keyword
definitions.
*** Test Cases ***
Add two numbers
Given I have Calculator open
When I add 2 and 40
Then result should be 42
Add negative numbers
Given I have Calculator open
When I add 1 and -2
Then result should be -1
*** Keywords ***
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

90/263

6/24/2018

Robot Framework User Guide

I have ${program} open
Start Program
${program}
I add ${number 1} and ${number 2}
Input Number
${number 1}
Push Button
+
Input Number
${number 2}
Push Button
=
Result should be ${expected}
${result} =
Get Result
Should Be Equal
${result}

${expected}

Note
Embedded arguments feature in Robot Framework is inspired by how step definitions are created in a popular BDD tool Cucumber.

2.6.6 User keyword return values
Similarly as library keywords, also user keywords can return values. Typically return values are defined with the [Return] setting, but it is also possible to
use BuiltIn keywords Return From Keyword and Return From Keyword If. Regardless how values are returned, they can be assigned to variables in test
cases and in other user keywords.

Using [Return] setting
The most common case is that a user keyword returns one value and it is assigned to a scalar variable. When using the [Return] setting, this is done by
having the return value in the next cell after the setting.
User keywords can also return several values, which can then be assigned into several scalar variables at once, to a list variable, or to scalar variables and
a list variable. Several values can be returned simply by specifying those values in different cells after the [Return] setting.
*** Test Cases ***
One Return Value
${ret} =
Return One Value
Some Keyword
${ret}

argument

Multiple Values
${a}
${b}
${c} =
Return Three Values
@{list} =
Return Three Values
${scalar}
@{rest} =
Return Three Values
*** Keywords ***
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

91/263

6/24/2018

Robot Framework User Guide

Return One Value
[Arguments]
${arg}
Do Something
${arg}
${value} =
Get Some Value
[Return]
${value}
Return Three Values
[Return]
foo

bar

zap

Using special keywords to return
BuiltIn keywords Return From Keyword and Return From Keyword If allow returning from a user keyword conditionally in the middle of the keyword.
Both of them also accept optional return values that are handled exactly like with the [Return] setting discussed above.
The first example below is functionally identical to the previous [Return] setting example. The second, and more advanced, example demonstrates
returning conditionally inside a for loop.
*** Test Cases ***
One Return Value
${ret} =
Return One Value
Some Keyword
${ret}

argument

Advanced
@{list} =
Create List
foo
baz
${index} =
Find Index
baz
@{list}
Should Be Equal
${index}
${1}
${index} =
Find Index
non existing
Should Be Equal
${index}
${-1}

@{list}

*** Keywords ***
Return One Value
[Arguments]
${arg}
Do Something
${arg}
${value} =
Get Some Value
Return From Keyword
${value}
Fail
This is not executed
Find Index
[Arguments]
${element}
@{items}
${index} =
Set Variable
${0}
:FOR
${item}
IN
@{items}
\
Return From Keyword If
'${item}' == '${element}'
\
${index} =
Set Variable
${index + 1}
Return From Keyword
${-1}
# Could also use [Return]

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

${index}

92/263

6/24/2018

Robot Framework User Guide

Note
Both Return From Keyword and Return From Keyword If are available since Robot Framework 2.8.

2.6.7 User keyword teardown
User keywords may have a teardown defined using [Teardown] setting.
Keyword teardown works much in the same way as a test case teardown. Most importantly, the teardown is always a single keyword, although it can be
another user keyword, and it gets executed also when the user keyword fails. In addition, all steps of the teardown are executed even if one of them fails.
However, a failure in keyword teardown will fail the test case and subsequent steps in the test are not run. The name of the keyword to be executed as a
teardown can also be a variable.
*** Keywords ***
With Teardown
Do Something
[Teardown]

Log

keyword teardown

Using variables
[Documentation]
Teardown given as variable
Do Something
[Teardown]
${TEARDOWN}

2.7 Resource and variable files
User keywords and variables in test case files and test suite initialization files can only be used in files where they are created, but resource files provide a
mechanism for sharing them. Since the resource file structure is very close to test case files, it is easy to create them.
Variable files provide a powerful mechanism for creating and sharing variables. For example, they allow values other than strings and enable creating
variables dynamically. Their flexibility comes from the fact that they are created using Python code, which also makes them somewhat more complicated
than Variable tables.
2.7.1 Resource files
Taking resource files into use
Resource file structure
Documenting resource files
Example resource file
2.7.2 Variable files
Taking variable files into use
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

93/263

6/24/2018

Robot Framework User Guide

Creating variables directly
Getting variables from a special function
Implementing variable file as Python or Java class
Variable file as YAML

2.7.1 Resource files
Taking resource files into use
Resource files are imported using the Resource setting in the Settings table. The path to the resource file is given in the cell after the setting name.
If the path is given in an absolute format, it is used directly. In other cases, the resource file is first searched relatively to the directory where the importing
file is located. If the file is not found there, it is then searched from the directories in Python's module search path. The path can contain variables, and it
is recommended to use them to make paths system-independent (for example, ${RESOURCES}/login_resources.html or ${RESOURCE_PATH}).
Additionally, slashes (/) in the path are automatically changed to backslashes (\) on Windows.
*** Settings ***
Resource
myresources.html
Resource
../data/resources.html
Resource
${RESOURCES}/common.tsv

The user keywords and variables defined in a resource file are available in the file that takes that resource file into use. Similarly available are also all
keywords and variables from the libraries, resource files and variable files imported by the said resource file.

Resource file structure
The higher-level structure of resource files is the same as that of test case files otherwise, but, of course, they cannot contain Test Case tables.
Additionally, the Setting table in resource files can contain only import settings (Library, Resource, Variables) and Documentation. The Variable table
and Keyword table are used exactly the same way as in test case files.
If several resource files have a user keyword with the same name, they must be used so that the keyword name is prefixed with the resource file name
without the extension (for example, myresources.Some Keyword and common.Some Keyword). Moreover, if several resource files contain the same
variable, the one that is imported first is taken into use.

Documenting resource files

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

94/263

6/24/2018

Robot Framework User Guide

Keywords created in a resource file can be documented using [Documentation] setting. The resource file itself can have Documentation in the Setting
table similarly as test suites.
Both Libdoc and RIDE use these documentations, and they are naturally available for anyone opening resource files. The first line of the documentation
of a keyword is logged when it is run, but otherwise resource file documentations are ignored during the test execution.

Example resource file
*** Settings ***
Documentation
Library
Resource

An example resource file
SeleniumLibrary
${RESOURCES}/common.robot

*** Variables ***
${HOST}
${LOGIN URL}
${WELCOME URL}
${BROWSER}

localhost:7272
http://${HOST}/
http://${HOST}/welcome.html
Firefox

*** Keywords ***
Open Login Page
[Documentation]
Opens browser to login page
Open Browser
${LOGIN URL}
${BROWSER}
Title Should Be
Login Page
Input Name
[Arguments]
Input Text

${name}
username_field

${name}

Input Password
[Arguments]
Input Text

${password}
password_field

${password}

2.7.2 Variable files
Variable files contain variables that can be used in the test data. Variables can also be created using variable tables or set from the command line, but
variable files allow creating them dynamically and their variables can contain any objects.
Variable files are typically implemented as Python modules and there are two different approaches for creating variables:
Creating variables directly
Variables are specified as module attributes. In simple cases, the syntax is so simple that no real programming is needed. For example, MY_VAR =
'my value' creates a variable ${MY_VAR} with the specified text as the value.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

95/263

6/24/2018

Robot Framework User Guide

Getting variables from a special function
Variable files can have a special get_variables (or getVariables) method that returns variables as a mapping. Because the method can take
arguments this approach is very flexible.
Alternatively variable files can be implemented as Python or Java classes that the framework will instantiate. Also in this case it is possible to create
variables as attributes or get them from a special method.

Taking variable files into use
Setting table
All test data files can import variables using the Variables setting in the Setting table, in the same way as resource files are imported using the Resource
setting. Similarly to resource files, the path to the imported variable file is considered relative to the directory where the importing file is, and if not found,
it is searched from the directories in the module search path. The path can also contain variables, and slashes are converted to backslashes on Windows.
If an argument file takes arguments, they are specified in the cells after the path and also they can contain variables.
*** Settings
Variables
Variables
Variables
Variables

***
myvariables.py
../data/variables.py
${RESOURCES}/common.py
taking_arguments.py
arg1

${ARG2}

All variables from a variable file are available in the test data file that imports it. If several variable files are imported and they contain a variable with the
same name, the one in the earliest imported file is taken into use. Additionally, variables created in Variable tables and set from the command line
override variables from variable files.
Command line
Another way to take variable files into use is using the command line option --variablefile. Variable files are referenced using a path to them, and
possible arguments are joined to the path with a colon (:):
--variablefile
--variablefile
--variablefile
--variablefile

myvariables.py
path/variables.py
/absolute/path/common.py
taking_arguments.py:arg1:arg2

Starting from Robot Framework 2.8.2, variable files taken into use from the command line are also searched from the module search path similarly as
variable files imported in the Setting table.
If a variable file is given as an absolute Windows path, the colon after the drive letter is not considered a separator:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

96/263

6/24/2018

Robot Framework User Guide

--variablefile C:\path\variables.py

Starting from Robot Framework 2.8.7, it is also possible to use a semicolon (;) as an argument separator. This is useful if variable file arguments
themselves contain colons, but requires surrounding the whole value with quotes on UNIX-like operating systems:
--variablefile "myvariables.py;argument:with:colons"
--variablefile C:\path\variables.py;D:\data.xls

Variables in these variable files are globally available in all test data files, similarly as individual variables set with the --variable option. If both
--variablefile and --variable options are used and there are variables with same names, those that are set individually with --variable option
take precedence.

Creating variables directly
Basic syntax
When variable files are taken into use, they are imported as Python modules and all their global attributes that do not start with an underscore (_) are
considered to be variables. Because variable names are case-insensitive, both lower- and upper-case names are possible, but in general, capital letters are
recommended for global variables and attributes.
VARIABLE = "An example string"
ANOTHER_VARIABLE = "This is pretty easy!"
INTEGER = 42
STRINGS = ["one", "two", "kolme", "four"]
NUMBERS = [1, INTEGER, 3.14]
MAPPING = {"one": 1, "two": 2, "three": 3}

In the example above, variables ${VARIABLE}, ${ANOTHER VARIABLE}, and so on, are created. The first two variables are strings, the third one is an
integer, then there are two lists, and the final value is a dictionary. All these variables can be used as a scalar variable, lists and the dictionary also a list
variable like @{STRINGS} (in the dictionary's case that variable would only contain keys), and the dictionary also as a dictionary variable like &
{MAPPING}.
To make creating a list variable or a dictionary variable more explicit, it is possible to prefix the variable name with LIST__ or DICT__, respectively:
from collections import OrderedDict
LIST__ANIMALS = ["cat", "dog"]
DICT__FINNISH = OrderedDict([("cat", "kissa"), ("dog", "koira")])

These prefixes will not be part of the final variable name, but they cause Robot Framework to validate that the value actually is list-like or dictionary-like.
With dictionaries the actual stored value is also turned into a special dictionary that is used also when creating dictionary variables in the Variable table.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

97/263

6/24/2018

Robot Framework User Guide

Values of these dictionaries are accessible as attributes like ${FINNISH.cat}. These dictionaries are also ordered, but preserving the source order
requires also the original dictionary to be ordered.
The variables in both the examples above could be created also using the Variable table below.
*** Variables ***
${VARIABLE}
${ANOTHER VARIABLE}
${INTEGER}
@{STRINGS}
@{NUMBERS}
&{MAPPING}
@{ANIMALS}
&{FINNISH}

An example string
This is pretty easy!
${42}
one
two
${1}
${INTEGER}
one=${1}
two=${2}
cat
dog
cat=kissa
dog=koira

kolme
${3.14}
three=${3}

four

Note
Variables are not replaced in strings got from variable files. For example, VAR = "an ${example}" would create variable ${VAR} with a literal string value
an ${example} regardless would variable ${example} exist or not.

Using objects as values
Variables in variable files are not limited to having only strings or other base types as values like variable tables. Instead, their variables can contain any
objects. In the example below, the variable ${MAPPING} contains a Java Hashtable with two values (this example works only when running tests on
Jython).
from java.util import Hashtable
MAPPING = Hashtable()
MAPPING.put("one", 1)
MAPPING.put("two", 2)

The second example creates ${MAPPING} as a Python dictionary and also has two variables created from a custom object implemented in the same file.
MAPPING = {'one': 1, 'two': 2}
class MyObject:
def __init__(self, name):
self.name = name
OBJ1 = MyObject('John')
OBJ2 = MyObject('Jane')

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

98/263

6/24/2018

Robot Framework User Guide

Creating variables dynamically
Because variable files are created using a real programming language, they can have dynamic logic for setting variables.
import os
import random
import time
USER = os.getlogin()
RANDOM_INT = random.randint(0, 10)
CURRENT_TIME = time.asctime()
if time.localtime()[3] > 12:
AFTERNOON = True
else:
AFTERNOON = False

# current login name
# random integer in range [0,10]
# timestamp like 'Thu Apr 6 12:45:21 2006'

The example above uses standard Python libraries to set different variables, but you can use your own code to construct the values. The example below
illustrates the concept, but similarly, your code could read the data from a database, from an external file or even ask it from the user.
import math
def get_area(diameter):
radius = diameter / 2
area = math.pi * radius * radius
return area
AREA1 = get_area(1)
AREA2 = get_area(2)

Selecting which variables to include
When Robot Framework processes variable files, all their attributes that do not start with an underscore are expected to be variables. This means that
even functions or classes created in the variable file or imported from elsewhere are considered variables. For example, the last example would contain
the variables ${math} and ${get_area} in addition to ${AREA1} and ${AREA2}.
Normally the extra variables do not cause problems, but they could override some other variables and cause hard-to-debug errors. One possibility to
ignore other attributes is prefixing them with an underscore:
import math as _math
def _get_area(diameter):
radius = diameter / 2.0
area = _math.pi * radius * radius
return area
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

99/263

6/24/2018

Robot Framework User Guide

AREA1 = _get_area(1)
AREA2 = _get_area(2)

If there is a large number of other attributes, instead of prefixing them all, it is often easier to use a special attribute __all__ and give it a list of attribute
names to be processed as variables.
import math
__all__ = ['AREA1', 'AREA2']
def get_area(diameter):
radius = diameter / 2.0
area = math.pi * radius * radius
return area
AREA1 = get_area(1)
AREA2 = get_area(2)

Note
The __all__ attribute is also, and originally, used by Python to decide which attributes to import when using the syntax from modulename import *.

Getting variables from a special function
An alternative approach for getting variables is having a special get_variables function (also camelCase syntax getVariables is possible) in a
variable file. If such a function exists, Robot Framework calls it and expects to receive variables as a Python dictionary or a Java Map with variable names
as keys and variable values as values. Created variables can be used as scalars, lists, and dictionaries exactly like when creating variables directly, and it
is possible to use LIST__ and DICT__ prefixes to make creating list and dictionary variables more explicit. The example below is functionally identical to
the first creating variables directly example.
def get_variables():
variables = {"VARIABLE ": "An example string",
"ANOTHER VARIABLE": "This is pretty easy!",
"INTEGER": 42,
"STRINGS": ["one", "two", "kolme", "four"],
"NUMBERS": [1, 42, 3.14],
"MAPPING": {"one": 1, "two": 2, "three": 3}}
return variables

can also take arguments, which facilitates changing what variables actually are created. Arguments to the function are set just as any
other arguments for a Python function. When taking variable files into use in the test data, arguments are specified in cells after the path to the variable
file, and in the command line they are separated from the path with a colon or a semicolon.
get_variables

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

100/263

6/24/2018

Robot Framework User Guide

The dummy example below shows how to use arguments with variable files. In a more realistic example, the argument could be a path to an external text
file or database where to read variables from.
variables1 = {'scalar': 'Scalar variable',
'LIST__list': ['List','variable']}
variables2 = {'scalar' : 'Some other value',
'LIST__list': ['Some','other','value'],
'extra': 'variables1 does not have this at all'}
def get_variables(arg):
if arg == 'one':
return variables1
else:
return variables2

Implementing variable file as Python or Java class
Starting from Robot Framework 2.7, it is possible to implement variables files as Python or Java classes.
Implementation
Because variable files are always imported using a file system path, creating them as classes has some restrictions:
Python classes must have the same name as the module they are located.
Java classes must live in the default package.
Paths to Java classes must end with either .java or .class. The class file must exists in both cases.
Regardless the implementation language, the framework will create an instance of the class using no arguments and variables will be gotten from the
instance. Similarly as with modules, variables can be defined as attributes directly in the instance or gotten from a special get_variables (or
getVariables) method.
When variables are defined directly in an instance, all attributes containing callable values are ignored to avoid creating variables from possible methods
the instance has. If you would actually need callable variables, you need to use other approaches to create variable files.
Examples
The first examples create variables from attributes using both Python and Java. Both of them create variables ${VARIABLE} and @{LIST} from class
attributes and ${ANOTHER VARIABLE} from an instance attribute.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

101/263

6/24/2018

Robot Framework User Guide

class StaticPythonExample(object):
variable = 'value'
LIST__list = [1, 2, 3]
_not_variable = 'starts with an underscore'
def __init__(self):
self.another_variable = 'another value'
public class StaticJavaExample {
public static String variable = "value";
public static String[] LIST__list = {1, 2, 3};
private String notVariable = "is private";
public String anotherVariable;

}

public StaticJavaExample() {
anotherVariable = "another value";
}

The second examples utilizes dynamic approach for getting variables. Both of them create only one variable ${DYNAMIC VARIABLE}.
class DynamicPythonExample(object):
def get_variables(self, *args):
return {'dynamic variable': ' '.join(args)}
import java.util.Map;
import java.util.HashMap;
public class DynamicJavaExample {

}

public Map getVariables(String arg1, String arg2) {
HashMap variables = new HashMap();
variables.put("dynamic variable", arg1 + " " + arg2);
return variables;
}

Variable file as YAML
Variable files can also be implemented as YAML files. YAML is a data serialization language with a simple and human-friendly syntax. The following
example demonstrates a simple YAML file:
string:
integer:
list:

Hello, world!
42

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

102/263

6/24/2018

Robot Framework User Guide

- one
- two
dict:
one: yksi
two: kaksi
with spaces: kolme

Note
Using YAML files with Robot Framework requires PyYAML module to be installed. If you have pip installed, you can install it simply by running pip
install pyyaml.
YAML support is new in Robot Framework 2.9. Starting from version 2.9.2, the standalone JAR distribution has PyYAML included by default.

YAML variable files can be used exactly like normal variable files from the command line using --variablefile option, in the settings table using
Variables setting, and dynamically using the Import Variables keyword. The only thing to remember is that paths to YAML files must always end with
.yaml extension.
If the above YAML file is imported, it will create exactly the same variables as the following variable table:
*** Variables
${STRING}
${INTEGER}
@{LIST}
&{DICT}

***
Hello, world!
${42}
one
two
one=yksi
two=kaksi

YAML files used as variable files must always be mappings in the top level. As the above example demonstrates, keys and values in the mapping
become variable names and values, respectively. Variable values can be any data types supported by YAML syntax. If names or values contain nonASCII characters, YAML variables files must be UTF-8 encoded.
Mappings used as values are automatically converted to special dictionaries that are used also when creating dictionary variables in the variable table.
Most importantly, values of these dictionaries are accessible as attributes like ${DICT.one}, assuming their names are valid as Python attribute names. If
the name contains spaces or is otherwise not a valid attribute name, it is always possible to access dictionary values using syntax like &{DICT}[with
spaces] syntax. The created dictionaries are also ordered, but unfortunately the original source order of in the YAML file is not preserved.

2.8 Advanced features
2.8.1 Handling keywords with same names
Keyword scopes
Specifying a keyword explicitly
Specifying explicit priority between libraries and resources
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

103/263

6/24/2018

Robot Framework User Guide

2.8.2 Timeouts
Test case timeout
User keyword timeout
2.8.3 For loops
Normal for loop
Nested for loops
Using several loop variables
For-in-range loop
For-in-enumerate loop
For-in-zip loop
Exiting for loop
Continuing for loop
Removing unnecessary keywords from outputs
Repeating single keyword
2.8.4 Conditional execution
2.8.5 Parallel execution of keywords

2.8.1 Handling keywords with same names
Keywords that are used with Robot Framework are either library keywords or user keywords. The former come from standard libraries or external
libraries, and the latter are either created in the same file where they are used or then imported from resource files. When many keywords are in use, it is
quite common that some of them have the same name, and this section describes how to handle possible conflicts in these situations.

Keyword scopes
When only a keyword name is used and there are several keywords with that name, Robot Framework attempts to determine which keyword has the
highest priority based on its scope. The keyword's scope is determined on the basis of how the keyword in question is created:
1. Created as a user keyword in the same file where it is used. These keywords have the highest priority and they are always used, even if there are
other keywords with the same name elsewhere.
2. Created in a resource file and imported either directly or indirectly from another resource file. This is the second-highest priority.
3. Created in an external test library. These keywords are used, if there are no user keywords with the same name. However, if there is a keyword
with the same name in the standard library, a warning is displayed.
4. Created in a standard library. These keywords have the lowest priority.

Specifying a keyword explicitly
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

104/263

6/24/2018

Robot Framework User Guide

Scopes alone are not a sufficient solution, because there can be keywords with the same name in several libraries or resources, and thus, they provide a
mechanism to use only the keyword of the highest priority. In such cases, it is possible to use the full name of the keyword, where the keyword name is
prefixed with the name of the resource or library and a dot is a delimiter.
With library keywords, the long format means only using the format LibraryName.Keyword Name. For example, the keyword Run from the
OperatingSystem library could be used as OperatingSystem.Run, even if there was another Run keyword somewhere else. If the library is in a module or
package, the full module or package name must be used (for example, com.company.Library.Some Keyword). If a custom name is given to a library
using the WITH NAME syntax, the specified name must be used also in the full keyword name.
Resource files are specified in the full keyword name, similarly as library names. The name of the resource is derived from the basename of the resource
file without the file extension. For example, the keyword Example in a resource file myresources.html can be used as myresources.Example. Note that
this syntax does not work, if several resource files have the same basename. In such cases, either the files or the keywords must be renamed. The full
name of the keyword is case-, space- and underscore-insensitive, similarly as normal keyword names.

Specifying explicit priority between libraries and resources
If there are multiple conflicts between keywords, specifying all the keywords in the long format can be quite a lot work. Using the long format also
makes it impossible to create dynamic test cases or user keywords that work differently depending on which libraries or resources are available. A
solution to both of these problems is specifying the keyword priorities explicitly using the keyword Set Library Search Order from the BuiltIn library.
Note
Although the keyword has the word library in its name, it works also with resource files. As discussed above, keywords in resources always
have higher priority than keywords in libraries, though.

The Set Library Search Order accepts an ordered list or libraries and resources as arguments. When a keyword name in the test data matches multiple
keywords, the first library or resource containing the keyword is selected and that keyword implementation used. If the keyword is not found from any of
the specified libraries or resources, execution fails for conflict the same way as when the search order is not set.
For more information and examples, see the documentation of the keyword.

2.8.2 Timeouts
Keywords may be problematic in situations where they take exceptionally long to execute or just hang endlessly. Robot Framework allows you to set
timeouts both for test cases and user keywords, and if a test or keyword is not finished within the specified time, the keyword that is currently being
executed is forcefully stopped. Stopping keywords in this manner may leave the library or system under test to an unstable state, and timeouts are
recommended only when there is no safer option available. In general, libraries should be implemented so that keywords cannot hang or that they have
their own timeout mechanism, if necessary.
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#pypy-installation

105/263

6/24/2018

Robot Framework User Guide

Test case timeout
The test case timeout can be set either by using the Test Timeout setting in the Setting table or the [Timeout] setting in the Test Case table. Test Timeout in
the Setting table defines a default test timeout value for all the test cases in the test suite, whereas [Timeout] in the Test Case table applies a timeout to an
individual test case and overrides the possible default value.
Using an empty [Timeout] means that the test has no timeout even when Test Timeout is used. It is also possible to use value NONE for this purpose.
Regardless of where the test timeout is defined, the first cell after the setting name contains the duration of the timeout. The duration must be given in
Robot Framework's time format, that is, either directly in seconds or in a format like 1 minute 30 seconds. It must be noted that there is always some
overhead by the framework, and timeouts shorter than one second are thus not recommended.
The default error message displayed when a test timeout occurs is Test timeout