Select Page
Software Testing

An End-to-End Robot Framework Tutorial

Our Robot Framework Tutorial covers everything one will need to write automation scripts easily for a keywords-driven approach.

An End to End Robot Framework Tutorial

Robot Framework is an open-source Python-based automation framework used for Robotic Process Automation (RPA) and also for Acceptance Testing & Acceptances Test-Driven Development (ATDD). It is used with the keyword-driven testing approach for which testers can write automation test scripts easily. The Test cases are written using the keyword style in a tabular format making them easy to understand. Robot Framework does provide good support for external libraries. But Selenium library is the most popular library used with Robot Framework for web development and UI testing. As a leading mobile app testing service provider, we have been using Robot Framework in our various Android and iOS app testing projects. So we have written this end-to-end Robot Framework Tutorial that covers everything one has to know.

The Basic requirements for robot framework

Since the Robot framework is built based on Python, we have to install the latest version of Python by downloading it from their official site. After successful installation, set up the Path environment variable in your local system.

Steps to Install Robot Framework:-

1. You can check if the Python setup has been installed properly by opening Command Prompt and typing the below command.

python --version

2. Use the below command to check the pip version. (Pip is a Python package manager)

pip --version

3. Now we’re all set to install the Robot framework

a. For a straightforward installation of the robot framework, you can use the command

pip install robotframework

b. If there is a need to install the robot framework without any cache, you can use this code instead.

pip install --no-cache-dir robotframework

c. If for any reason, you want to uninstall the Robot framework, then you can do so by using the below code.

pip uninstall robotframework

4. Just like how we verified Java, we can use the below commands to check it using Command Prompt.

(i)

pip show robotframework

This command will show the details of the robot framework and the framework location.

(ii.)

pip check robotframework

Once we enter this command, the desired result that should be displayed is “No broken requirements found.” If any other message apart from this (i.e.) a warning is displayed, we need to check the warning related to the setup and install it properly.

We can also verify if the Robot Framework has also been installed properly in our Local system.

Go to the Python folder > Lib > site-packages > verify if Robot Framework is installed.

Robot Framework Installation

5. To verify the version of the installed Robot Framework, use this code

robot --version

6. You might face a scenario where you would need to use a specific version of the Robot Framework, you can accomplish this by mentioning the specific version you need as shown below.

pip install robotframework==4.0.0	//mention the specific version

7. In time, you might want to upgrade the old version of the Robot Framework. You can use the below code to do it.

pip install --upgrade robotframework

8. In addition to verifying if the Robot Framework has been installed correctly, you might also have to check if the python libraries.

(i.)

pip freeze

This command will show all the python libraries installed with the robot framework version.

(ii.)

pip list

This command will show all the python libraries installed with their version numbers.

For writing automation test case:

In the Robot Framework Tutorial, we would be exploring how to perform web browser testing using Selenium Library. But for that to happen, we have to import the Selenium library file to this Robot project

Step 1: Enter the Command-Line to install Selenium

pip install selenium

Step 2: To upgrade the pip installation with the Selenium library, enter the below-mentioned command

pip install --upgrade robotframework-seleniumlibrary

Step 3: Finally, you can check if the pip Robot framework Selenium library has been installed properly by using this command.

pip check robotframework-seleniumlibrary

IDE for the Robot framework:

We can conveniently use the following IDE’s to write the Robot Framework automation testing codes.

1. PyCharm

2. Eclipse with RED plugin

3. Visual Studio with one of the plugin

4. RIDE

In this Robot Framework Tutorial, we have used PyCharm with Selenium to write a website automation testing code.

PyCharm IDE Installation and a New Project Creation:-

Step 1: Go to https://www.jetbrains.com/pycharm/download/#section=windows

Step 2: Download the free Open-Source Community Version of the PyCharm .exe file.

Step 3: Once you run the .exe file of the PyCharm setup, you’ll see the ‘Install Location’ window. If you want to change the location from the default option, you can click on the “BROWSE” button, and select your own file setup location and click on the ‘Next’ button.

