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 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.
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/
b) Select the “Customize installation” option
c) Select all the available options on this wizard screen
(PIP- Package Installer for Python is needed to install libraries)
d) Select the Advanced Options. If you are using Visual Studio, also select the last option on this list
e) Please wait for the installation to complete
f) Click the “Close” button to complete the setup process
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
b) If you get a message like the one below, please upgrade your pip version
c) Wait for the pip upgrade
d) Start with installing the Robot Framework
e) At any time, use “pip list” to list all the installed libraries. The next item in our list is to install Selenium libraries
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.
b) List of Chromium drivers
c) Once you download the correct version, extract the ZIP file
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
e) Next, update the PATH to include this folder. Right click on “This PC” and select Properties
f) Click Advanced System Settings
g) On the System properties window, click “Environment variables”
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.
i) Click New button and enter the Web Driver folder path
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
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
b) There are two flavors, but it’s preferred to use the first one (system installer)
c) Proceed to the installation with all the default settings
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
b) Open Visual Studio Code and select the project folder
c) Create a new file named “HelloWorld.robot”
d) Notice that we are missing Intellisense for our Robot development. For that, we go to Marketplace and install a few libraries.
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.
When I click on extensions, I should see two extensions as shown below:
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.
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”
j) Select “Use Workspace Folder”
k) Select the first option since we have only one robot file for now
l) This action will create a few files in the folder as shown below
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
The code execution stops at breakpoint line #21
About the Code
The robot file starts with including libraries, and in our case, we include the Selenium libraries
The next two lines is the recommended approach to start the browser and close the browser at the end, irrespective of error or exception
We are defining the variables with a URL, browser type and search keywords
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
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:
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.