How to handle alerts in Robot Framework 

HOME

In this tutorial, we will discuss various types of Alerts available in web application testing and how to handle alerts 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.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.

How to create a test to automate the alerts in Robot Framework?

1. Simple Alert

Step 4 – 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 Confirm_Alert_Demo.robot, Ok_Alert_Demo.robot and TextBox_Alert_Demo.robot as shown below:

Step 5 – 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 is placed in a folder name drivers in the RobotFramework_Demo project. I have renamed chromedriver to Chrome.

Step 6 – Automate the Simple Alert

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

To work with the Robot Framework, 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 when we click on “Alert with OK”, then click on the “click the button to display an alert box” button, a new alert opens with the message – I am an alert box!.

Below is an example of selecting the “Simple Alert”.

*** Settings ***
Documentation    To validate the Message Alert
Library     SeleniumLibrary
Test Teardown    Close Browser

*** Variables ***
${okOption}    xpath://div[@class='tabpane pullleft']/ul/li[1]/a
${alertBtn}    css:.btn-danger

*** Test Cases ***
Handle Message Alert
    Open the Browser with URL
    Select the Alert with OK Option
    Verify text on Alert Box

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

Select the Alert with OK Option
    Click Element    ${okOption}
    Click Button     ${alertBtn}

Verify text on Alert Box
    Alert Should Be Present     I am an alert box!      ACCEPT

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. Click Element − This keyword is used to click the element identified by the locator. In this case, it is the “Alert with OK” link.

6. Click Button – This keyword is used to click the button identified by the locator. In this case, it is the “Click the button to display an alert box” button.

7. Alert Should Be Present – This keyword is used to verify that an alert is present on the page and, by default, accepts it.

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 7 – Execute the tests

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

 robot Ok_Alert_Demo.robot

The output of the above program is

Step 8 – 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).

2. Confirmation Alert

This alert comes with an option to accept or dismiss the alert.

The below page shows that when we click on Alert with OK & Cancel”, then click on the “click the button to display a confirm box” button, a new alert opens with the message – Press a Button!.

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

Below is an example of selecting the “Confirmation Alert”.

*** Settings ***
Documentation    To validate the Confirm Alert
Library     SeleniumLibrary
Test Teardown    Close Browser
Documentation    To validate the Confirmation Alert
Library     SeleniumLibrary
Test Teardown    Close Browser


*** Variables ***
${okCancelOption}    xpath://div[@class='tabpane pullleft']/ul/li[2]/a
${confirmBtn}    css:.btn-primary
${text}     id:demo

*** Test Cases ***
Handle Confirm Alert
    Open the Browser with URL
    Select the Alert with OK & Option
    Verify text on Confirm Box on selecting Cancel option

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

Select the Alert with OK & Option
    Click Element    ${okCancelOption}
    Click Button     ${confirmBtn}

Verify text on Confirm Box on selecting Cancel option
    Alert Should Be Present     Press a Button !     DISMISS
    Element Text Should Be    ${text}      You Pressed Cancel

3. Prompt Alert

 In the prompt alert, we get an option to add text to the alert box. This is used when some input is required from the user.

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

Below is an example of selecting the “Prompt Alert”.

*** Settings ***
Documentation    To validate the TextBox Alert
Library     SeleniumLibrary
Test Teardown    Close Browser

*** Variables ***
${textboxOption}    xpath://div[@class='tabpane pullleft']/ul/li[3]/a
${displayBtn}    css:.btn-info
${text}     id:demo1

*** Test Cases ***
Handle TextBox Alert
    Open the Browser with URL
    Select the Alert with TextBox Option
    Verify text on entered on textbox is displayed as message

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

Select the Alert with TextBox Option
    Click Element    ${textboxOption}
    Click Button     ${displayBtn}

Verify text on entered on textbox is displayed as message
    Input Text Into Alert     Hello     ACCEPT
    Element Text Should Be    ${text}      Hello Hello How are you today

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

How to handle multiple windows in Robot Framework 

HOME