Step 4: In the 4th Window, select the 64-bit launcher and click the ‘NEXT’ button to move to the next window where you can directly click on the ‘INSTALL’ button to install all the files.

Step 5: Once the setup and jar files are properly installed and updated, tick the checkbox and finish by clicking on the “OK” button in the “Import Pycharm Settings” pop-up.

Step 6: Now, you will see the ‘Welcome to PyCharm’ window. Click on the “Create New Project” option and it will automatically generate a project fill location to set up the project. If you would like to change the location, then you may click on the file option to customize it as you please. Enter the “Project Name”, and click on the “CREATE” button.

PyCharm IDE Installation

Step 7: Finally the PyCharm Window will display with New Project.

PyCharm IDE new project

In this Pycharm IDE, we are going to create a Robot framework for a website’s automation testing. So let’s explore how to generate a report and all the other essential actions in the upcoming topics of this Robot Framework Tutorial.

How to Create a New Robot Project and the required Setups:

In the Robot framework, we have to set up interpreters and add some plugins as well. Let see how to do those things now.

Step 1: You’ve already created the Initial Project for which you need to add the interpreters to work with the Selenium and Robot framework. So follow the below steps, and use the image as a reference if needed.

Go to File > Settings > Click on Project: “current project name” > Python Interpreter > + icon

Create new Robot Object in Robot Framework Tutorial

Step 2: You need to install the following packages for this project

i. Selenium

ii. robotframework

iii. robotframework-seleniumlibrary

You have to enter these three keywords one by one in the search input field and search for the packages. Once you find them, you have to click on the “Install Package” button and wait for a while for the packages to install in the back end. Once it is successfully installed, the highlighted message will appear and you can close the window by clicking on the “OK” button in the settings window.

Note: Make sure to close the window only after installing the three packages one by one.

Installation of Selenium

Step 3: Now, you have to add the “IntelliBot @SeleniumLibrary Patched” Plugin as it’ll help us find the Robot framework files and give auto suggestions for the keywords. So without this plugin, PyCharm will not be able to find the “.robot” files. The steps are as follows,

Settings > Plugin > Marketplace >Search “IntelliBot @SeleniumLibrary Patched” > Install

Adding Intelli Project in Selenium Library

Once the Plugin has been installed, you have to restart the IDE for the initial configuration.

Step 4: Normally, the Project Structure contains multiple directories and each directory contains a similar kind of file. So in this Test project, we are going to create a test case inside the directory first.

Right-click Test Project > New > Directory > Enter the Directory Name

That directory will be created under the Test Project and so our Robot test cases can be created inside it.

Step 5: Create the “.robot” file under the created directory.

Right Click on Created Directory > New > File > Enter a File name that ends with “.robot”

Once the robot project has been created, the structure of the project will be how it’s shown in the following image.

Create Robot file in Created Directory

Prerequisites to run Automation Test Cases in the Robot Framework:

Whenever you write automation test cases in the Robot framework, 4 sections should be there. They are

  • Settings
  • Variables
  • Test Cases
  • Keywords

Prerequisites to run Automation Test Cases

Note:

  • These 4 sections are must-know aspects from a beginner’s point of view.
  • Each and every section starts with ‘***’ and is followed by the Name of the Section. It also ends with ‘***’.
  • One (or) Two Tab spaces are needed in between the Keyword and the Test data (or) Data (or) input data because indentation is very important in Python.
  • When you’re about to write a test case, you should first write the test case name and then go to the next line to write the keyword after leaving a tab space.

Step 1: Settings

You are going to import the Selenium Library in this Test case.

The first line indicates the code block and the second line uses the “Library” keyword to import the “SeleniumLibrary”.

Syntax:

***Settings***
				Keyword		LibraryName

Selenium Library in Settings Test Cases

Step 2: Write the Test Cases

