In this tutorial, we will automate the execution of the Radio Button in Robot Framework.
- Install Python
- Install PIP
- Install Robot Framework
- Install Robot framework Selenium Library
- Install PyCharm IDE
Please refer to this tutorial to install Robot Framework – How to install and setup Robot Framework for Python.
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 RadioButton_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.
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 Radio Buttons
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 the Radio Buttons.
- Verify that the page does not contain the Radio Button. Provided the locator for the checkbox
- Click on “Male” Radio Button
- Verify that “Male” Radio Button is selected
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 2 Radio Buttons – Male and FeMale.
Let us inspect the locator of the Radio Button.
Below is an example of selecting the “Male” option in Radio Buttons.
*** 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 Select impressive option from 3 radio buttons Verify that the radio button is selected *** Keywords *** Open the Browser with URL Create Webdriver Chrome executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/chromedriver_linux64 Go To https://demo.automationtesting.in/Register.html Maximize Browser Window Set Selenium Implicit Wait 2 Select impressive option from 3 radio buttons Page Should Contain Radio Button name:radiooptions Page Should Not Contain Radio Button id:checkbox1 #This is checkbox Select Radio Button radiooptions Male Verify that the radio button is selected Radio Button Should Be Set To radiooptions Male
All the below-mentioned keywords are derived from SeleniumLibrary. 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 Radio Button − This keyword is used to find the radio buttons that are
6. Page Should Not Contain Radio Button – This keyword is used to find that the radio buttons are not
7. Select Radio Button – This keyword is used to click on the “Male” option of the radio buttons.
8. Radio Button Should Be Set To – This keyword verifies if the radio button “Male” is selected or not.
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.
Step 6 – Execute the tests
We need the below command to run the Robot Framework script.
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.
Right-click on report.html. Select Open In->Browser->Chrome(any browser of your wish).
The Report generated by the framework is shown below:
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!!