With 5000+ stars and 1500+ forks on GitHub, Robot framework has been a go-to-option for many organizations who are aiming for Agile and Test Driven Development (TDD) where developers should write functional code only when there is a test that has failed. Robot framework allows acceptance testing, behaviour driven testing, Robotic Process Automation (RPA), and Acceptance test-driven development (ATDD).

It offers an extensible keyword driven approach to perform automation testing. The learning curve is simple as you don’t need to have a programming experience to get started with the Robot framework.

Robot framework is written in Python, however, it is not restricted to that. You can implement keywords in Robot framework using Python, Java, JavaScript, Perl, .Net and PHP.

This Robot framework tutorial will help you run your first Selenium testing script with Python. Further, we will look into running automation scripts for more complex scenarios using Robot and Selenium. Selenium would be used to implement automated browser testing using keyword driven testing with Robot in Python.

What Is Keyword-Driven Testing(Table-Driven Testing)?

Keyword-driven testing is a form of testing where data tables are developed with relevant keywords and the keywords being used are agnostic of the test framework being used for testing. The purpose of the keywords is to broadly describe the actions that need to be performed for a particular test.

The primary advantage of keyword-driven testing is that testers can make use of keywords to describe the action of a particular test. It can be used for both manual and automated testing.

There are different types of keywords.

  1. Higher-level keywords – These keywords can be used to test particular aspects of a system.
  2. Lower-level keywords – These keywords describe the actual functionality testing which is a combination of a number of lower-level keywords.
  3. Technical keywords – These are the ones that are used to execute the tests.

Hence, in a keyword-driven test, you need to first identify the right set of higher-level and lower-level keywords and then associate actions with these keywords.

For example, if you are responsible for testing the login screen of a banking website, your keywords would be Open Browser, Login, Enter password, Logout, Close Browser, etc. All these keywords are self-explanatory and this is what makes keyword-driven testing more effective.

Now that we have touched upon the basics of keyword-driven testing, let’s deep dive into the architecture of Robot framework.

Robot Framework Architecture

Robot framework has a highly modular architecture as seen in the figure below. It is a technology-independent framework that uses keyword-driven testing. Users can create higher-level keywords from the existing keywords. Along with the generation of keywords, users can also create test libraries in different programming languages.

Robot Framework Architecture

Test Data

Test data, the first layer of the Robot framework is in a tabular format. Since the data is in a tabular format, maintaining the data is very easy. This test data is the input to the Robot framework and once it receives the test data, it starts processing the test data and on execution, it generates reports & logs. The report is in HTML and XML format. The generated reports offer detailed information about every line that is executed as a part of the test case.

Robot Framework

The primary advantage of the Robot framework is that it is agnostic of the target under test. The interaction with the layers below the framework can be done using the libraries [built-in or user-created] that make use of application interfaces.

Test Libraries & Test Tools

Since the Robot framework only interacts with the other layers in the system using libraries, it makes the code portable and maintainable. Libraries are normally imported at the start of the implementation [in the *** Settings *** section], example is shown below

*** Settings ***
Library  Selenium2Library
……………………………..

*** Variables ***
……………………………..
……………………………..

System Under Test

This is the actual target on which the testing activity is performed. It could either be a website or a web app. Libraries act as an interface between the Robot Framework and the system under test. Hence, there is no way through which the framework can directly talk to the system under test. The Robot framework supports various file formats namely HTML, TSV (Tab Separated Values), reST (Restructured Text), and Plain text. As per the official documentation of Robot framework, the plain text format is recommended.

Prerequisites for Robot Framework Tutorial with Python and Selenium

So far in this Robot framework tutorial, we have covered the basics of Robot framework and the building blocks that constitute the framework. Let’s set up the prerequisites for running Robot framework with Selenium.

Here is everything you need for this Robot framework tutorial:

  1. An IDE, download PyCharm Community Edition
  2. Install the Intellibot Plugin in PyCharm for Robot framework.
  3. Install Robot framework
  4. Specify Selenium as an external test library.

Let us look at each of these, one by one.

Install The Intellibot Plugin

Once you have installed the PyCharm IDE, you need to install the Intellibot plugin for Robot framework. Go to File -> Settings -> Plugins -> Search for Intellibot in the plugins marketplace -> Install the plugin -> Restart the IDE.

Install The Robot Framework

To install Robot framework, please execute the below command in the terminal section of PyCharm IDE.

pip install robotframework

Once installed, you can check the version of the Robot framework being used by using the command:

robot–version

pip installation

The Robot framework supports a number of command-line options and covering each option is beyond the scope of this Robot framework tutorial. You can execute the following command to get more information about each option.

robot --help

Automation Framework

Install Selenium Library For Robot Framework