Now, you have to write exact test cases as per your requirements. First, you have to assign a test case name, and then enter the test case information in the next line. You can write these test cases using free defined Selenium Keywords. Being a leading QA Company, we wanted our Robot Framework Tutorial to be a comprehensive guide even for beginners. That is why we’re going through everything from scratch.

Syntax:

***Test Cases***
			TestCase_Name		
				Keyword	Locators(or)data	Testdata

In this Robot Framework Tutorial, we are going to perform the following test cases:-

1. Visit the Codoid Website.

2. Navigate to another page and verify it.

3. Pass the Input data.

The first step towards automation is launching your browser. Based on the browser you are using (Chrome, Firefox, etc.), you have to download the various drivers. Once you have downloaded the drivers, you have to extract the downloaded file and copy the driver.exe file path. We will be using Chrome for our demonstration.

Syntax for the Chrome launch:

***Test Cases***
TestCase_Name
Keyword	driver_name		executable_path= “driver_path”

Syntax for Chrome Launch

There is also another method that can help us save some valuable time by reducing the time to launch the browser. You can,

1. Copy or Cut “various_driver.exe” file from your local.

2. Paste them under the Python/Scripts page under your local system as shown below.

Local System folder

After this step, we can directly launch the browser without pointing to the driver location in the framework. We have to write the following syntax instead of using the “Create webdriver” keyword to set up the path.

Direct browser launching syntax:

***Test Cases***
TestCase_Name
Keyword	input_data (or) URL	driver_name

Browser Launching Syntax

Based on the requirements, we have to write the test steps under the test case name with the Selenium Library Keywords and respected Locators along with the test data.

Selenium Keywords in Robot Framework Tutorial

In this example, will be performing the test case with limited Selenium Keywords in the robot framework. For more Selenium Library keywords please visit their website.

Step 3: Define the Variable

The variables are elements used to store values which can be referred to by other elements.

Syntax:

***Variables ***
				${URL}	url
				@{UserCredentials}		inputs

Defined variables can be replaced in test cases and we can even reuse them anywhere in the test case when needed.

Define the Variable Testcases in Robot Framework Tutorial

Apart from this, we have a lot of variables available in Robot Framework. We have mentioned only the required ones here

Variables Available in Robot Framework Tutorial

Step 4: Define the KEYWORDS

Since the keywords are reusable in the Robot framework, it helps manage the changes in a faster and efficient manner. You can even create our own keywords here.

Syntax:

***Keywords***	
			Keyword_Name
				Selenium_keyword		locators 	input_data

Keywords Testcases

Once you write your own keyword, you can replace the test case steps with the keywords.

Replacing Test cases with Keywords in Robot Framework tutorial

Even once all of this is done, we won’t be able to run our project directly in the PyCharm Robot framework. We would have to go to the Terminal and use the below command

robot directory_name\file_name.robot

Terminal Section in Robot Framework Tutorial

Once the project has been successfully executed, the output.html, the log.html, and the report.html files along with the screenshots for each test case will be automatically created in our project structure. So we can copy and paste it into any browser to check the report of the execution of our project.

Execution of the Project

Testcase Report

Here we have executed all the test cases. But if you are looking to run a separate test case, you can do so by using Tags. You should include the tags with the name of your choice inside the test cases section under the test case name as shown in the below image.

Including Tags in the testcases

You can either run one or a particular set of test cases by using this command in the Terminal.

For one particular Tag:

robot --include=Tag_name directory_name\file_name.robot

One particular tag at a time

For Two Tags at a Time:

robot –i Tag_name  -i Tag_name directory_name\file_name.robot

Two tags at a time

So using tags you will be able to get more concise reports as you can execute the test cases based on priorities. Refer to the following images to get a better understanding of what we mean.

Tags details in Testcase in Robot Framework Tutorial

Test Case details in the Robot Framework Tutorial

Test Case log

Conclusion:

We hope you have found our end-to-end Robot framework tutorial to be useful as the Robot framework is an easy-to-understand open-source tool that provides a modular interface to build custom automation test cases based on your varying requirements. So it has been widely adopted by various large organizations for this very purpose, and for good reason.

