Robot Framework Basics

Introduction

Robot Framework is a framework for developing automated acceptance tests (ATDD).

It is a keyword-driven testing framework that provides table formatting

The main ideas for creating Robot Framework were reflected in Pekka Klärck's master's thesis in 2005.

The first version was developed by Nokia Siemens Networks in the same year. Version 2.0 was released under the open source Apache License on June 24, 2008. The framework is written in Python.

You can guess that the framework is Finnish by some Easter eggs, for example in the library OperatingSystem you can find the text Hyv\xe4 esimerkki, which translated from Finnish means good example

Documentation

RobotFramework consists of several libraries, so documentation broken into pieces:

Example

A small example of working with a configured framework. Read about installing RobotFramework here

Go to the directory with tests

cd /soft/src/tests/robot

This directory may contain Makefile , Dockerfile various files from which data is taken to create test environments, and so on.

This is usually set up by DevOps or QA Team Lead

ls -la

total 70 drwxr-xr-x 8 andrei urn_su 4096 Mar 9 12:15 . drwxr-xr-x 9 andrei urn_su 4096 Mar 9 17:45 .. drwxr-xr-x 2 andrei urn_su 4096 Mar 9 12:15 bin -rw-r--r-- 1 andrei urn_su 1534 Mar 9 12:15 Dockerfile -rw-r--r-- 1 andrei urn_su 1293 Mar 9 12:15 Dockerfile.alpine -rw-r--r-- 1 andrei urn_su 38 Mar 9 12:15 .dockerignore drwxr-xr-x 2 andrei 111 4096 Mar 9 12:15 input -rw-r--r-- 1 andrei urn_su 13586 Mar 9 12:15 Makefile drwxr-xr-x 2 andrei 111 4096 Mar 9 12:15 output -rw-r--r-- 1 andrei urn_su 0 Mar 9 12:15 README.md drwxr-xr-x 2 andrei urn_su 4096 Mar 9 12:15 requirements drwxr-xr-x 2 andrei urn_su 4096 Mar 9 12:15 scripts drwxr-xr-x 8 andrei 111 4096 Mar 9 12:15 src

In this example, to create a test environment, you need to run

make dev

More about make read the article «Working with GNUmakefile»

When the environment is active, you can start using the robot.

To call help, run

robot --help

QuickStart

The official quick start guide for RobotFramework can be cloned from github

Documentation

git clone https://github.com/robotframework/QuickStartGuide.git
cd QuickStartGuide
ll

drwxr-xr-x 5 andrei urnsu 4096 May 5 11:25 ./ drwxr-xr-x 5 andrei urnsu 4096 May 5 11:25 ../ -rw-r--r-- 1 andrei urnsu 796 May 5 11:25 BUILD.rst drwxr-xr-x 8 andrei urnsu 4096 May 5 11:25 .git/ drwxr-xr-x 2 andrei urnsu 4096 May 5 11:25 lib/ -rw-r--r-- 1 andrei urnsu 21237 May 5 11:25 QuickStart.rst -rw-r--r-- 1 andrei urnsu 359 May 5 11:25 README.rst drwxr-xr-x 2 andrei urnsu 4096 May 5 11:25 sut/

The project for testing the login is in the directory sut

The script is called login.py

python sut/login.py create andrei HeiHeiru1

SUCCESS

python sut/login.py login andrei HeiHeiru1

Logged In

robot QuickStart.rst

============================================================================== QuickStart ============================================================================== User can create an account and log in | PASS | ------------------------------------------------------------------------------ User cannot log in with bad password | PASS | ------------------------------------------------------------------------------ User can change password | PASS | ------------------------------------------------------------------------------ Invalid password | PASS | ------------------------------------------------------------------------------ User status is stored in database | PASS | ------------------------------------------------------------------------------ QuickStart | PASS | 5 tests, 5 passed, 0 failed ============================================================================== Output: /home/andrei/robotframework/QuickStartGuide/output.xml Log: /home/andrei/robotframework/QuickStartGuide/log.html Report: /home/andrei/robotframework/QuickStartGuide/report.html

Banner image

Your own keywords

In the Keywords section you can declare your own keywords.

In this case the Test Case will be shorter and easier to read.

*** Settings *** Documentation Basic Search Functionality Library SeleniumLibrary *** Variables *** *** Test Cases *** Verify basic search functionality for eBay [Documentation] This test case verifies the basic search [Tags] Functional Start TestCase Verify Search Results Finish TestCase *** Keywords *** Start TestCase Open Browser https://www.ebay.com chrome Input Text //*[@id="gh-ac"] mobile Verify Search Results Click Element id:gh-btn Page Should Contain results for mobile Finish TestCase Close Browser

robot -d results Tests/eBay/BasicSearch.robot

Move the keywords into a separate file

Keeping everything in one file quickly becomes inconvenient.

We will leave the tests themselves in the file BasicSearch.robot and split the keywords into two groups: common and project-specific

BasicSearch.robot

*** Settings *** Documentation Basic Search Functionality Resource ../../Resources/CommonFunctionality.robot Resource ../../Resources/eBay_UserDefinedKeywords.robot *** Variables *** *** Test Cases *** Verify basic search functionality for eBay [Documentation] This test case verifies the basic search [Tags] Functional Start TestCase Verify Search Results Finish TestCase *** Keywords ***

Note that in this file SeleniumLibrary no longer has to be imported

Into the file CommonFunctionality.robot we will move such common actions as open browser, close browser and so on

*** Settings *** Library SeleniumLibrary *** Keywords *** Start TestCase Open Browser https://www.ebay.com chrome Maximize Browser Window Finish TestCase Close Browser