The Robot framework has a set of Robot standard libraries that are supported along with the framework. Usage of these libraries does not require installation of a separate module. Some of the standard libraries that are included in the normal installation are:

  1. Operating System
  2. Remote
  3. Process
  4. Reserved
  5. Screenshot
  6. String
  7. Telnet
  8. XML
  9. DateTime

You can find the complete list by visiting the official documentation of robot.libraries package. Any test library that is not a part of the standard libraries is considered as an external library.
There are a number of external libraries that are created by the Robot framework open-source community. To install , you just need to initiate the below command from the terminal.

pip install <robotframework-externallibrarypackage>

As we would be using the Robot framework with Selenium, the next step in the Robot Framework tutorial is to install the SeleniumLibrary as an external test library to Robot. In order to install the SeleniumLibrary, run the below command on the terminal.

pip install robotframework-SeleniumLibrary

Terminal SeleniumLibrary

The SeleniumLibary is mandatory for automation testing with Selenium & Python using the Robot framework. SeleniumLibrary supports Python version 2.7, 3.4, or newer. This library is forked from Selenium2Library, hence you can also install the same library using the below command.

pip install robotframework-Selenium2Library

Other than the Robot framework for Selenium with Python, the SeleniumLibrary also offers support with PyPy and Jython; though these topics would not be covered as a part of this Robot framework tutorial. I would be sure to cover them in my upcoming articles so make sure to hit the bell icon on blog to stay tuned.

Apart from Selenium, some of the other popular Robot External Libraries are

  1. HTTP
  2. Database
  3. SSH
  4. Android
  5. iOS
  6. MongoDB

Here is a simplistic view of the .robot script/file which contains all of the necessary libraries both internal and external which might be utilized by the test cases.

Robotscript

Also Read: Parallel testing in Selenium with Python

Now that you have everything set up correctly, it is time to get your hands dirty with Robot and Selenium test execution.

Should You Use Robot Framework or Selenium WebDriver, or Both?

Many developers & testers have the confusion whether they should use Robot framework or Selenium WebDriver in itself would suffice. There is a huge difference between both of them – Robot is a test framework that makes use of test libraries (standard & external) to execute tests, whereas Selenium is only a WebDriver/library that requires the support of test automation runners in order to perform test execution.

Robot framework can be used to perform different types of automated tests, whether these tests are about UI testing or API level testing. SeleniumLibrary module which was described above enables Selenium framework support in Robot.

The SeleniumLibrary interfaces with the Selenium WebDriver, which in turn executes the commands on the respective browser under test. The interaction between the SeleniumLibrary and Selenium WebDriver is abstracted from the developer of the test script.

So yes, you need both Selenium WebDriver and the Robot framework.

Run Your First Robot Framework Script With Selenium And Python

Test cases using the Robot framework are created using Keywords. As a part of the SeleniumLibrary, a number of Keywords can be used for Test Suite implementation. Before using the Keywords, you need to first import the SeleniumLibrary in the Robot script (in the *** Settings *** section), this can be done using Library SeleniumLibrary or Library Selenium2Library.

Here are some of the most prominently used Keywords from the SeleniumLibrary.

SeleniumLibrary Keywords

However, the choice of keywords would depend on your test suite or test case. You can have a look at all the Keywords supported by SeleniumLibrary in the official documentation of SeleniumLibrary Keywords.

It is now time to get to the crux of this Robot framework tutorial and have a look at a sample implementation that uses Robot Framework and SeleniumLibrary.

Test Scenario 1: Perform a Google search with the search query ‘LambdaTest’.

Keywords to use –

Wait Until Page Contains, Wait Until Element Is Visible, Input Text, and Submit Form. Since these Keywords are part of the SeleniumLibary/Selenium2Libary, the required library is imported before we start the actual operation.

*** Settings ***
Library  Selenium2Library
Suite Setup     Open browser    ${URL}   ${BROWSER}
Suite Teardown  Close All Browsers


*** Variables ***
${URL}              http://www.google.com
${BROWSER}          Chrome
# Alternately you can also use xpath=//*[@id="tsf"]/div[2]/div/div[1]/div/div[1]/input
${search_form}      css=form[name=f]
${search_query}     css=input[name=q]

${search_term}      LambdaTest

*** Test Cases ***
Google Search
    Wait Until Page Contains      ${URL}
    Wait Until Element Is Visible  ${search_form}
    Wait Until Element Is Visible  ${search_query}
    Input Text      ${search_query}   ${EMPTY}
    Input Text      ${search_query}   ${search_term}
    Submit Form

In order to get information about each element located in the URL under test (google.com), we make use of the Inspect feature in Chrome.

Google

You can execute the code using the command robot