Testing Automation – Robot Framework Vs. Code

Robo Framework Main Image

Is your team looking to implement a quick test automation framework for your application?  If that’s the case, then this article is for you.  Automation has been the prime focus as companies adopt de-centralized remote teams during the pandemic, and when it comes to testing automation, there are many options. Automated tools generally require product experience and licensing cost; however, there is a wide range of free tools to choose from that you can use with little to no experience.  In this article, we are going to discuss one of the popular open-source options for teams with little experience in Selenium and Python.

 

ROBOT FRAMEWORK
Robot framework is a python-based open-source framework for test automation.  It is one of the most popular frameworks on Test-Driven Development (TDD) on the market.  If the team is looking for Behavior-Driven Development (BDD) to enhance collaboration between the product owner, tester, and developers, consider looking into Robot Framework for testing.

In this article, I will focus primarily on the Microsoft Windows platform; however, the framework is Operating System and Language independent.  You are free to use a variety of IDEs, but in this article, I am going to stick with Visual Studio code.

Installation
Let’s start with installation and configuration needs. I am using Windows 11 as my operating system and downloading the latest version of the Python software.

 

Step 1: Install Python

a) Download and install the latest version of Python from https://www.python.org/downloads/

Robo1

 

b) Select the “Customize installation” option

Robo2

 

c) Select all the available options on this wizard screen

(PIP- Package Installer for Python is needed to install libraries)

Robo3

 

d) Select the Advanced Options.  If you are using Visual Studio, also select the last option on this list

Robo4

 

e) Please wait for the installation to complete

Robo5

 

f) Click the “Close” button to complete the setup process

Robo6

 

Step 2: Install Robot Framework Libraries

a) The next step would be to add all the necessary libraries. Check the installed Python version by issuing the following command from the command prompt: python –version

Robo7

 

b) If you get a message like the one below, please upgrade your pip version

Robo8

 

c) Wait for the pip upgrade

Robo9

 

d) Start with installing the Robot Framework

Robo10

 

e) At any time, use “pip list” to list all the installed libraries. The next item in our list is to install Selenium libraries

Robo11

Robo12

 

Step 3: Install The Selenium Browser Web Drivers

a) Our next step is to download the web drivers. I am using Google Chrome, so my plan is to download the driver that matches with the Chrome version. You can get your Chrome version at chrome://settings/help

Go to the following URL to get the list of drivers.
URL: https://www.selenium.dev/downloads/

Robo13

 

b) List of Chromium drivers

Robo14

 

Robo15

 

c) Once you download the correct version, extract the ZIP file

Robo16

 

d) Create a new folder named “Webdrivers” under the Python installation folder. Extract the zip file and copy the chromedriver.exe to this folder. E.g., C:\Program Files\Python310\Webdrivers, since my Python is installed under C:\Program Files\Python310

Robo17

 

e) Next, update the PATH to include this folder. Right click on “This PC” and select Properties

Robo18

 

f) Click Advanced System Settings

Robo19

 

g) On the System properties window, click “Environment variables”

Robo20

 

h) Click on the Edit button after selecting the PATH variable. Please use the one under the “System Variables” section so that it is configured as a system wide setting.

Robo21

 

i) Click New button and enter the Web Driver folder path

Robo22

Robo23

 

j) Click the “OK” Button twice to close the dialogs.

k) Verify that the Path includes the web driver folder by typing “Path” on the command window

Robo24

 

Step 4: Install Visual Studio Code
We are going to use Visual Studio Code for the demo. If you have a licensed version of Visual Studio Enterprise, you don’t need to install VS Code.

a) Go to Microsoft Visual Studio download page and select the appropriate installer. I am using the system installer, which requires admin rights on the OS for the setup

Robo25

 

b) There are two flavors, but it’s preferred to use the first one (system installer)

Robo26

 

c) Proceed to the installation with all the default settings

Robo27

 

Robo28

 

Robo29

 

Robo30

 

Robo31

 

Robo32

 

Robo33

 

Develop Robot code with Debugging
We have successfully installed and configured our system to write our first “Hello World” Robot test code.

a) Create a folder for our project

Robo34

 

b) Open Visual Studio Code and select the project folder

Robo35

 

c) Create a new file named “HelloWorld.robot”

Robo36

 

d) Notice that we are missing Intellisense for our Robot development. For that, we go to Marketplace and install a few libraries.

Robo37

 

e) Search and install “RoboCorp Code” & “Framework Language Server”.

Please note that installing other components could conflict with the other Robot libraries, so stick with one if you can.

Robo38

Robo39

 

When I click on extensions, I should see two extensions as shown below:

Robo40

 

f) This is the most important step. Configure the RoboCorp to include the Python install folder.

Go to Extensions -> Click on Settings icon -> Extension settings and set the executable path on both settings.

Robo41

Robo42

You can read more on this at: https://robocorp.com/docs/developer-tools/visual-studio-code/overview

 

g) I am using a simple robot file that searches for “robot framework” on Google. You can download the code on my

GitHub at: https://github.com/MuraliMuruguswamy/BlogSamples

 

h) Next, press CTRL + SHIFT + P to open the command console on VS Code . Type Robocorp to get the list of Robocorp commands. Select the “Create Robot” option

 

i) Select the “Standard Robot Framework template”

Robo43

 

j) Select “Use Workspace Folder”

Robo44

 

k) Select the first option since we have only one robot file for now

Robo45

 

l) This action will create a few files in the folder as shown below

Robo46

Update the robot.yaml file to reflect the robot file name. By default, it creates tasks.robot for execution. Please modify other switches on this file as needed.

 

m) Now, we are ready to debug the code. Select “Run” after setting a few breakpoints

Robo47

 

The code execution stops at breakpoint line #21

Robo48

 

About the Code
The robot file starts with including libraries, and in our case, we include the Selenium libraries

Robo49

The next two lines is the recommended approach to start the browser and close the browser at the end, irrespective of error or exception

Robo50

Robo51

We are defining the variables with a URL, browser type and search keywords

Robo52

Finally, we write code under the “Test Cases” session. First, the code waits for the element, inputs our search text, and then submits the form to get the search result

Robo53

Executing the code will open the Chrome browser, search for “Robot Framework”, and then close the browser.

 

This will also generate a nice report, as shown below:

Robo54

 

Final Note
I hope this article helps you to consider Robot Framework for your application. As you can see from the article, Robot Framework will help the team in implementing test automation if you don’t have one now. Please reach out to us for any questions or comments.