In this tutorial, we will automate the switching of Windows 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.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.

    How to create a test to automate the switching of the windows in Robot Framework?

    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.

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

    Step 3 – 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. Similarly, you can use Firefox, edge, safari, and many more browsers.

    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 4 – Automate the switching of windows

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

    To work with Windows, 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 when we click on “Open New Separate Windows”, then click on the “click” button, a new child window opens – Selenium.dev.

    Let us inspect the locator of the NEW Window.

    Below is an example of switching windows in Robot Framework.

    *** Settings ***
    Documentation    To validate the switching of windows
    Library     SeleniumLibrary
    Test Teardown    Close Browser
    
    *** Variables ***
    ${mainPageText}    xpath://div[@class='col-sm-8 col-xs-8 col-md-8']/h1
    
    *** Test Cases ***
    Switch windows
        Open the Browser with URL
        Select the button to switch to child window
        Verify the child window is opened
        Verify the user is switched back to parent window
    
    *** Keywords ***
    Open the Browser with URL
        Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework/drivers/chromedriver_linux64
        Go To    https://demo.automationtesting.in/Windows.html
        Maximize Browser Window
        Set Selenium Implicit Wait    2
    
    Select the button to switch to child window
        Click Element    xpath://div[@class='tabpane pullleft']/ul/li[2]/a
        Click Button    css:.btn-primary
    
    
    Verify the child window is opened
        Switch Window    NEW
        Page Should Contain    Selenium automates browsers
    
    
    Verify the user is switched back to parent window
         Switch Window    MAIN
         Element Text Should Be     ${mainPageText}    Automation Demo Site
    

    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/Windows.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. Click Element − This keyword is used to click the element identified by the locator. In this case, it is “Open new seperate windows” link.

    6. Click Button – This keyword is used to click the button identified by the locator. In this case, it is “Click” button.

    7. Switch Window NEW – This keyword is used to switch to the latest opened window.

    8. Page Should Contain – This keyword is used to verify that the current page contains the text specified. Here, we are checking if the newly opened windows contain the text “Selenium automates browsers”.

    9. Switch Window MAIN – This keyword is used to switch to the main window.

    10. Element Text Should Be – This keyword is used to verify that the current page contains the exact text identified by the locator. Here, we are checking if we switched back to the main window and the main window contains the exact text “Automation Demo Site”.

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

    Step 5 – Execute the tests

    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 SwitchWindow_Demo.robot
    

    The output of the above program is

    Step 5 – 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).

    Multiple Window Switch

    Selenium WebDriver assigns an alphanumeric id to each window as soon as the WebDriver object is instantiated. This unique alphanumeric id is called a window handle. Selenium uses this unique id to switch control among several windows. In simple terms, each unique window has a unique ID, so that Selenium can differentiate when it is switching controls from one window to the other.

    The below page shows that when we click on “Open Separate Multiple Windows”, then click on the “click” button, 2 new child windows open – Selenium.dev and Demo page.

    Below is an example of switching between multiple windows.

    *** Settings ***
    Documentation    To validate the switching between multiple windows
    Library     SeleniumLibrary
    Test Teardown    Close Browser
    
    *** Variables ***
    ${mainPageText}    xpath://div[@class='col-sm-8 col-xs-8 col-md-8']/h1
    
    *** Test Cases ***
    Multiple Windows switch
        Open the Browser with URL
        Select the button to switch to child window
        Verify child windows are opened
        Verify user switched back to parent window
    
    *** Keywords ***
    Open the Browser with URL
        Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework/drivers/chromedriver_linux64
        Go To    https://demo.automationtesting.in/Windows.html
        Maximize Browser Window
        Set Selenium Implicit Wait    5
    
    Select the button to switch to child window
        Click Element    xpath://div[@class='tabpane pullleft']/ul/li[3]/a
        Click Button    xpath:.//*[@id='Multiple']/button
    
    
    Verify child windows are opened
        @{windowHandle}=    Get Window Handles
    
        Switch Window   title:Selenium
        Page Should Contain     Selenium automates browsers. That's it!
    
        Switch Window   title:Index
        Page Should Contain Textfield      id:email
    
    
    Verify user switched back to parent window
         Switch Window    MAIN
         Element Text Should Be     ${mainPageText}    Automation Demo Site
    

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

    1. Get Window Handles − The keyword returns all child window handles of the selected browser as a list. Here, it will return 3 window handles.

    2. Switch Window title:Selenium – This keyword is used to switch to the window whose title is identified by the locator “Selenium”.

    3. Page Should Contain Textfield – This keyword verifies the text field identified by the locator found from the current page.

    Step 1 – Execute the tests

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

    robot MultipleWindows_Demo.robot
    

    The output of the above program is

    Step 2 – View Report and Log

    Report

    Log

    In the log, we can see that Get Window Handles has 3 alphanumeric id.

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

    How to handle dropdowns in Robot Framework 

    HOME

    In this tutorial, we will automate the execution of DropDown 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.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.

    How to create a test to automate the options of dropdown in Robot Framework?

    Step 4 – 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 DropDown_Demo.robot as shown below:

    Step 5 – 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 6 – Automate the selection of options for DropDown

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

    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 multiple DropDown options.

    Let us inspect the locator of DropDown.

    Below is an example of selecting the options in DropDown.

    *** Settings ***
    Documentation    To validate the selection of DropDown
    Library     SeleniumLibrary
    Test Teardown    Close Browser
    
    *** Test Cases ***
    Select options in DropDown
        Open the Browser with URL
        Select the dropdown options APIs by value
        Select the dropdown options Microsoft Excel by index
        Select the dropdown options CSS by label
    
    *** 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
    
    Select the dropdown options APIs by value
        Select From List By Value       id:Skills   APIs
    
    
    Select the dropdown options Microsoft Excel by index
        Select From List By Index        id:Skills   43
    
    Select the dropdown options CSS by label
        Select From List By Label       id:Skills   CSS
    
    
    

    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. Select From List By Value − This keyword is used to select APIs option from dropdown on the current page by value.

    6. Select From List By Index – This keyword is used to select Microsoft Excel option from dropdown on the current page by index.

    7. Select From List By Label – This keyword is used to select CSS option from the dropdown on the current page by label.

    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 7 – Execute the tests

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

    robot DropDown_Demo.robot
    

    The output of the above program is

    Step 8 – 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!!

    How to handle radio buttons in Robot Framework 

    HOME

    In this tutorial, we will automate the execution of the Radio Button 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.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.

    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 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 located on the current page.

    6. Page Should Not Contain Radio Button – This keyword is used to find that the radio buttons are not locator on the current page.

    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.

    robot RadioButton_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!!

    What is Resource File in Robot Framework 

    HOME

    What is Resource File?

    In Robot Framework, a resource file is a file that contains reusable keywords, variables, and other settings that can be used across multiple test cases or test suites. Resource files are used to organize and centralize common functionality and reduce duplication of effort in test automation.

    Resource files are typically created in plain text format using the .robot file extension. They can include user-defined keywords, as well as built-in keywords and libraries that are imported for use in test cases. Variables can also be defined in resource files, and these variables can be used to store data that is used across multiple test cases.

    Example of Resource File

    *** Settings ***
    Documentation    A resource file with reusable keywords and variables.
    Library     SeleniumLibrary
    
    *** Variables ***
    ${valid_username}     Admin
    ${valid_password}       admin123
    ${invalid_username}     1234
    ${invalid_password}     45678
    ${url}      https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
    
    *** Keywords ***
    
    Open the Browser with URL
        Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework/drivers/chromedriver_linux64
        Go To       ${url}
        Maximize Browser Window
        Set Selenium Implicit Wait    5
    
    Close Browser Session
        Close Browser
    

    In this tutorial, we will create a project in PyCharms and show the use of Resource File 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 – 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.

    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 test using Resource File 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 PageObject

    Right-click on the new directory and select New File and provide the name as LoginPage.robot and resources.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 Test using the Resource file

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

    Test 1

    Test 2

    We need locators to identify various web elements on the page.

    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

    Below is an example of a LoginPage.robot

    *** Settings ***
    Documentation       Tests to login to Login Page
    Library     SeleniumLibrary
    Resource       resources.robot
    
    *** Variables ***
    ${Login_Error_Message}      css:.oxd-alert-content--error
    ${Dashboard_Text}       css:.oxd-topbar-header-breadcrumb-module
    
    *** Test Cases ***
    
    Validate Unsuccessful Login
        Open the Browser with URL
        Fill the login form     ${valid_username}       ${invalid_password}
        verify error message is correct
        Close Browser Session
    
    Validate successful Login
        Open the Browser with URL
        Fill the login form     ${valid_username}       ${valid_password}
        Verify Dashboard page opens
        Close Browser Session
    
    *** Keywords ***
    
    Fill the login form
        [Arguments]    ${username}      ${password}
       Input Text    css:input[name=username]   ${username}
       Input Password    css:input[name=password]   ${password}
       Click Button    css:.orangehrm-login-button
    
    
    Verify error message is correct
        Element Text Should Be    ${Login_Error_Message}    Invalid credentials
    
    Verify Dashboard page opens
        Element Text Should Be    ${Dashboard_Text}     Dashboard
    

    As you can see, some keywords are not present in this file. The keywords which we know are going to be common for other test files are placed in a Resource File. We have imported the Resource file by using this command in Settings.

    *** Settings ***
    Resource       resources.robot
    

    Below is an example of the resources.robot file.

    *** Settings ***
    Documentation    A resource file with reusable keywords and variables.
    Library     SeleniumLibrary
    
    *** Variables ***
    ${valid_username}     Admin
    ${valid_password}       admin123
    ${invalid_username}     1234
    ${invalid_password}     45678
    ${url}      https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
    
    *** Keywords ***
    
    Open the Browser with URL
        Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework/drivers/chromedriver_linux64
        Go To       ${url}
        Maximize Browser Window
        Set Selenium Implicit Wait    5
    
    Close Browser Session
        Close Browser
    

    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.

    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. Input Text − This keyword is used to type the given text in the specified textbox identified by the locator name:username.

    6. Input Password – This keyword is used to type the given text in the specified password identified by the locator name:password.

    The difference compared to Input Text is that this keyword does not log the given password on the INFO level.

    7. Click button – This keyword is used to click on the button with location css:.orangehrm-login-button.

    8. ${result} – This is a variable that holds the text value of the error message that is located by css:.oxd-alert-content-text

    9. Get Text – This keyword returns the text value of the element identified by located by css:.oxd-alert-content-text.

    10. Should Be Equal As Strings – This keyword is used from builtIn keyword. This keyword returns false if objects are unequal after converting them to strings.

    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 LoginPage.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!!

    How to handle text box in Robot Framework 

    HOME

    In this tutorial, we will create a project in PyCharms and enter data in TextBox 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 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.

    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 Test_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 – Enter Data in Textbox

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

    To work with the textbox, 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

    Below is an example of entering data in TextBox.

    *** 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
    

    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.

    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. Input Text − This keyword is used to type the given text in the specified textbox identified by the locator name:username.

    6. Input Password – This keyword is used to type the given text in the specified password identified by the locator name:password.

    The difference compared to Input Text is that this keyword does not log the given password on the INFO level.

    7. Click button – This keyword is used to click on the button with location css:.orangehrm-login-button.

    8. ${result} – This is a variable that holds the text value of the error message that is located by css:.oxd-alert-content-text

    9. Get Text – This keyword returns the text value of the element identified by located by css:.oxd-alert-content-text.

    10. Should Be Equal As Strings – This keyword is used from builtIn keyword. This keyword returns false if objects are unequal after converting them to strings.

    Step 6 – Execute the tests

    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

    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).

    In the below image of the log, we can see that the text entered by the user is shown here, whereas the password does not show the value of the password.

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

    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!!