Robot Framework Hands On Workshop
Robot Framework Hands On Workshop
2 / 48
Trainers
Siili Solutions
3 / 48
Introduction
Welcome to the course!
4 / 48
What is Robot Framework?
Keyword-driven test automation framework
Tests written using natural language
Open source, Apache License 2.0
Implemented with Python
https://robotframework.org/
5 / 48
What is Robot Framework?
The first version was developed at Nokia Networks in 2005 (by
Pekka Klärck)
Version 2.0 was released as open source in 2008
Nowadays sponsored by Robot Framework Foundation
A non-profit consortium of approximately 30 member companies
6 / 48
Users of Robot Framework
Nokia
Cisco
ABB
Kone
U.S. Naval Research Laboratory
...and more
https://robotframework.org/#users
7 / 48
Getting started
Basic tools
We'll be working with the command line and an editor.
9 / 48
Good code editor
Recommended:
PyCharm
Atom
Sublime Text
VSCode
10 / 48
Development environment
You should always use a virtual environment when developing Python
software. Python 3 has built in venv:
Linux/MacOS: Windows:
11 / 48
Installing Robot Framework
Robot Framework is a Python library so you can install it with pip:
12 / 48
Exercise
Set up your Python environment
13 / 48
Basics of Robot Framework
Terminology
Test Suite
Test Case
Keyword
Libraries
Resources
15 / 48
Syntax
Plain text
File extension .robot
Space separated (min. 2)
Keyword and test case blocks are defined with indents
Code editor support
16 / 48
Syntax: suite example
*** Settings ***
Library SeleniumLibrary
17 / 48
Available libraries
BuiltIn AppiumLibrary
Collections SapGuiLibrary
Dialogs SeleniumLibrary
Screenshot WhiteLibrary
String TOSLibrary
18 / 48
BuiltIn library
The BuiltIn library includes some often needed keywords, e.g.
Log
Set Variable
Should Be Equal
Sleep
Run Keyword If
Fail
Convert To Integer
19 / 48
About the Robot Framework parser
The keyword libraries are not magic, they are Python code!
Print Sum 1 5
20 / 48
Exercise
We'll build a simple test suite in the project directory.
21 / 48
Exercise
Your solution should look something like this:
22 / 48
Running Robot Framework tests
robot <test_suite_file>
report.html
log.html
output.xml
23 / 48
Exercise
Run your previously created test suite and look at the output files.
24 / 48
Exercise
Run your previously created test suite and look at the output files.
Once the run has completed you should be seeing something like this:
==============================================================================
First Test Suite
==============================================================================
Logging Test | PASS |
------------------------------------------------------------------------------
First Test Suite | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\exercise\output.xml
Log: C:\exercise\log.html
Report: C:\exercise\report.html
24 / 48
Variables
String: ${MY_VARIABLE}
List: @{MY_VARIABLES}
Dictionary: &{MY_MAPPING}
25 / 48
Keyword arguments
Defining arguments for user keywords:
You can then pass variables as arguments when calling the keyword:
26 / 48
Exercise
Modify your previous test suite:
27 / 48
Best practices
Ideal project structure
├── libraries
│ └── DemoLibrary.py
├── resources
│ ├── demo_keywords.robot
│ └── settings.py
├── test_cases
│ └── main_test_suite.robot
└── README
29 / 48
Ideal project structure
├── test_cases
│ └── main_test_suite.robot
31 / 48
Configuration
├── resources
│ ├── settings.py
excel_path = "test_input.xlsx"
sheet_name = "Sheet1"
32 / 48
Python libraries
├── libraries
│ └── InputExcelReader.py
import openpyxl
class InputExcelReader:
33 / 48
Debugging in Robot Framework
There is no real working debugger for Robot Framework. However, you
can pause the execution with Pause Execution keyword. For this
to work, you have to import library Dialogs:
And you can use Log Variables to log all variable values to RF log.
34 / 48
Automating the Web
SeleniumLibrary
Web automation is the most common and best supported by Robot
Framework.
36 / 48
Webdrivers
You also need a browser and a web driver. Recommended are Google
Chrome and chromedriver.
and then
webdrivermanager chrome
37 / 48
Locators
Locators specify the GUI elements used in keywords.
In Chrome you can find locators for elements by right clicking on them
and selecting Inspect.
38 / 48
Locators
Locators specify the GUI elements used in keywords.
In Chrome you can find locators for elements by right clicking on them
and selecting Inspect.
id
name
class
xpath
...
38 / 48
Exercise
Create a test case which does the following using SeleniumLibrary:
39 / 48
Exercise: Example solution (1/2)
*** Settings ***
Documentation SeleniumLibrary demo
Library SeleniumLibrary
40 / 48
Exercise: Example solution (2/2)
*** Keywords ***
Open duckduckgo
[Documentation] Open Duck Duck Go Search engine
... with Chrome browser.
Open Browser ${duck_url} gc
Input query
Input text id:search_form_input_homepage Robot Framework
Click Search
Click Element id:search_button_homepage
41 / 48
More Robot Framework
Setup & Teardown
Setup specifies the actions to be performed before test execution, and
teardown specifies the actions after the test execution.
Teardown is executed despite the test result (pass, fail, interrupted, ...)
43 / 48
Setup & Teardown
*** Settings ***
Suite Teardown Clean Up
44 / 48
Tags
Test cases can be labeled with tags:
Second Example
[Tags] smoke not_ready
Do Something Else
Third Example
[Tags] dummy
Do Something Completely Different
Tags can be used to include or exclude cases when running the tests:
45 / 48
Data Driver Testing
Robot Framework supports test templates which provide an easy way
to move from keyword-driven test cases to data-driven tests.
46 / 48
And much more...
https://robotframework.org/
Robot Framework User Guide
47 / 48
And much more...
https://robotframework.org/
Robot Framework User Guide
47 / 48
Thanks!