Written By

Submit a Comment

Your email address will not be published. Required fields are marked *


Robot Framework is an open-source Python-based automation framework used for Robotic Process Automation (RPA) and also for Acceptance Testing & Acceptances Test-Driven Development (ATDD). It is used with the keyword-driven testing approach for which testers can write automation test scripts easily. The Test cases are written using the keyword style in a tabular format making them easy to understand. Robot Framework does provide good support for external libraries. But Selenium library is the most popular library used with Robot Framework for web development and UI testing. As a leading mobile app testing service provider, we have been using Robot Framework in our various Android and iOS app testing projects. So we have written this end-to-end Robot Framework Tutorial that covers everything one has to know.

The Basic requirements for robot framework

Since the Robot framework is built based on Python, we have to install the latest version of Python by downloading it from their official site. After successful installation, set up the Path environment variable in your local system.

Steps to Install Robot Framework:-

1. You can check if the Python setup has been installed properly by opening Command Prompt and typing the below command.

python --version

2. Use the below command to check the pip version. (Pip is a Python package manager)

pip --version

3. Now we’re all set to install the Robot framework

a. For a straightforward installation of the robot framework, you can use the command

pip install robotframework

b. If there is a need to install the robot framework without any cache, you can use this code instead.

pip install --no-cache-dir robotframework

c. If for any reason, you want to uninstall the Robot framework, then you can do so by using the below code.

pip uninstall robotframework

4. Just like how we verified Java, we can use the below commands to check it using Command Prompt.

(i)

pip show robotframework

This command will show the details of the robot framework and the framework location.

(ii.)

pip check robotframework

Once we enter this command, the desired result that should be displayed is “No broken requirements found.” If any other message apart from this (i.e.) a warning is displayed, we need to check the warning related to the setup and install it properly.

We can also verify if the Robot Framework has also been installed properly in our Local system.

Go to the Python folder > Lib > site-packages > verify if Robot Framework is installed.

Robot Framework Installation

5. To verify the version of the installed Robot Framework, use this code

robot --version

6. You might face a scenario where you would need to use a specific version of the Robot Framework, you can accomplish this by mentioning the specific version you need as shown below.

pip install robotframework==4.0.0	//mention the specific version

7. In time, you might want to upgrade the old version of the Robot Framework. You can use the below code to do it.

pip install --upgrade robotframework

8. In addition to verifying if the Robot Framework has been installed correctly, you might also have to check if the python libraries.

(i.)

pip freeze

This command will show all the python libraries installed with the robot framework version.

(ii.)

pip list

This command will show all the python libraries installed with their version numbers.

For writing automation test case:

In the Robot Framework Tutorial, we would be exploring how to perform web browser testing using Selenium Library. But for that to happen, we have to import the Selenium library file to this Robot project

Step 1: Enter the Command-Line to install Selenium

pip install selenium

Step 2: To upgrade the pip installation with the Selenium library, enter the below-mentioned command

pip install --upgrade robotframework-seleniumlibrary

Step 3: Finally, you can check if the pip Robot framework Selenium library has been installed properly by using this command.

pip check robotframework-seleniumlibrary

IDE for the Robot framework:

We can conveniently use the following IDE’s to write the Robot Framework automation testing codes.

1. PyCharm

2. Eclipse with RED plugin

3. Visual Studio with one of the plugin

4. RIDE

In this Robot Framework Tutorial, we have used PyCharm with Selenium to write a website automation testing code.

PyCharm IDE Installation and a New Project Creation:-

Step 1: Go to https://www.jetbrains.com/pycharm/download/#section=windows

Step 2: Download the free Open-Source Community Version of the PyCharm .exe file.

Step 3: Once you run the .exe file of the PyCharm setup, you’ll see the ‘Install Location’ window. If you want to change the location from the default option, you can click on the “BROWSE” button, and select your own file setup location and click on the ‘Next’ button.

Step 4: In the 4th Window, select the 64-bit launcher and click the ‘NEXT’ button to move to the next window where you can directly click on the ‘INSTALL’ button to install all the files.

Step 5: Once the setup and jar files are properly installed and updated, tick the checkbox and finish by clicking on the “OK” button in the “Import Pycharm Settings” pop-up.

Step 6: Now, you will see the ‘Welcome to PyCharm’ window. Click on the “Create New Project” option and it will automatically generate a project fill location to set up the project. If you would like to change the location, then you may click on the file option to customize it as you please. Enter the “Project Name”, and click on the “CREATE” button.

PyCharm IDE Installation

Step 7: Finally the PyCharm Window will display with New Project.

PyCharm IDE new project

In this Pycharm IDE, we are going to create a Robot framework for a website’s automation testing. So let’s explore how to generate a report and all the other essential actions in the upcoming topics of this Robot Framework Tutorial.

How to Create a New Robot Project and the required Setups:

In the Robot framework, we have to set up interpreters and add some plugins as well. Let see how to do those things now.

Step 1: You’ve already created the Initial Project for which you need to add the interpreters to work with the Selenium and Robot framework. So follow the below steps, and use the image as a reference if needed.

Go to File > Settings > Click on Project: “current project name” > Python Interpreter > + icon

Create new Robot Object in Robot Framework Tutorial

Step 2: You need to install the following packages for this project

i. Selenium

ii. robotframework

iii. robotframework-seleniumlibrary

You have to enter these three keywords one by one in the search input field and search for the packages. Once you find them, you have to click on the “Install Package” button and wait for a while for the packages to install in the back end. Once it is successfully installed, the highlighted message will appear and you can close the window by clicking on the “OK” button in the settings window.

Note: Make sure to close the window only after installing the three packages one by one.

Installation of Selenium

Step 3: Now, you have to add the “IntelliBot @SeleniumLibrary Patched” Plugin as it’ll help us find the Robot framework files and give auto suggestions for the keywords. So without this plugin, PyCharm will not be able to find the “.robot” files. The steps are as follows,

Settings > Plugin > Marketplace >Search “IntelliBot @SeleniumLibrary Patched” > Install

Adding Intelli Project in Selenium Library

Once the Plugin has been installed, you have to restart the IDE for the initial configuration.

Step 4: Normally, the Project Structure contains multiple directories and each directory contains a similar kind of file. So in this Test project, we are going to create a test case inside the directory first.

Right-click Test Project > New > Directory > Enter the Directory Name

That directory will be created under the Test Project and so our Robot test cases can be created inside it.

Step 5: Create the “.robot” file under the created directory.

Right Click on Created Directory > New > File > Enter a File name that ends with “.robot”

Once the robot project has been created, the structure of the project will be how it’s shown in the following image.

Create Robot file in Created Directory

Prerequisites to run Automation Test Cases in the Robot Framework:

Whenever you write automation test cases in the Robot framework, 4 sections should be there. They are

  • Settings
  • Variables
  • Test Cases
  • Keywords

Prerequisites to run Automation Test Cases

Note:

  • These 4 sections are must-know aspects from a beginner’s point of view.
  • Each and every section starts with ‘***’ and is followed by the Name of the Section. It also ends with ‘***’.
  • One (or) Two Tab spaces are needed in between the Keyword and the Test data (or) Data (or) input data because indentation is very important in Python.
  • When you’re about to write a test case, you should first write the test case name and then go to the next line to write the keyword after leaving a tab space.

Step 1: Settings

You are going to import the Selenium Library in this Test case.

The first line indicates the code block and the second line uses the “Library” keyword to import the “SeleniumLibrary”.

Syntax:

***Settings***
				Keyword		LibraryName

Selenium Library in Settings Test Cases

Step 2: Write the Test Cases

Now, you have to write exact test cases as per your requirements. First, you have to assign a test case name, and then enter the test case information in the next line. You can write these test cases using free defined Selenium Keywords. Being a leading QA Company, we wanted our Robot Framework Tutorial to be a comprehensive guide even for beginners. That is why we’re going through everything from scratch.

Syntax:

***Test Cases***
			TestCase_Name		
				Keyword	Locators(or)data	Testdata

In this Robot Framework Tutorial, we are going to perform the following test cases:-

1. Visit the Codoid Website.

2. Navigate to another page and verify it.

3. Pass the Input data.

The first step towards automation is launching your browser. Based on the browser you are using (Chrome, Firefox, etc.), you have to download the various drivers. Once you have downloaded the drivers, you have to extract the downloaded file and copy the driver.exe file path. We will be using Chrome for our demonstration.

Syntax for the Chrome launch:

***Test Cases***
TestCase_Name
Keyword	driver_name		executable_path= “driver_path”

Syntax for Chrome Launch

There is also another method that can help us save some valuable time by reducing the time to launch the browser. You can,

1. Copy or Cut “various_driver.exe” file from your local.

2. Paste them under the Python/Scripts page under your local system as shown below.

Local System folder

After this step, we can directly launch the browser without pointing to the driver location in the framework. We have to write the following syntax instead of using the “Create webdriver” keyword to set up the path.

Direct browser launching syntax:

***Test Cases***
TestCase_Name
Keyword	input_data (or) URL	driver_name

Browser Launching Syntax

Based on the requirements, we have to write the test steps under the test case name with the Selenium Library Keywords and respected Locators along with the test data.

Selenium Keywords in Robot Framework Tutorial

In this example, will be performing the test case with limited Selenium Keywords in the robot framework. For more Selenium Library keywords please visit their website.

Step 3: Define the Variable

The variables are elements used to store values which can be referred to by other elements.

Syntax:

***Variables ***
				${URL}	url
				@{UserCredentials}		inputs

Defined variables can be replaced in test cases and we can even reuse them anywhere in the test case when needed.

Define the Variable Testcases in Robot Framework Tutorial

Apart from this, we have a lot of variables available in Robot Framework. We have mentioned only the required ones here

Variables Available in Robot Framework Tutorial

Step 4: Define the KEYWORDS

Since the keywords are reusable in the Robot framework, it helps manage the changes in a faster and efficient manner. You can even create our own keywords here.

Syntax:

***Keywords***	
			Keyword_Name
				Selenium_keyword		locators 	input_data

Keywords Testcases

Once you write your own keyword, you can replace the test case steps with the keywords.

Replacing Test cases with Keywords in Robot Framework tutorial

Even once all of this is done, we won’t be able to run our project directly in the PyCharm Robot framework. We would have to go to the Terminal and use the below command

robot directory_name\file_name.robot

Terminal Section in Robot Framework Tutorial

Once the project has been successfully executed, the output.html, the log.html, and the report.html files along with the screenshots for each test case will be automatically created in our project structure. So we can copy and paste it into any browser to check the report of the execution of our project.

Execution of the Project

Testcase Report

Here we have executed all the test cases. But if you are looking to run a separate test case, you can do so by using Tags. You should include the tags with the name of your choice inside the test cases section under the test case name as shown in the below image.

Including Tags in the testcases

You can either run one or a particular set of test cases by using this command in the Terminal.

For one particular Tag:

robot --include=Tag_name directory_name\file_name.robot

One particular tag at a time

For Two Tags at a Time:

robot –i Tag_name  -i Tag_name directory_name\file_name.robot

Two tags at a time

So using tags you will be able to get more concise reports as you can execute the test cases based on priorities. Refer to the following images to get a better understanding of what we mean.

Tags details in Testcase in Robot Framework Tutorial

Test Case details in the Robot Framework Tutorial

Test Case log

Conclusion:

We hope you have found our end-to-end Robot framework tutorial to be useful as the Robot framework is an easy-to-understand open-source tool that provides a modular interface to build custom automation test cases based on your varying requirements. So it has been widely adopted by various large organizations for this very purpose, and for good reason.