How to handle checkbox in Robot Framework 

HOME

In this tutorial, we will automate the execution of the CheckBox in Robot Framework.

Prerequisite:

  1. Install Python
  2. Install PIP
  3. Install Robot Framework
  4. Install Robot framework Selenium Library
  5. Install PyCharm IDE

Please refer to this tutorial to install Robot Framework – How to install and setup Robot Framework for Python.

Implementation Steps:

Step 1 – Create a new Project

Step 1.1 – Open PyCharm and create a new project. Go to File and select New Project from the main menu.

Step 1.2 – Choose the project location. Click the “Browse” button next to the Location field and specify the directory for your project.

Deselect the Create a main.py welcome script checkbox because you will create a new Python file for this tutorial.

Click on the “Create” Button.

Step 1.3 – A new dialog appears asking to open the project using any one of the given options. I have selected New Window as I like to have separate windows for each project.

Below is the image of the new project created in PyCharms.

Step 2 – Create a new directory in the new project

Right-Click on the project, select New->Directory and provide name as Tests

Below is the image of the new directory.

Step 3 – Create a robot Test File

Right-click on the new directory and select New File and provide the name as CheckBox_Demo.robot as shown below:

Step 4 – Download ChromeBinaries from the below location

The tests are going to use the Chrome browser, so we need to download the ChromeBinaries to open a blank browser in Chrome.

https://chromedriver.chromium.org/

The chromedriver and geckodriver are placed in a folder name drivers in the RobotFramework_Demo project. I have renamed chromedriver to Chrome and geckodriver to Firefox.

Step 5 – Automate the selection of options for CheckBox

We are now going to write test cases. The test case details will be as follows −

  • Open the browser and copy URL − https://demo.automationtesting.in/Register.html in Chrome.
  • Verify that the page contains CheckBox.
  • Verify that the page does not contain CheckBox. Provided the locator for Radio button.
  • Check “Cricket” and “Hockey” options of CheckBox.
  • Uncheck “Hockey” option of CheckBox.
  • Verify that Cricket option of CheckBox is checked.
  • Verify that Hockey option of CheckBox is not checked.

To work with the Radio Button, we need a locator. A locator is an identifier for the textbox like id, name, class, xpath, css selector, etc.

To know more about locators, refer to these Selenium Tutorials:

 Locators in Selenium – Locate by ID, ClassName,  Name, TagName,  LinkText, PartialLinkText

Dynamic XPath  in Selenium WebDriver

CSS Selector in Selenium WebDriver

The below page shows that we have 3 CheckBoxes – Cricket, Movies, and Hockey.

Let us inspect the locator of the CheckBox.

Below is an example of selecting the “Cricket” and “Hockey” options in CheckBox.

*** Settings ***
Documentation    To validate the Login Form
Library     SeleniumLibrary
Test Teardown    Close Browser

*** Test Cases ***
Select an option of Radio Button
    Open the Browser with URL
    Verifies page contains a checkbox
    Select the checkbox options Cricket and Hockey
    Unselect the checkbox option Hockey
    Verify Checkbox option Cricket is selected
    Verify Checkbox option Hockey is not selected


*** Keywords ***
Open the Browser with URL
    Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework/drivers/chromedriver_linux64
    Go To    https://demo.automationtesting.in/Register.html
    Maximize Browser Window
    Set Selenium Implicit Wait    2


Verifies page contains a checkbox
    Page Should Contain Checkbox    id:checkbox1
    Page Should Not Contain Checkbox    name:radiooptions   #This is the locator for Radio Button


Select the checkbox options Cricket and Hockey
    Select Checkbox    id:checkbox1
    Select Checkbox    id:checkbox3

Unselect the checkbox option Hockey
    Unselect Checkbox    id:checkbox3

Verify Checkbox option Cricket is selected
    Checkbox Should Be Selected      id:checkbox1

Verify Checkbox option Hockey is not selected
    Checkbox Should Not Be Selected    id:checkbox3

All the below-mentioned keywords are derived from SeleniumLibrary except the last one. The functionality of keywords mentioned above:

1. Create Webdriver − The keyword creates an instance of Selenium WebDriver.

2. Go To – This keyword navigates the current browser window to the provided URL – https://demo.automationtesting.in/Register.html.

3. Maximize Browser Window – This keyword maximizes the current browser window.

4. Set Selenium Implicit Wait – This keyword sets the implicit wait value used by Selenium.

5. Page Should Contain Checkbox − This keyword is used to find the checkbox that is located on the current page.

6. Page Should Not Contain Checkbox – This keyword is used to find that the checkbox is not locator on the current page.

7. Select Checkbox – This keyword is used to select options “Cricket” and “Hockey” of the CheckBox.

8. Unselect Checkbox – This keyword is used to unselect the option “Hockey” of the CheckBox.

9. Checkbox Should Be Selected – This keyword verifies if the checkbox “Cricket” is checked.

10. Checkbox Should Not Be Selected – This keyword verifies if the checkbox “Hockey” is not checked.

