Robot Framework: Stairway to hassle-free test automation
By: Avtar Krishna Jha
Tags: Selenium, Testing, Automation, Robot Framework, Appium

TARGET AUDIENCE

Anyone who wants to learn test automation without knowing how to code

Anyone who is familiar with test automation but wants to save enormous amount of time spent on creating and maintaining frameworks/ test scripts, converting complex logics to code and integrating it with third-party tools

PRE-REQUISITE

Absolutely nothing. Well, except for a computer and an enthusiasm to learn.

WHAT IS ROBOT FRAMEWORK?

Robot Framework is a general-purpose automation framework that serves as one-stop shop for most of your test automation needs and robotic process automation. Using Robot Framework, one can automate web, mobile, REST/SOAP api, databases etc. This is not the only part that is exciting, the beauty of this tool is that you get to automate these things without writing any complex code with confusing syntax. YOU HEARD ME RIGHT!!!.

Robot Framework is open and extensible and can be integrated with virtually any other tool (Selenium, Appium, Playwright, SikuliX, TestFX, White Framework and many more) to create powerful and flexible automation solutions.

It is operating system and application independent. It has easy syntax that is written utilising human readable keywords. Its capabilities can be extended by libraries implemented with Python or Java (Don’t worry, there are a plenty of existing libraries and you wouldn’t have to write any python or java code)

WHY SHOULD YOU USE ROBOT FRAMEWORK?

Before answering why, ask yourself following questions —

Are you looking for a tool that can cater to all your automation needs like web, mobile apps, api, database etc? Are you looking for a tool that can define test cases and all the underlying logic in a readable format? Are you looking for a solution that can be readily plugged in with any CICD tool? Are you keen on not squandering your time and resources in creating and maintaining automation framework? Are you looking for a tool that has an extremely lean learning curve?

If your answer is yes to any/all of the above questions, then this tool is for you.

HOW TO USE ROBOT FRAMEWORK?

If you’ve read through the What and Why section above and are enthralled by the possibilities of what you can do with the tool, please be patient, we’ll work together step by step and create magic

First things first

Install python from Python downloads section. All python versions > 3.4.0 should work. (At the time of writing this blog, I am on python version 3.8.0). Check that pip is available. Open terminal/ command prompt and run

python -m pip --version

Depending on the installation, you might have to use python/python3 to access python executable. Similar is the case with pip. So, in case the following commands don’t work, substitute them with pip3

3. Install Robot Framework and other necessary libraries

# This will install Robot Framework

pip install robotframework

# This will install selenium library used for automating web browser

pip install robotframework-seleniumlibrary

I highly recommend Robot IDE for working with Robot Framework. But, if you are very comfortable with other IDEs, please refer https://robotframework.org/#tools to install plugins for robot framework. At the time of writing this, robot IDE 2.0 is in pre-release. Please check https://github.com/robotframework/RIDE before running commands mentioned below.

# This will install robot IDE which is a standalone IDE.

pip install psutil

pip install -U --pre robotframework-ride

CONGRATULATIONS! You are all set to write your test cases now.

But, before we start writing tests, let’s understand some core concepts.

CORE CONCEPTS

Syntax

The following sections will explain how to actually create test cases, test suites and so on.

Files & Directories

The hierarchical structure for arranging test cases is built as follows:

Test cases are created in a test case file that in turn automatically creates a test suite containing the test cases in that file.

A test suite could also be a directory which can contain other test suite directories, and this hierarchical structure can be as deeply nested as needed.

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.

Sections in a Robot File

You can notice a gap between robot framework keywords and its value (example gap between keyword Library and its value SeleniumLibrary) from the image above. In robot framework, there should be a gap of 4 spaces/ 1 tab between any keyword and value.

Library

Libraries provide the actual automation and testing capabilities to Robot Framework by providing keywords. In the installation steps above, we have installed SeleniumLibrary which provides all the capabilities of Selenium using Keywords. You need to mention the library under **** Settings *** section in a robot file that contains test case/ keywords.

Keywords

In Robot Framework, any action that you want to perform is a keyword. Libraries contain keywords. For example Open Browser is a keyword in SeleniumLibrary. The keywords can be categorised into two, low level keywords and high level keywords/ user keywords.

Low level keywords are keywords that are contained in libraries. An example of a low level keyword is Open Browser from SeleniumLibrary

High level keywords are defined by users using the low-level keywords. For example Navigate to Google Homepage is a high level keyword which used a low level keyword Open Browser. Refer the image below.

Each and every library has a documentation which tells all the details about keywords like what arguments does the keyword expects and if that returns any value. Refer the link to see the details for Open Browser keyword.

UNDERSTAND THIS CAREFULLY !!!!

From the image below, you’ll see that Open Browser keyword expects url, browser, alias, remote_url etc as arguments. But, they have a default value, written after ‘=’, in case the user doesn’t want to specify all/any of them. If, there is no ‘=’ sign after an argument, it is mandatory and user has to provide a value for it, else the keyword will throw error.

The arguments need to be in the order in which they are defined in the keyword documentation. Although, writing the argument name is not mandatory. For example in the case of Open Browser keyword, user could write in either ways shown below

Back to the track !!!

Writing Test Cases

Writing a test case would consist of following steps

Create a Test Suite Import Library under the *** Settings *** section Write user defined high level keywords under the *** Keywords *** section using low level keywords from the library Create a Test Case in the suite under the *** Test Cases *** section

TA DA!!!

Let’s see How would the overall structure and the test case file look in Robot IDE

Test Case File / Test Suite

All the pictures above were to make you understand the concepts. In reality, the test cases and user keywords are much more easier to create and read in Robot IDE. Below is a snapshot of the same test as the one above i.e. ‘Hello Selenium’.

Overall Structure

STEPS TO CREATE TEST CASES USING GUI(SPECIFIC TO ROBOT IDE)

Right click on a project and create Test Suite. Keep the format as ROBOT. Choose Type as per your need

Import a library by clicking on Library button in the Test Suite and then defining the name of the library.

Right click on the created suite, and create new Test Case, User keyword or scalar (variable).

HAPPY SCRIPT-LESS CODING!!!!

ERR…. JUST ONE MORE THING

Executing and generating reports in RIDE is a cakewalk.

Select the case you want to run and click on Start button in the Run tab as shown below.

Once, the execution is finished, Click on the Report button adjacent to Execution Profile.

Sample Report

There are more ways in which we can run the tests, using robot command line tool, and pabot for parallel execution best suited for CICD. But, I’ll stop at this point and let you explore the other options. To kickstart your journey with Robot framework, I have also created a demo project that contains one test each for web, mobile and web service. Please refer https://github.com/avtarjha/RobotFramework-Demo

More demos can be found at https://robotframework.org/#learning

Helpful Links

Demo robot framework project for web, mobile and API automation:

https://github.com/avtarjha/RobotFramework-Demo

Helpful youtube tutorials: Rest API testing using Robot Framework

Web Automation using Robot Framework

Tools & IDE: https://robotframework.org/#tools

Robot framework recorder for chrome: https://chrome.google.com/webstore/detail/robotcorder/ifiilbfgcemdapeibjfohnfpfmfblmpd/related

Libraries: https://robotframework.org/#libraries

Comprehensive usage guide: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html

Community:https://robotframework.org/#community