Note line 2. User keywords contain keywords from the SeleniumLibrary library, so it has to be imported in the settings.

Into the file eBayUserDefinedKeywords.robot we will move everything that relates specifically to this project

*** Settings *** Library SeleniumLibrary *** Keywords *** Verify Search Results Input Text //*[@id="gh-ac"] mobile Click Element id:gh-btn Page Should Contain results for mobile Filter Results By Condition Mouse Over //*[@id="w7"] Sleep 3s Mouse Down //*[@id="w7"]/div/ul/li[2] Click Element //*[@id="w7"]/div/ul/li[2] Verify Filter Results Element Should Contain //*[@id="srp-river-results-query_answer1-w0-x-carous

robot -d results Tests/eBay/BasicSearch.robot

============================================================================== BasicSearch :: Basic Search Functionality ============================================================================== Verify basic search functionality for eBay :: This test case verif... | PASS | ------------------------------------------------------------------------------ BasicSearch :: Basic Search Functionality | PASS | 1 test, 1 passed, 0 failed ==============================================================================

If you get the error No keyword with name 'Start TestCase' found

============================================================================== BasicSearch :: Basic Search Functionality ============================================================================== Verify basic search functionality for eBay :: This test case verif... |FAIL | No keyword with name 'Start TestCase' found. ------------------------------------------------------------------------------ BasicSearch :: Basic Search Functionality |FAIL | 1 test, 0 passed, 1 failed ==============================================================================

make sure that at the beginning of BasicSearch.robot you specified the correct path to the files with Resourse CommonFunctionality.robot , eBayUserDefinedKeywords.robot

*** Settings *** Documentation Basic Search Functionality Resource ../../Resources/CommonFunctionality.robot Resource ../../Resources/eBay_UserDefinedKeywords.robot

Test Setup and Test Teardown

The code from the previous example works perfectly in case of success.

However, if the result is FAIL the browser will not close automatically.

To save yourself the need to clean up the environment in case of failure, use Test Setup and Test Teardown

*** Settings *** Documentation Basic Search Functionality Resource ../../Resources/CommonFunctionality.robot Resource ../../Resources/eBay_UserDefinedKeywords.robot Test Setup Start TestCase Test Teardown Finish TestCase *** Variables *** *** Test Cases *** Verify basic search functionality for eBay [Documentation] This test case verifies the basic search [Tags] Functional Verify Search Results Filter Results By Condition Verify Filter Results *** Keywords ***

Explicitly specify the source of a keyword

If user keywords are repeated in different files, a conflict is possible.

To avoid it you can explicitly specify which file the keyword is used from

eBay_UserDefinedKeywords.Verify Search Results eBay_UserDefinedKeywords.Filter Results By Condition eBay_UserDefinedKeywords.Verify Filter Results

Now in the file BasicSearch.robot there is no need to import Selenium Library and write Keywords

Catenate: joining strings

Several string variables can be joined with Catenate

Example: the script caten.robot

*** Settings *** *** Test Cases *** Caten ${site}= Set Variable heihei ${proto}= Set Variable https ${url}= Catenate ${proto}://www.${site}.ru Log To Console \n${url}

robot caten.robot

============================================================================== Caten ============================================================================== Caten ... https://www.heihei.ru Caten | PASS | ------------------------------------------------------------------------------ Caten | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /opt/robot/src/tests/pam/rbac/output.xml Log: /opt/robot/src/tests/pam/rbac/log.html Report: /opt/robot/src/tests/pam/rbac/report.html

Banner image

Date and time

To get the current date you need to import the library DateTime and use the keyword Get Current Date

Library DateTime … ${date}= Get Current Date

The date format will look like

2026-11-15 03:16:24.714

result_format=datetime

For convenient access to the attributes of the object date you can use the argument result_format=datetime

The date format will look like

2026-11-15 03:16:24.918613

To get the month or the year, it is enough to specify the attribute as ${date.month} or ${date.year}

Library DateTime … ${date}= Get Current Date result_format=datetime

An example from my free trainer : checking that the page title is correct; the year in it must match the current one.

*** Settings *** Documentation Checking Title Library Browser ... enable_playwright_debug=${True} ... auto_closing_level=TEST ... retry_assertions_for=0:00:03 Library Collections Library DateTime Force Tags ui *** Variables *** *** Keywords *** Test Setup Tasks Start Chromium Browser Test Teardown Tasks Close Browser Start Chromium Browser New Browser browser=chromium headless=True New Context viewport={'width': 1920, 'height': 1080} ignoreHTTPSErrors=True *** Test Cases *** Italy [Tags] italy New Page https://www.urn.su/qa/ui/basic_test/ ${urls}= Get Elements //a[@class="march8"] # depends on Collections lib Log ${urls} ${url0}= Get From List ${urls} 0 Click ${url0} ${date}= Get Current Date result_format=datetime Log To Console "Check dates" Log To Console ${date} Log To Console ${date.year} Get Title == 8 March in Italy in ${date.year} Close Browser

robot --include italy src/tests/ui/

============================================================================== Ui ============================================================================== Ui.Ui Test Page :: Checking Title ============================================================================== Italy ......"Check dates" .2023-01-03 09:56:18.065095 .2023 Italy Italy | PASS | ------------------------------------------------------------------------------ Ui.Ui Test Page :: Checking Title | PASS | 1 test, 1 passed, 0 failed ============================================================================== Ui | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /opt/tests/robot/output.xml Log: /opt/tests/robot/log.html Report: /opt/tests/robot/report.html

Web UI
Selenium Library
RFBrowser

Article author: Andrei Olegovich