These keywords are present in SeleniumLibrary. To know more about these keywords, please refer to this document – https://robotframework.org/SeleniumLibrary/SeleniumLibrary.htm

To run this script, go to the command line and go to directory tests.

cd Tests

Step 6 – Execute the tests

We need the below command to run the Robot Framework script.

robot CheckBox_Demo.robot

The output of the above program is

Step 7 – View Report and Log

We have the test case passed. The Robot Framework generates log.html, output.xml, and report.html by default.

Let us now see the report and log details.

Report

Right-click on report.html. Select Open In->Browser->Chrome(any browser of your wish).

The Report generated by the framework is shown below:

Log

Robot Framework has multiple log levels that control what is shown in the automatically generated log file. The default Robot Framework log level is INFO.

Right-click on log.html. Select Open In->Browser->Chrome(any browser of your wish).

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

Robot Framework – Working With Browsers Using Selenium Library

HOME

In this tutorial, we will create a project in PyCharms and create a test case in Robot Framework using Selenium WebDriver.

Prerequisite:

  1. Install Python
  2. Install PIP
  3. Install Robot Framework
  4. Install Robot framework Selenium Library
  5. Install PyCharm IDE

Please refer to this tutorial to install Robot Framework – How to install and setup Robot Framework for Python.

Implementation Steps:

Step 1 – Open PyCharm and create a new project. Go to File and select “New Project” from the main menu.

Step 2 – Choose the project location. Click the “Browse” button next to the Location field and specify the directory for your project.

Deselect the Create a main.py welcome script checkbox because you will create a new Python file for this tutorial.

Python best practice is to create a virtualenv for each project. In most cases, PyCharm creates a new virtual environment automatically, and you don’t need to configure anything. But, in this case, we need to create a Base Interpreter that has the robot framework already installed. This is explained in this tutorial – How to install and setup Robot Framework for Python. To preview and modify the venv options. Expand the Python Interpreter: New Virtualenv Environment node and select a tool used to create a new virtual environment. Let’s choose Virtualenv tool, and specify the location of the environment and the base Python interpreter used for the new virtual environment.

Click on the “Create” Button.

Step 3 – A new dialog will appear asking to Open the project using any one of the given options. I have selected New Window as I like to have separate windows for each project.

Below is the image of the new project created in PyCharms.

How to create a Selenium test in Robot Framework?

Step 1 – Create a new directory in the new project

Right-Click on the project, select New->Directory and provide name as Tests

Below is the image of the new directory.

Right-click on the new directory and select New File and provide the name as Test_Demo.robot as shown below:

Step 2 – Download ChromeBinaries from the below location

The tests are going to use the Chrome browser, so we need to download the ChromeBinaries to open a blank browser in Chrome.

https://chromedriver.chromium.org/

Step 3 – Create a simple Selenium Test

*** Settings ***
Documentation    To validate the Login Form
Library     SeleniumLibrary

*** Test Cases ***
Validate Unsuccessful Login
    Open the Browser with URL
    Fill the login form
    Verify error message is correct


*** Keywords ***
Open the Browser with URL
    Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/chromedriver_linux64
    Go To    https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
    Maximize Browser Window
    Set Selenium Implicit Wait    5

Fill the login form
   Input Text    css:input[name=username]   Admin
   Input Password    css:input[name=password]   Admin
   Click Button    css:.orangehrm-login-button


Verify error message is correct
    ${result}=  Get Text    CSS:.oxd-alert-content-text
    Should Be Equal As Strings   ${result}  Invalid credentials

The chromedriver is placed in a folder name drivers in RobotFramework_Demo project.

I will explain the terms Settings, Test Cases, Keywords in the next tutorial.

To run this script, go to the command line and go to directory tests.

We need the below command to run the Robot Framework script.

robot Test_Demo.robot

The output of the above program is

We have the test case passed. The Robot Framework generates log.html, output.xml, and report.html by default.

Let us now see the report and log details.

Report

Right-click on report.html. Select Open In->Browser->Chrome(any browser of your wish).

The Report generated by the framework is shown below:

Log

Robot Framework has multiple log levels that control what is shown in the automatically generated log file. The default Robot Framework log level is INFO.

Right-click on log.html. Select Open In->Browser->Chrome(any browser of your wish).

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

Robot Framework Tutorials

HOME

Robot Framework is a generic open-source automation framework. It can be used for test automation and robotic process automation (RPA). RPA is extensively used for Web Application Automation, API Automation, RPA, and Database Testing.

Robot Framework has an easy syntax, utilizing human-readable keywords. Its capabilities can be extended by libraries implemented with Python, Java, or many other programming languages.

Chapter 1 Robot Framework Features – Settings, Libraries, Variables, Keywords, Resources, Reports, Logs
Chapter 2 What are variables in Robot Framework?
Chapter 3 How to handle text box in Robot Framework
Chapter 4 How to handle radio buttons in Robot Framework
Chapter 5 How to handle checkbox in Robot Framework
Chapter 6 How to handle dropdowns in Robot Framework
Chapter 7 How to handle multiple windows in Robot Framework
Chapter 8 How to handle alerts in Robot Framework
Chapter 9 What is Resource File in Robot Framework 
Chapter 10 How to run all the tests from the folder in Robot Framework
Chapter 11 How to implement tagging in Robot Framework
Chapter 12 How to rerun failed tests in Robot Framework
Chapter 13 How to use Drag and Drop in Robot Framework?
Chapter 14 How to set variable values from Runtime command in Robot Framework
Chapter 15 Page Object Model in Robot Framework with Selenium and Python
Chapter 16 Parallel Testing in Robot Framework
Chapter 17 How to write tests in Robot Framework in BDD Format

Data-Driven Testing

Chapter 1 Data-Driven Testing in Robot Framework 
Chapter 2 How to load data from CSV files in the Robot Framework?

API Testing

Chapter 1 How to perform API Testing in Robot Framework using RequestLibrary
Chapter 2 How to Implement Basic Auth in Robot Framework – NEW
Chapter 3 How to pass authorization token in header in Robot Framework – NEW
Chapter 4 Verifying Status Code and Status Line in Robot Framework – NEW

CI/CD

Chapter 1 Run Robot Framework Tests in GitLab CI/CD
Chapter 2How to run Robot Framework in GitHub Actions

Jenkins

Chapter 1 How to integrate Robot Framework with Jenkins
Chapter 2 How to run parameterized Robot Framework tests in Jenkins

How to install PyCharms on Windows 11

HOME

This tutorial will explain the step-by-step process to download and install PyCharm on Windows.

Prerequisite:

Python is already installed on the machine.

You can refer to this tutorial to install Python on Windows 11.

Installation Steps

Step 1 –  To download PyCharm visit the website https://www.jetbrains.com/pycharm/download/, and it will give you two options: Professional or Community. The professional edition of PyCharm requires a subscription, while the community edition is free. Click the “DOWNLOAD” button under the Community Section.

Step 2 – Once the download is complete, run the exe to install PyCharm. The setup wizard should have started. Click the “Next” button.

Step 3 – On the next screen, Change the installation path if required. Click the “Next” button.

Step 4 –  On the next screen, you can create a desktop shortcut if you want, Add Open Folder as Project, Create Associations, Update PATH variable (restart needed), and click on the “Next” button.

Step 5 – Choose the start menu folder. Keep selecting JetBrains and click on the “Install” button.

 

Step 6 – Wait for the installation to finish.

 

Step 7 – Once the installation is finished, you should receive a message screen that PyCharm is installed. You can select either of the options – Reboot now or I want to manually reboot later and click the “Finish” button.

Step 8 – After you click on the “Finish” button, the following screen will appear. I already have created a new project, so you can see the RobotFramework project here.

How to Install Python on Windows 11

HOME

Python is becoming a popular programming language for both new and experienced developers. Python is a flexible and versatile programming language with strengths in scripting, automation, data analysis, machine learning, and back-end development.

In this tutorial, we’ll install Python on Windows 11 using the Python installer for Windows.

Prerequisites

You’ll need a computer running Windows 11 with administrative privileges and an internet connection.

Installation Steps

Step 1 – Download the Python Installer

Go to the official website of Python – Python download page for Windows.

Click on the latest version of Python for Windows. Click the appropriate link for your system to download the executable file: Windows installer (64-bit) or Windows installer (32-bit). In this case, I have selected – Python 3.11.2

Step 2 – Running the Executable Installer

After the installer is downloaded, double-click the .exe file, for example, “python-3.11.2-amd64 .exe“, to run the Python installer.

If you want to save the installation file in a different location, click on Customize installation; otherwise, continue with Install Now.

Once the installation is complete, the below pop-up box will appear: Setup was successful.

Step 3 – Adding Python to the Environment Variables 

Go to Start and enter View advanced system settings in the search bar. Click on View advanced system settings.

In the System Properties dialog, click the Advanced tab and then click Environment Variables.

Depending on your installation:

  • If you selected Install for all users during installation, select Path from the list of System Variables and click Edit.
  • If you didn’t select Install for all users during installation, select Path from the list of User Variables and click Edit.

Click the “New” button and enter the Python directory path, then click the “OK” button until all the dialogs are closed.

Step 4 – Verify the Python Installation

You can verify whether the Python installation is successful either through the command line or through the Integrated Development Environment (IDLE) application if you chose to install it.

Go to Start and enter cmd in the search bar. Click Command Prompt.

Enter the following command in the command prompt:

python --version

PIP gets installed along with python, and you can check the same in the command line as follows.

pip --version

We can also check the version of Python by opening the IDLE application.

Go to Start and search for Python. You can see Python 3.11 (64-bit) and IDLE. Let’s open IDLE, which is the short form for Integrated Development Environment, and run a simple print statement.

Congratulations!! We are able to install Python on Windows 11.