How to Use Robot Framework
This article gives you a brief overview on how to use Robot Framework. You can refer this article to install Robot Framework, write custom library and how to use them to write test cases.
- What is Robot Framework
Robot Framework is automation framework which allows end users to perform one of many following operations(Refer to official guide to know more use cases):
- Write Test Cases to validate Products/APIs.
- Write custom libraries to support API driven tests
- Import libraries to support testing.
If you want to know more about robot framework, you can know more about here: Robot Framework
2. Installation
In this section I will include necessary environment and setup details to use Robot Framework. I will be using virtual env to install/run test cases:
- Install zsh terminal on your machine
- Install virtualenv using virtualenvwrapper this allows end user to work on environment without re-installing it.
sudo pip3 install virtualenvwrapper
mkvirtualenv <virtual_env_name>
pip install robotframework
pip install robotframework-appiumlibrary
- Example for how to use virtual env: workon <virtual_env_name>
- Verify that you have Robot Framework and Python3 installed:
(virtual-dev) ➜ Desktop robot — version
Robot Framework 3.1.2 (Python 3.7.6 on darwin)
On this point following sections assumes that you have a working virtualenv which has robot framework and python3 installed. Use `robot — help` command to see your virtualenv has robot installed.
3. Code Directory Structure
You can follow below standard directory structure to host robot framework codes/libraries/docs etc:
When you create a custom library you can also define a unique name (Example: `galaxy`) and you can use that to retrieve your keywords. I will cover that in following sections.
4. Use Custom Library
Before we jump on creating custom library, lets pick a very simple example where we will create Hello World keyword in a library and use that library in our test case:
1. Create a python file within your directory structure and add below context:
some/path ✗ cat custom_hello.py
def custom_hello():
print(“HELLO WORLD — California!”)
some/path ✗
2. Import created custom library file path in your test case as below:
*** Settings ***
Library custom_hello.py
*** Test Cases ***
Print Hello World # Test Case Name
Custom Hello # Out keyword defined in custom library python file
3. Now run your hello world file using robot command:
So as you can see I have run a hello keyword successfully using a custom library.
5. Key Components
In hello.robot test case you noticed, there are mainly three components which are defined as below:
- Settings : This section includes library, resources, variables files and relevant settings needed to run your test cases
- Keywords: This section includes any custom keywords which are local to your test case/suite files.
- Test Cases: This section includes your test cases which you want to Run.
There might be more core components, so I would recommend to follow official guide.
6. Reports
Once you run any robot test case, it creates three main files related to logs:
- report.html
- output.xml
- log.html
You can either use them locally or feed to report portal as needed.
Example: