• Selenium Video Tutorials

Selenium with Robot Framework Tutorial



Selenium can be used with Robot API. A Robot Framework is used for creating automation framework used for acceptance test driven development. This acceptance test driven development approach is based on keyword driven testing. Selenium is used extensively for web automation testing. Selenium is an open-source and a portable automated software testing tool for testing web applications.

What is a Robot Framework?

A Robot Framework comprises a large number of libraries developed using Java, Python, and so on. Apart from the existing keywords available in the Robot framework, we can add new keywords in the Robot Framework using the syntax of the existing ones for developing new tests. Only basic programming knowledge is enough for using a Robot Framework.

Prerequisites to Setup Robot Framework

Step 1 − Download and install Python from the link − https://www.python.org/downloads/.

To get a more detailed view on how set up Python, refer to the link − Python.

Once we have successfully installed Python, we can confirm its installation by running the command: python –version, from the command prompt. The output of the command executed would point to the Python version installed in the machine.

Step 2 − Install the Python code editor called the PyCharm from the link − https://www.jetbrains.com/pycharm/.

Using this editor, we can start working on a Python project to start our test automation. To get a more detailed view on how to set up PyCharm, refer to the link − PyCharm.

Step 3 − Run the command: pip install selenium from the command prompt. This is done to install the Selenium. To confirm the version of Selenium installed in the machine, run the command −

pip show selenium

The output of this command shall give the result −

Name: selenium
Version: 4.19.0
Summary: None
Home-page: https://www.selenium.dev
Author: None
Author-email: None
License: Apache 2.0.

Step 4 − Run the command: pip install robotframework from the command prompt. This is done to install the Robot Framework. To confirm the version of Robot Framework installed in the machine, run the command −

pip show robotframework

The output of this command gave the below result −

Name: robotframework
Version: 7.0
Summary: Generic automation framework for acceptance 
   testing and robotic process automation (RPA)
Home-page: https://robotframework.org
Author: Pekka Klärck
Author-email: peke@eliga.fi
License: Apache License 2.0
Location: /Users/opt/anaconda3/lib/python3.8/site-packages
Requires: 
Required-by:

Step 5 − Run the command: pip install requests from the command prompt. This is done to install the request library which would help to automate the Rest APIs.

Step 6 − Run the command: pip install robotframework-requests from the command prompt. This is done to install the Robot Framework request library which would help to automate the Rest APIs.

Step 7 − Run the command: pip install -U robotframework-jsonlibrary from the command prompt. This is done to verify the JSON responses.

Step 8 − Restart PyCharm once Step 8 has been completed.

Step 9 − Open PyCharm and create a New Project by navigating to the File menu.

Selenium Robot Framework Tutorial 1

Enter the project name and location within the Location field, and then click on the Create button.

Selenium Robot Framework Tutorial 2

Step 10 − From the right bottom corner of the PyCharm editor, select the option Interpreter Settings.

Selenium Robot Framework Tutorial 3

Select the option Python Interpreter from the left, then click on ‘+’.

Selenium Robot Framework Tutorial 4

Step 11 − Enter selenium in the package search box inside the Available Packages popup, then the search results appear along with the Description to the right. The Description contains information about the version of the Selenium package that shall be installed.

There is also an option to install a specific version of the Selenium package beside the Specify version field. Then click on the Install Package button. After successful installation, the message Package ‘selenium’ installed successfully should display.

Selenium Robot Framework Tutorial 5

Step 12 − Enter robotframework in the package search box inside the Available Packages popup, and install it in the same way.

Step 13 − Enter requests in the package search box inside the Available Packages popup, and install it in the same way.

Step 14 − Enter robotframework-jsonlibrary in the package search box inside the Available Packages popup, and install it in the same way.

Step 15 − Enter robotframework-seleniumlibrary in the package search box inside the Available Packages popup, and install it in the same way.

Exit out of the Available Packages popup.

Step 16 − All the packages installed in the Steps 11, 12, 13, 14, and 15 should reflect under the Package. Click on the OK button. Restart PyCharm.

Selenium Robot Framework Tutorial 6

Step 17 − Create the first test case, by right clicking on the Project folder. Here, we have given the project name as SeleniumPython. Then right click on the newly created project, click on the New option, and finally select Directory.

Selenium Robot Framework Tutorial 7

Step 18 − Enter a directory name, say Robot and click on Enter. The project Robot should appear in the left under the SeleniumPython project folder.

Selenium Robot Framework Tutorial 8

Step 19 − Navigate to the PyCharm Settings, and click on Plugins tab.

Selenium Robot Framework Tutorial 9

Step 20 − Enter IntelliBotSelenium in the search box, and click on the Install button. After installing this plugin, restart the PyCharm. This is done so that all the robot related test cases having extension as .robot can be identified by the PyCharm editor.

Selenium Robot Framework Tutorial 10

Step 21 − Right click on the directory Robot, and create a file, say GetRequest.robot.

Selenium Robot Framework Tutorial 11

Step 22 − Add the below code to trigger a Get request

*** Settings ***
Library  RequestsLibrary

*** Variables ***
${baseUrl} https://api.restful-api.dev/objects
${object}  7

*** Test Cases ***
Get_Object
   create session firstSession ${baseUrl}
   ${response} = get request firstSession ${object}
   log to console ${response.status_code}
   log to console ${response.content}
   log to console ${response.header}

This concludes our comprehensive take on the tutorial on Selenium - Robot API. We’ve started with describing what a Robot Framework is and how to set up a Robot Framework using Python and Selenium.

This equips you with in-depth knowledge of the Selenium - Robot API. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements