How to Merge Robot Framework Test Reports

HOME

In this tutorial, we will discuss the steps to combine the test reports in a single test report in the 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 3 new directories in the new project

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

Below is the image of the new directories.

Step 3 – Download ChromeBinaries, Geckodriver and msedgedriver binaries

Download ChromeBinaries, Geckodriver and msedgedriver binaries and place in Drivers directory. This directory contains the browser binary in it. As we are using Chrome, will keep chromedriver.exe here.

The tests are going to use the Chrome browser, Firefox and Edge browsers, so we need to download the corresponding driver binaries to open a blank browser.

https://chromedriver.chromium.org/

Releases · mozilla/geckodriver

Microsoft Edge WebDriver | Microsoft Edge Developer

I will rename chromedriver.exe to Chrome, msedgedriver.exe to Edge and geckodriver.exe to Firefox.

Step 4 – Create Test Files

This directory contains multiple test case files consisting of test steps. 

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

Below is the code for LoginPageTests.robot

*** Settings ***
Documentation       Tests to login to Login Page
Library     SeleniumLibrary
Test Setup      Open the Browser with URL
Test Teardown   Close Browser Session
Resource       ../Resources/GenericResources.robot
Resource       ../Resources/LoginResources.robot

*** Test Cases ***

Validate Unsuccessful Login using invalid credentials

    LoginResources.Fill the login form     ${valid_username}       ${invalid_password}
    LoginResources.Verify the error message is correct


Validate successful Login

    LoginResources.Fill the login form     ${valid_username}       ${valid_password}
    DashboardResources.Verify Dashboard page opens

Step 5 – Create Resources file for each page

It maintains the files which contain page elements as well as corresponding keywords. 

Right-click on the new directory and select New File and provide the name as LoginResources.robot, DashboardResources.robot and GenericResources.robot as shown below:

GenericResources.robot contains the keywords that are common to all the tests, like the opening of the browser or closing of the browser.

*** 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
${browser}      Chrome   #Default browser, if no browser provided


*** Keywords ***

Open the Browser with URL
    Open Browser   ${url}    ${browser}   executable_path=C:/Users/vibha/Documents/Automation/Python/CrossBrowser_RobotFramework/Drivers/${browser}
    Maximize Browser Window
    Set Selenium Implicit Wait    5

Close Browser Session
    Close Browser

Below is the code for LoginResources.robot

*** Settings ***
Documentation        All the page objects and keywords of landing page
Library     SeleniumLibrary

*** Variables ***
${login_error_message}      css:.oxd-alert-content--error
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module
${missing_username_error_message}    xpath://*[@class='oxd-form']/div[1]/div/span
${missing_password_error_message}   xpath://*[@class='oxd-form']/div[2]/div/span
${forgot_password_link}   xpath://div[@class='orangehrm-login-forgot']/p

*** 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 the error message is correct
    Element Text Should Be    ${login_error_message}    Invalid credentials

Below is the code for DashboardResources.robot

*** Settings ***
Documentation        All the page objects and keywords of Dashboard page
Library     SeleniumLibrary

*** Variables ***
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module

*** Keywords ***

Verify Dashboard page opens
    Element Text Should Be    ${dashboard_title}      Dashboard

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

1. Open Browser − The keyword opens a new browser instance to the optional url.

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

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

4. Close Browser – Close the current browser.

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 the button identified by the locator. In this case, it is “Login” button.

8. 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 the exact text “Invalid Credentials”.

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

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

Step 6 – Execute the tests

Run your tests separately for each browser (e.g., Chrome, Firefox, Edge), generating an individual output XML file for each. For example, use the below command to run the tests using the Chrome browser:

robot --variable browser:Chrome --output output_chrome.xml .

The output of the above program is

robot --variable browser:Firefox --output output_firefox.xml .
robot --variable browser:Edge --output output_edge.xml .

rebot --outputdir Report --report Consolidated_Report.html output_chrome.xml output_edge.xml output_firefox.xml

Step 8 – View Report and Log

We have total 6 test cases passed (2 test case for each browser).

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

The screenshots will be included in the log.html file under the specific failed test case step. 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!!

Additional Tutorials

How to Install Python on Windows 11
How to install and setup Robot Framework for Python
How to rerun failed tests in Robot Framework
How to implement tagging in Robot Framework
 How to set variable values from Runtime command in Robot Framework
How to load data from CSV files in the Robot Framework?

Add Screenshots to Failed Tests in Robot Framework

HOME

In this tutorial, we will discuss the steps to add the screenshots to the failed tests in the 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 3 new directories in the new project

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

Below is the image of the new directories.

Step 3 – Download ChromeBinaries and place in Drivers directory

This directory contains the browser binary in it. As we are using Chrome, will keep chromedriver.exe here.

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/

I will rename chromedriver.exe to Chrome.

Step 4 – Create Test Files

This directory contains multiple test case files consisting of test steps. 

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

Below is the code for LoginPageTests.robot

*** Settings ***
Documentation       Tests to login to Login Page
Library     SeleniumLibrary
Test Setup      Open the Browser with URL
Test Teardown   Capture Screenshot On Failure
Suite Teardown  Close Browser Session
Resource       ../Resources/GenericResources.robot
Resource       ../Resources/LoginResources.robot

*** Test Cases ***

Validate Unsuccessful Login using invalid credentials

    LoginResources.Fill the login form     ${valid_username}       ${invalid_password}
    LoginResources.Verify the error message is correct


Validate successful Login

    LoginResources.Fill the login form     ${valid_username}       ${valid_password}
    DashboardResources.Verify Dashboard page opens


Validate Unsuccessful Login for blank username

     LoginResources.Fill the login form     ${blank_username}       ${valid_password}
     LoginResources.Verify the error message is displayed for username

Step 5 – Create Resources file for each page

It maintains the files which contain page elements as well as corresponding keywords. 

Right-click on the new directory and select New File and provide the name as LoginResources.robot, DashboardResources.robot and GenericResources.robot as shown below:

GenericResources.robot contains the keywords that are common to all the tests, like the opening of the browser or closing of the browser.

*** 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
${blank_username}
${url}        https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
${browser_name}      Chrome
${output_dir}      ./screenshots


*** Keywords ***

Open the Browser with URL
    Open Browser   ${url}    ${browser_name}   executable_path=C:/Users/vibha/Documents/Automation/Python/CrossBrowser_RobotFramework/Drivers/${browser_name}
    Maximize Browser Window
    Set Selenium Implicit Wait    5

Capture screenshot On Failure
    Run Keyword If Test Failed    Capture Page Screenshot    ${output_dir}/${TEST NAME}.png
    Close Browser

Close Browser Session
    Close Browser

Below is the code for LoginResources.robot

*** Settings ***
Documentation        All the page objects and keywords of landing page
Library     SeleniumLibrary

*** Variables ***
${login_error_message}      css:.oxd-alert-content--error
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module
${missing_username_error_message}    xpath://*[@class='oxd-form']/div[1]/div/span

*** 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 the error message is correct
    Element Text Should Be    ${login_error_message}    Invalid credentials


Verify the error message is displayed for username
     Element Text Should Be    ${missing_username_error_message}      Required

Below is the code for DashboardResources.robot

*** Settings ***
Documentation        All the page objects and keywords of Dashboard page
Library     SeleniumLibrary

*** Variables ***
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module

*** Keywords ***

Verify Dashboard page opens
    Element Text Should Be    ${dashboard_title}      Dashboard

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

1. Open Browser − The keyword opens a new browser instance to the optional url.

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

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

5. Close Browser – Close the current browser.

6. Input Text − This keyword is used to type the given text in the specified textbox identified by the locator name:username.

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

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

9. 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 the exact text “Invalid Credentials”.

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

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 .

The output of the above program is

Step 8 – View Report and Log

We have 2 test cases passed and 1 failed. 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

The screenshots will be included in the log.html file under the specific failed test case step. 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!!

Additional Tutorials

How to Install Python on Windows 11
How to install and setup Robot Framework for Python
How to rerun failed tests in Robot Framework
How to implement tagging in Robot Framework
 How to set variable values from Runtime command in Robot Framework
How to load data from CSV files in the Robot Framework?

How to run headless tests in Robot Framework 

HOME

In this tutorial, we will run the tests in headless mode 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.

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

Step 3 – Execute tests in headless mode

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

Below is an example of executing Chrome tests in headless mode.

*** 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
    Open Browser   https://opensource-demo.orangehrmlive.com/web/index.php/auth/login    headlesschrome
    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

Below is an example of executing Firefox tests in headless mode.

*** 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
    Open Browser   https://opensource-demo.orangehrmlive.com/web/index.php/auth/login    headlessfirefox
    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. Open Browser  − The keyword opens a new browser instance to the optional URL.

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

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

4. Input Text − This keyword is used to type the given text in the specified textbox identified by the locator name:username.

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

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

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

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

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

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

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

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

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

How to rerun failed tests in Robot Framework
How to use Drag and Drop in Robot Framework? 
How to set variable values from Runtime command in Robot Framework
Page Object Model in Robot Framework with Selenium and Python
Parallel Testing in Robot Framework 
Integration of Allure Report with Robot Framework 

How to use Drag and Drop in Robot Framework?

HOME

In this tutorial, we will discuss in detail how we can perform Drag and Drop actions 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 the name as Tests

Below is the image of the new directory.

Right-click on the new directory, select New File and provide the name as Drag_And_Drop_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.

https://chromedriver.chromium.org/

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

Step 4 – Automate the drag and drop option

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

  • Open the Browser with the URL
  • Verify element Text before drag
  • Drag the element and drop
  • Verify element Text after drag

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

Let us inspect the locator of the drag and drop option.

Below is an example of a drag and drop option.

*** Settings ***
Documentation    To drag the box
Library     SeleniumLibrary

*** Test Cases ***
Verify that the user can drag and drop elements
    [documentation]  This test case verifies that a user can drag and drop an element from source to destination
    Open the Browser with URL
    Verify element Text before drag
    Drag the element and drop
    Verify element Text after drag

*** Keywords ***
Open the Browser with URL
    Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/Chrome
    Go To    https://demoqa.com/droppable
    Maximize Browser Window
    Set Selenium Implicit Wait    5

Verify element Text before drag
    Element Text Should Be      id:droppable  Drop here  timeout=5  #Before Drag and Drop

Drag the element and drop
    Drag And Drop   id:draggable   id:droppable

Verify element Text after drag
    Element Text Should Be  id:droppable  Dropped!  timeout=5  #After Drag and Drop

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://demoqa.com/droppable.

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.

6. Drag And Drop – Drags the element identified by the locator into the target element.  The locator argument is the locator of the dragged element and the target is the locator of the target.

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

Before

After

Step 5 – Automate the Drag and Drop by Offset option

Drag And Drop By Offset – Drags the element identified with the locator by xoffset/yoffset.

*** Settings ***
Documentation    To drag the box
Library     SeleniumLibrary
Test Teardown    Close Browser

*** Test Cases ***

Verify that the user can drag and drop element by offset
    [documentation]  This test case verifies that a user can drag and drop an element by offset
    Open the Browser with URL
    Verify element Text before drag
    Drag the element and drop locator by xoffset/yoffset
    Verify no change in Text


*** Keywords ***
Open the Browser with URL
    Create Webdriver    Chrome  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/Chrome
    Go To    https://demoqa.com/droppable
    Maximize Browser Window
    Set Selenium Implicit Wait    5

Verify element Text before drag
    Element Text Should Be      id:droppable  Drop here  timeout=5  #Before Drag and Drop

Drag the element and drop locator by xoffset/yoffset
     Drag And Drop By Offset  id:draggable  50  70

Verify no change in Text
     Element Text Should Be  id:droppable  Drop here  timeout=5  #After Drag and Drop

Before

After

Step 6 – Execute the tests

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

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

How to set variable values from Runtime command in Robot Framework
Page Object Model in Robot Framework with Selenium and Python
Parallel Testing in Robot Framework
How to run headless tests in Robot Framework 
Integration of Allure Report with Robot Framework 

How to write tests in Robot Framework in BDD Format

Last Modified Date

HOME

In this tutorial, we will run the tests in the BDD format in Robot Framework.

What is BDD?

BDD is an Agile software development process in which an application is documented and designed around the behaviour that a user expects to see when interacting with it. BDD helps to avoid bloat, excessive code, unnecessary features, and lack of focus by encouraging developers to focus only on the requested behaviours of an app or program. This methodology combines, augments, and refines test-driven development (TDD) and acceptance testing practices.

The Given-When-Then syntax is a commonly used structure for writing user stories and acceptance criteria in a behaviour-driven development (BDD). It is used to describe the desired behaviour of a system in a clear, concise, and consistent manner.

The structure is broken down into three parts:

  • Given: This section describes the initial state or context of the system. It sets the scene for the scenario being tested.
  • When: This section describes the action or event that occurs. It specifies the trigger for the scenario being tested.
  • Then: This section describes the expected outcome or result of the scenario. It defines the acceptance criteria for the scenario being tested.

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 run tests in BDD format 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 BDD_Demo.robot as shown below:

Step 3 – Execute the tests

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

Below is an example of tests in BDD format.

*** Settings ***
Documentation       Tests to login to Login Page
Library     SeleniumLibrary

*** Variables ***
${valid_username}     Admin
${valid_password}       admin123
${invalid_password}     45678
${url}      https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
${browser_name}      Chrome
${login_error_message}      css:.oxd-alert-content--error
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module


*** Test Cases ***

Validate Unsuccessful Login using invalid credentials
    [Tags]    SMOKE
    Given I open the Browser with URL
    When I fill the login form     ${valid_username}       ${invalid_password}
    Then I verify the error message is correct
    And Close Browser Session

Validate successful Login
    [Tags]    UAT
    Given I open the Browser with URL
    When I fill the login form     ${valid_username}       ${valid_password}
    Then I verify Dashboard page opens
    And Close Browser Session

*** Keywords ***

Given I open the Browser with URL
    Create Webdriver    ${browser_name}  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/${browser_name}
    Go To       ${url}
    Maximize Browser Window
    Set Selenium Implicit Wait    5

When I 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

Then I verify the error message is correct
    Element Text Should Be    ${login_error_message}    Invalid credentials

Then I verify Dashboard page opens
    Element Text Should Be    ${dashboard_title}      Dashboard


And Close Browser Session
    Close Browser

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

1. Open Browser  − The keyword opens a new browser instance to the optional URL.

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

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

4. Input Text − This keyword is used to type the given text in the specified textbox identified by the locator name:username.

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

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

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

8. Element Text Should Be  – This keyword is used to verify that the element locator contains exact the text expected.

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

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

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

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

Integration of Allure Report with Robot Framework

Last Updated on

HOME

In this tutorial, we will discuss the integration of Allure Report with the Robot Framework.

Table of Contents:

  1. What is Allure Report?
  2. Prerequisite
  3. Implementation Steps
    1. Create a new project
    2. Install allure-robotframework plugin
    3. Add allure-robotframework package to the PyCharms
    4. Create 3 new directories in the new project
    5. Create the test code
    6. Execute the tests
    7. View Report and Log
    8. Generate the Allure Report
    9. Allure Report Dashboard
    10. Categories in Allure Report
    11. Suites in Allure Report
    12. Graphs in Allure Report
    13. Timeline in Allure Report
    14. Behaviours of Allure Report
    15. Packages in Allure Report

What is Allure Report?

Allure Framework is a flexible lightweight multi-language test report tool that not only shows a very concise representation of what has been tested in a neat web report form but allows everyone participating in the development process to extract maximum useful information from everyday execution of tests.

From the dev/qa perspective, Allure reports shorten common defect lifecycle: test failures can be divided into bugs and broken tests, also logs, steps, fixtures, attachments, timings, history, and integrations with TMS and bug-tracking systems can be configured, so the responsible developers and testers will have all information at hand.

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 – Install allure-robotframework plugin

Go to the command prompt and run the below-mentioned command to download the plugin:

pip install allure-robotframework

The below image shows that the plugin is installed successfully.

Step 3 – Add allure-robotframework package to the PyCharms

Go to File->Settings ->Project:RobotFramework_Demo ->Python Interpreter.

Click on the “+” sign and enter allure-r in the search bar. It will show a list of packages. Select the “allure-robotframework” package and click on the “Install Package”.

Once the package is installed, we will see the message that the package is installed successfully.

Once the package is installed, it can be seen under the package list as shown below:

Step 4 – Create 3 new directories in the new project

Right-Click on the project, select New->Directory and provide the name as TestCases, Drivers, and Resources

Step 5 – Create the test code

To know the framework, tests, and corresponding keywords can be referred from here – Page Object Model in the Robot Framework.

Step 6 – Execute the tests

We need the below command to run the Robot Framework script using Allure listener.

 robot --listener allure_robotframework --outputdir ./output/robot ./TestCases

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.

These reports are generated in the output/robot folder as I have provided –outputdir ./output/robot in the command line.

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

As one of the tests purposefully failed to demonstrate how the report would look in the event of a failure, we can see that it is now a Red report. The framework generated the following report:

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

Step 8 – Generate the Allure Report

To create Allure Report, use the below command

 allure serve ./output/allure

This will generate the beautiful Allure Test Report as shown below.

Step 9 – Allure Report Dashboard

The overview page hosts several default widgets representing the basic characteristics of your project and test environment.

  1. Statistics – overall report statistics.
  2. Launches – if this report represents several test launches, statistics per launch will be shown here.
  3. Behaviours – information on results aggregated according to stories and features.
  4. Executors – information on test executors that were used to run the tests.
  5. History Trend – if tests accumulated some historical data, it’s trend will be calculated and shown on the graph.
  6. Environment – information on the test environment.

Categories in Allure Report

The categories tab gives you a way to create custom defect classifications to apply for test results. There are two categories of defects – Product Defects (failed tests) and Test Defects (broken tests).

Suites in Allure Report

On the Suites tab a standard structural representation of executed tests, grouped by suites and classes can be found.

Graphs in Allure Report

Graphs allow you to see different statistics collected from the test data: statuses breakdown or severity and duration diagrams.

Timeline in Allure Report

The timeline tab visualizes retrospective of tests execution, allure adaptors collect precise timings of tests, and here on this tab, they are arranged accordingly to their sequential or parallel timing structure.

Behaviours of Allure Report

This tab groups test results according to Epic, Feature, and Story tags.

Packages in Allure Report

The packages tab represents a tree-like layout of test results, grouped by different packages.

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

Parallel Testing in the Robot Framework

HOME

In this tutorial, we will discuss running the tests parallelly in the Robot Framework. To run the tests parallelly, we need to have pabot installed on the machine. Pabot is a parallel test runner for Robot Framework. It can be used to run tests in parallel on a single machine with multiple processes.

What is Parallel Testing?

Parallel testing is an automated testing process that allows developers and testers to run numerous tests against various real-world device combinations and browser setups at the same time. Parallel testing aims to solve time restrictions by distributing tests across available resources.

For example, if 20 test cases take 100 minutes to complete, 10 parallel execution might run 2 test cases each, reducing overall testing time to 10 minutes.

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 – Download pabot plugin

Go to command prompt and run the below mentioned command to download pabot:

 pip install -U robotframework-pabot

Step 3 – Add pabot package to the PyCharms

Go to File->Settings ->Project:RobotFramework_Demo ->Python Interpreter.

Click on the “+” sign and enter pabot in the search bar. It will show a list of packages. Select the “robotframework-pabot” package and click on the “Install Package”.

Once the package is installed, we will see the message that the package is installed successfully.

Once the package is installed, it can be seen under the package list as shown below:

Click the “Apply” and “OK” button.

Step 4 – Create 3 new directories in the new project

Right-Click on the project, select New->Directory, and provide the name as TestCases, Drivers, and Resources

Below is the image of the new directories.

Step 5 – Download ChromeBinaries and place them in the Drivers directory

This directory contains the browser binary in it. As we are using Chrome, will keep chromedriver.exe here.

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/

I will rename chromedriver.exe to Chrome.

Step 6 – Create Test Files

This directory contains multiple test case files consisting of test steps. 

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

Below is the code for LoginPageTests.robot

*** Settings ***
Documentation       Tests to login to Login Page
Library     SeleniumLibrary
Test Setup      Open the Browser with URL
Test Teardown   Close Browser Session
Resource       ../Resources/GenericResources.robot
Resource       ../Resources/LoginResources.robot
Resource      ../Resources/DashboardResources.robot

*** Test Cases ***

Validate Unsuccessful Login using invalid credentials

    LoginResources.Fill the login form     ${valid_username}       ${invalid_password}
    LoginResources.Verify the error message is correct


Validate Unsuccessful Login for blank username

     LoginResources.Fill the login form     ${blank_username}       ${valid_password}
     LoginResources.Verify the error message is displayed for username


Validate Unsuccessful Login for blank password

     LoginResources.Fill the login form     ${valid_username}       ${blank_password}
     LoginResources.Verify the error message is displayed for password


Validate successful Login


    LoginResources.Fill the login form     ${valid_username}       ${valid_password}
    DashboardResources.Verify Dashboard page opens

Below is the code for ForgetPasswordTests.robot

*** Settings ***
Documentation       Tests to validate Forgot Your Password Page functionality
Library     SeleniumLibrary
Test Setup      Open the Browser with URL
Test Teardown   Close Browser Session
Resource       ../Resources/GenericResources.robot
Resource       ../Resources/LoginResources.robot
Resource      ../Resources/ForgetPasswordResources.robot


*** Test Cases ***

Validate Reset Password Functionality

    LoginResources.Go to Forgot Your Password Page
    ForgetPasswordResources.Verify Forgot Your Password Page opens
    ForgetPasswordResources.Fill the Forgot Password Page
    ForgetPasswordResources.Verify the message

Validate Cancel Functionality

    LoginResources.Go to Forgot Your Password Page
    ForgetPasswordResources.Verify Forgot Your Password Page opens
    ForgetPasswordResources.Cancel the Reset Password
    ForgetPasswordResources.Verify that Login Page is displayed


Step 7 – Create Resources file for each page

It maintains the files which contain page elements as well as corresponding keywords. 

Right-click on the new directory and select New File and provide the name as LoginResources.robot, DashboardResources.robot, GenericResources.robot, and ForgetPasswordResources.robot as shown below:

GenericResources.robot contains the keywords that are common to all the tests, like the opening of the browser or closing of the browser.

*** 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
${blank_username}
${blank_password}
${url}      https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
${browser_name}      Chrome

*** Keywords ***

Open the Browser with URL
    Create Webdriver    ${browser_name}  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/${browser_name}
    Go To       ${url}
    Maximize Browser Window
    Set Selenium Implicit Wait    5

Close Browser Session
    Close Browser

Below is the code for LoginResources.robot

*** Settings ***
Documentation        All the page objects and keywords of landing page
Library     SeleniumLibrary

*** Variables ***
${login_error_message}      css:.oxd-alert-content--error
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module
${missing_username_error_message}    xpath://*[@class='oxd-form']/div[1]/div/span
${missing_password_error_message}   xpath://*[@class='oxd-form']/div[2]/div/span
${forgot_password_link}   xpath://div[@class='orangehrm-login-forgot']/p

*** 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 the error message is correct
    Element Text Should Be    ${login_error_message}    Invalid credentials


Verify the error message is displayed for username
     Element Text Should Be    ${missing_username_error_message}      Required

Verify the error message is displayed for password
      Element Text Should Be    ${missing_password_error_message}      Required

Go to Forgot Your Password Page
    Click Element      ${forgot_password_link}

Below is the code for DashboardResources.robot

*** Settings ***
Documentation        All the page objects and keywords of Dashboard page
Library     SeleniumLibrary

*** Variables ***
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module

*** Keywords ***

Verify Dashboard page opens
    Element Text Should Be    ${dashboard_title}      Dashboard

Below is the code for ForgetPasswordResources.robot

*** Settings ***
Documentation       All the page objects and keywords of Forget Password page
Library     SeleniumLibrary

*** Variables ***
${forgot_page_title}       css:.orangehrm-forgot-password-title
${username}     css:.oxd-input--active
${reset_btn}     css:.orangehrm-forgot-password-button--reset
${cancel_btn}    css:.orangehrm-forgot-password-button--cancel
${reset_message}      xpath://div[@class='orangehrm-card-container']/h6
${login_page_title}   xpath://*[@class='orangehrm-login-slot']/h5

*** Keywords ***

Verify Forgot Your Password Page opens
    Element Text Should Be    ${forgot_page_title}      Reset Password

Fill the Forgot Password Page
   Input Text        ${username}     abc@gmail.com
   Click Button    ${reset_btn}

Verify the message
    Element Text Should Be    ${reset_message}      Reset Password link sent successfully

Cancel the Reset Password
    Click Button    ${cancel_btn}

Verify that Login Page is displayed
    Element Text Should Be    ${login_page_title}       Login

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 the button identified by the locator. In this case, it is “Login” button.

8. 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 the exact text “Invalid Credentials”.

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 8 – Split execution to suite files

We need the below command to run the Robot Framework script. This will start all the test suites parallelly. We have 2 test files, so they started parallelly.

pabot .

The output of the above program is

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

Step 10 – Split execution on test level

In this case, the tests present in a test file will be executed parallelly.

 pabot --testlevelsplit LoginPageTests.robot

The below image shows that all the tests present in LoginPageTests.robot file started parallelly.

The below report shows that all the tests are started simultaneously.

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

Additional Tutorials

How to Install Python on Windows 11
How to install and setup Robot Framework for Python
How to rerun failed tests in Robot Framework
Page Object Model in the Robot Framework
How to integrate Robot Framework with Jenkins
How to load data from CSV files in the Robot Framework?

Page Object Model in the Robot Framework

HOME

In this tutorial, we will discuss Page Object Model in the Robot Framework.

What is Page Object Model Framework?

Page Object is a prominent Design Pattern in test automation for improving test maintenance and eliminating code duplication. A page object is an object-oriented class that acts as an interface to your AUT’s page. The methods of this page object class are then used by the tests anytime they need to interact with the UI of that page. The benefit is that if the page’s UI changes, just the code within the page object needs to update, rather not the tests themselves. As a result, all updates to accommodate that new UI are centralized.

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 Page Object Model tests in Robot Framework?

Step 2 – Create 3 new directories in the new project

Right-Click on the project, select New->Directory, and provide the name as TestCases, Drivers, and Resources

Below is the image of the new directories.

Step 3 – Download ChromeBinaries and place in Drivers directory

This directory contains the browser binary in it. As we are using Chrome, will keep chromedriver.exe here.

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/

I will rename chromedriver.exe to Chrome.

Step 4 – Create Test Files

This directory contains multiple test case files consisting of test steps. 

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

Below is the code for LoginPageTests.robot

*** Settings ***
Documentation       Tests to login to Login Page
Library     SeleniumLibrary
Test Setup      Open the Browser with URL
Test Teardown   Close Browser Session
Resource       ../Resources/GenericResources.robot
Resource       ../Resources/LoginResources.robot
Resource      ../Resources/DashboardResources.robot

*** Test Cases ***

Validate Unsuccessful Login using invalid credentials

    LoginResources.Fill the login form     ${valid_username}       ${invalid_password}
    LoginResources.Verify the error message is correct


Validate Unsuccessful Login for blank username

     LoginResources.Fill the login form     ${blank_username}       ${valid_password}
     LoginResources.Verify the error message is displayed for username


Validate Unsuccessful Login for blank password

     LoginResources.Fill the login form     ${valid_username}       ${blank_password}
     LoginResources.Verify the error message is displayed for password


Validate successful Login


    LoginResources.Fill the login form     ${valid_username}       ${valid_password}
    DashboardResources.Verify Dashboard page opens

Below is the code for ForgetPasswordTests.robot

*** Settings ***
Documentation       Tests to validate Forgot Your Password Page functionality
Library     SeleniumLibrary
Test Setup      Open the Browser with URL
Test Teardown   Close Browser Session
Resource       ../Resources/GenericResources.robot
Resource       ../Resources/LoginResources.robot
Resource      ../Resources/ForgetPasswordResources.robot


*** Test Cases ***

Validate Reset Password Functionality

    LoginResources.Go to Forgot Your Password Page
    ForgetPasswordResources.Verify Forgot Your Password Page opens
    ForgetPasswordResources.Fill the Forgot Password Page
    ForgetPasswordResources.Verify the message

Validate Cancel Functionality

    LoginResources.Go to Forgot Your Password Page
    ForgetPasswordResources.Verify Forgot Your Password Page opens
    ForgetPasswordResources.Cancel the Reset Password
    ForgetPasswordResources.Verify that Login Page is displayed


Step 5 – Create Resources file for each page

It maintains the files which contain page elements as well as corresponding keywords. 

Right-click on the new directory and select New File and provide the name as LoginResources.robot, DashboardResources.robot, GenericResources.robot, and ForgetPasswordResources.robot as shown below:

GenericResources.robot contains the keywords that are common to all the tests, like the opening of the browser or closing of the browser.

*** 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
${blank_username}
${blank_password}
${url}      https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
${browser_name}      Chrome

*** Keywords ***

Open the Browser with URL
    Create Webdriver    ${browser_name}  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/${browser_name}
    Go To       ${url}
    Maximize Browser Window
    Set Selenium Implicit Wait    5

Close Browser Session
    Close Browser

Below is the code for LoginResources.robot

*** Settings ***
Documentation        All the page objects and keywords of landing page
Library     SeleniumLibrary

*** Variables ***
${login_error_message}      css:.oxd-alert-content--error
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module
${missing_username_error_message}    xpath://*[@class='oxd-form']/div[1]/div/span
${missing_password_error_message}   xpath://*[@class='oxd-form']/div[2]/div/span
${forgot_password_link}   xpath://div[@class='orangehrm-login-forgot']/p

*** 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 the error message is correct
    Element Text Should Be    ${login_error_message}    Invalid credentials


Verify the error message is displayed for username
     Element Text Should Be    ${missing_username_error_message}      Required

Verify the error message is displayed for password
      Element Text Should Be    ${missing_password_error_message}      Required

Go to Forgot Your Password Page
    Click Element      ${forgot_password_link}

Below is the code for DashboardResources.robot

*** Settings ***
Documentation        All the page objects and keywords of Dashboard page
Library     SeleniumLibrary

*** Variables ***
${dashboard_title}       css:.oxd-topbar-header-breadcrumb-module

*** Keywords ***

Verify Dashboard page opens
    Element Text Should Be    ${dashboard_title}      Dashboard

Below is the code for ForgetPasswordResources.robot

*** Settings ***
Documentation       All the page objects and keywords of Forget Password page
Library     SeleniumLibrary

*** Variables ***
${forgot_page_title}       css:.orangehrm-forgot-password-title
${username}     css:.oxd-input--active
${reset_btn}     css:.orangehrm-forgot-password-button--reset
${cancel_btn}    css:.orangehrm-forgot-password-button--cancel
${reset_message}      xpath://div[@class='orangehrm-card-container']/h6
${login_page_title}   xpath://*[@class='orangehrm-login-slot']/h5

*** Keywords ***

Verify Forgot Your Password Page opens
    Element Text Should Be    ${forgot_page_title}      Reset Password

Fill the Forgot Password Page
   Input Text        ${username}     abc@gmail.com
   Click Button    ${reset_btn}

Verify the message
    Element Text Should Be    ${reset_message}      Reset Password link sent successfully

Cancel the Reset Password
    Click Button    ${cancel_btn}

Verify that Login Page is displayed
    Element Text Should Be    ${login_page_title}       Login

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 the button identified by the locator. In this case, it is “Login” button.

8. 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 the exact text “Invalid Credentials”.

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 .

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

Additional Tutorials

How to Install Python on Windows 11
How to install and setup Robot Framework for Python
How to rerun failed tests in Robot Framework
How to implement tagging in Robot Framework
 How to set variable values from Runtime command in Robot Framework
How to load data from CSV files in the Robot Framework?

How to load data from CSV files in the Robot Framework?

HOME

In this tutorial, we will discuss data-driven testing in the Robot Framework.

What is Data Driven Testing?

Data Driven Testing is a type of software testing in which test data is maintained in table or spreadsheet format. Data-driven testing enables testers to provide a single test script that may perform tests for all test data from a table and expect the test results to be returned to the same table. Table-driven testing is another name for parameterized testing.

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 – Add datadriver package to the PyCharms

Go to File->Settings ->Project:RobotFramework_Demo ->Python Interpreter.

Click on the “+” sign and enter datadriver in the search bar. It will show a list of packages. Select the “robotframework-datadriver” package and click on the “Install Package”.

Once the package is installed, it can be seen under the package list as shown below:

Step 3 – Create a new directory in the new project

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

Below is the image of the new directory.

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

Step 4 – Create a test data file (.csv)

Create a folder with the name of Resources in the DataDriven directory.

Add a data.csv file that contains the test data in it.

Make sure that fields are separated by commas.

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 – Create a Data Driven Test

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

A locator is an identifier for the web elements used to identify an element on the web page like id, name, class, xpath, css selector.

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 Data-Driven Test.

*** Settings ***
Documentation    To validate the Login Form
Library     SeleniumLibrary
Library    DataDriver       file=Resources/data.csv     encoding=utf_8      dialect=unix
Test Template    Validate Unsuccessful Login

*** Variables ***
${browser_name}     Chrome
${login_btn}        css:.orangehrm-login-button
${login_error_message}      css:.oxd-alert-content--error


*** Test Cases ***
Login to form using ${Username} and ${Password}     abc     123


*** Keywords ***
Validate Unsuccessful Login
    [Arguments]    ${Username}   ${Password}
    Open the Browser with URL
    Fill the login form     ${Username}   ${Password}
    verify error message is correct


Open the Browser with URL
    Create Webdriver    ${browser_name}  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/${browser_name}
    Go To    https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
    Maximize Browser Window
    Set Selenium Implicit Wait    2

Fill the login form
  [Arguments]        ${Username}       ${Password}
   Input Text        name:username     ${Username}
   Input Password    name:password     ${Password}
   Click Button    ${login_btn}

Verify error message is correct
    Element Text Should Be    ${login_error_message}   Invalid credentials
     
Close Browser Session
    Close Browser

In the below image, it shows that there are 3 steps to creating a Data-Driven test from an external data source like .csv.

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 the button identified by the locator. In this case, it is “Login” button.

8. 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 the exact text “Invalid Credentials”.

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

Data-Driven Testing in Robot Framework 

HOME

In this tutorial, we will discuss data-driven testing in the Robot Framework.

What is Data Driven Testing?

Data Driven Testing is a type of software testing in which test data is maintained in table or spreadsheet format. Data-driven testing enables testers to provide a single test script that may perform tests for all test data from a table and expect the test results to be returned to the same table. Table-driven testing is another name for parameterized testing.

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 the name as DataDriven

Below is the image of the new directory.

Right-click on the new directory and select New File and provide the name as DataDrivenTesting_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.

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 – Create a Data Driven Test

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

A locator is an identifier for the web elements used to identify an element on the web page like id, name, class, xpath, css selector.

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 Data-Driven Test

*** Settings ***
Documentation   To validate the Login form
Library     SeleniumLibrary
Test Teardown   Close Browser
Test Template   Validate UnSuccesful Login
Documentation   To validate the Login form
Library     SeleniumLibrary
Test Template   Validate UnSuccesful Login

*** Variables ***
${browser_name}     Chrome
${login_btn}        css:.orangehrm-login-button
${login_error_message}      css:.oxd-alert-content--error


*** Test Cases ***              username        password
Invalid username                abc             admin123
Invalid password                Admin           abc
Special characters              @#$             %$^&
Invalid username and password   abc             abc123


*** Keywords ***
Validate UnSuccesful Login
    [Arguments]     ${username}     ${password}
    Open the Browser with URL
    Fill the login form         ${username}      ${password}
    Verify the error message is correct
    Close Browser Session

Open the Browser with URL
    Create Webdriver    ${browser_name}  executable_path=/Vibha_Personal/RobotFramework_Demo/drivers/${browser_name}
    Go To    https://opensource-demo.orangehrmlive.com/web/index.php/auth/login
    Maximize Browser Window
    Set Selenium Implicit Wait    2

Fill the login Form
    [arguments]         ${username}          ${password}
    Input Text          name:username        ${username}
    Input Password      name:password        ${password}
    Click Button        ${login_btn}


Verify the error message is correct
   ${result}=   Get Text    ${login_error_message}
   Should Be Equal As Strings     ${result}     Invalid credentials

Close Browser Session
    Close Browser

In the below image, it shows that there are 3 steps to creating a Data-Driven test.

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

. 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 the button identified by the locator. In this case, it is “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–error.

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

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.

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

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

 robot DataDrivenTesting_Demo.robot

The output of the above program is

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