Robot FrameWork: The Ultimate Guide To Running Your Tests



Created to function as a Robotic process automation tool, the Robot Framework has developed to evolve into a generic framework. Automation developers and testers also utilize this framework for automation software tests. Selenium WebDriver is one of the vastly utilized tools for accomplishing automation testing on web applications. 

To include the capabilities of Selenium, the Robot Framework internally integrates Selenium WebDriver functionality. This has directed to the innovation of a robust automated website testing tool that must be talked about and set to use. We will also talk about load testing but before let’s look at the robot framework in detail.

Robot Framework

The Robot Framework is created on top of Python and includes many open source tools to deliver a single tool for test automation. The robot delivers the syntax to compose test cases. It gives something akin to a programming language with its set of structure, keywords, and flow.

This tool comprises two fundamental components:

1. Libraries

By default, the framework arrives with a set of built-in libraries. These libraries enable developers to implement test cases. To maintain its modular, third-party libraries can be added to broaden its abilities. While String manipulation, date-time, screenshots, and XML handling libraries come by default, libraries like Django, Android support, and HTTP libraries can be added established on requirements and utilize cases.

2. Tools

Tools are implied to enable maintaining test cases and ease of use. They comprise editing tools like plugins for Eclipse IDE, documentation, built-in tools for logging, and HTML based report generation. Utilizing the Robot Framework includes using both the libraries and tools to create scalable automation test cases.

Robot framework to run automation test case

Selenium library

Since the Robot Framework doesn’t possess all the essential tools to create and enforce automation tests for web applications, testers utilize this to perform. This Selenium-based library enables the Robot Framework to utilize Selenium and conduct web-based operations internally. It can be utilized to replicate a mixture of user actions, from accessing a website to performing all UI operations.

This robot framework will analyze how to write an automation test case.

Writing a Test Case with Robot Framework and Selenium

1. Installation and setup

If one has Python installed, installing the Robot Framework is precise. Simply run the subsequent command.

For thorough instructions and alternate installation procedures, refer to the official installation guide.

Next, install Selenium and run.

To verify successful installation, enforce the command below:

robot –version

If the installation was successful, one will recognize the framework edition.

Before proceeding, assure that the browser driver is in the system way so that Selenium can open the browser. To do so, download the chrome driver and point it under the scripts folder where Python is launched. 

2. Writing an Automation Test Case

This will seek to write a test case to open a browser, navigate to Google, and search for a topic or issue.

Earlier we examined the numerous sections of the test suite, let’s build a file named “my_testcase.robot”. The many sections illustrated below such as settings, keyword definitions, etc would be added to this file.

Step 1. Settings

The very first phase is to configure the settings at the beginning of the file. For our test case, we are required to utilize the Selenium2library. So, importing that is the barely setting we require to configure.

The settings section of the test case:

Settings

Each section in a Robot Framework test case begins followed by the name of the block. The initial line implies that the code block that follows is the setting block. The second line utilizes the “Library” keyword to import the Selenium2Library into context.

Step 2. Defining Variables

The variables block enables defining some constants that probably be utilized throughout the use case. For this test case, two variables will be defined: the “HOMEPAGE” variable, which will store the URL of the website to be opened, and the “BROWSER” variable, which saves data on which browser is to be utilized. 

Variables

${HOMEPAGE} http://www.google.com

${BROWSER} Chrome

Set the HOMEPAGE to be google.com, use the Google Chrome browser to run the test case.

Step 3. Keyword definitions

Keywords in the Robot Framework function contrarily when compared to other programming languages. Robots are expected to create a framework simple to understand, so the keywords are human-readable descriptions. For instance, Selenium2Library arrives with a huge number of predefined keywords like “Open Browser”. This keyword is accountable for opening a browser and loading a webpage.

Furthermore, in a test case, one has to define custom keywords to create operations that are related to the use case. The first keyword is known as ‘open the browser’. It is configured to open a fresh browser window described by the “BROWSER” variable and load the URL initialized in the “HOMEPAGE” variable. Here, “Open Browser” is an in-built keyword of Selenium2Library utilized to open a browser example using Selenium Webdriver.

The second keyword defined here is “search topic”. This keyword is capable of enforcing the following tasks in sequence:

  1. It accepts an argument called “topic.”
  2. It utilizes the “Input Text” in-built keyword to discover an element on the web page and input text.

Here, it utilizes a locator to discover the input component where text can be entered. On the Google homepage, the text box to enter search questions has an attribute called “name” whose value is put to “q”. Here, the Input Text keyword searches for a text box with the word characteristic set to the value “q”. It then types the text given in the argument in step 1.

Eventually, it tries the “Press Key” in-built keyword to simulate the user action of pressing the “Enter” key denoted by “\\13”.

Step 4. Writing Test Cases

Presently, use all the blocks that have been formulated before to write test cases. Let’s disperse the task into two test cases. The first test case opens the homepage on Chrome and the second test case searches for a topic on Google. Each test case has a generic structure. The first line is the name of the test case, and the second line summons the keywords defined in Step 3. The test approves the arguments wherever applicable.

The initial automation test case is “Open browser”. It is enacted if the browser opens the homepage on the mentioned browser. Contrarily, it declines. Another test case is “Search on Google”. Here, it searches for the term “BrowserStack”. If the search is finished, this test case will be noted as successful, else it is marked as a defeat.

Step 5. Running the Test Suite

We are providing the whole test suite as follows:

Settings

Library Selenium2Library

Variables 

${HOMEPAGE} http://www.google.com

${BROWSER} Chrome

Keywords 

open the browser

Open Browser ${HOMEPAGE} ${BROWSER}

search topic

[Arguments] ${topic}

Input Text name=q ${topic}

Press Key name=q \\13

Test Cases 

Open Browser

open the browser

Search on Google

search topic BrowserStack

Store this in a file and name it “my_testcase.robot”. Formerly this file is saved, run it utilizing the robot command:

robot my_testcase.robot

If it’s victorious, the testers will receive the text “pass” against each of the test cases implemented.

To conclude we can say that the Robot Framework is an easy-to-comprehend open-source tool that gives a modular interface to create custom automation test cases. It has been accepted by huge institutions for this purpose, and good reason. As illustrated above, it is particularly useful for automation testers.

It delivers a vast array of keywords along with the possibility to create and utilize one’s keywords. This makes writing test cases much easier and sooner. Altogether, it’s a tremendous tool that can be utilized to test a mixture of strategies and is an important tool in the testers’ toolbox.