RelationDigest

Monday, 19 June 2023

[New post] How to write tests in Robot Framework in BDD Format

Site logo image vibssingh posted: " 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 " QA Automation Expert

How to write tests in Robot Framework in BDD Format

vibssingh

Jun 19

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 −

  • Open browser − URL − https://opensource-demo.orangehrmlive.com/web/index.php/auth/login in Chrome mode
  • Enter username and password in the search textbox
  • Click Search Button
  • Verify the error message (Scenario 1)
  • Verify Dashboard page opens (Scenario 2)

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

Comment
Like
Tip icon image You can also reply to this email to leave a comment.

Unsubscribe to no longer receive posts from QA Automation Expert.
Change your email settings at manage subscriptions.

Trouble clicking? Copy and paste this URL into your browser:
http://qaautomation.expert/2023/06/19/how-to-write-tests-in-robot-framework-in-bdd-format/

WordPress.com and Jetpack Logos

Get the Jetpack app to use Reader anywhere, anytime

Follow your favorite sites, save posts to read later, and get real-time notifications for likes and comments.

Download Jetpack on Google Play Download Jetpack from the App Store
WordPress.com on Twitter WordPress.com on Facebook WordPress.com on Instagram WordPress.com on YouTube
WordPress.com Logo and Wordmark title=

Learn how to build your website with our video tutorials on YouTube.


Automattic, Inc. - 60 29th St. #343, San Francisco, CA 94110  

at June 19, 2023
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Francis Bacon - Father of Scientism (Featuring scientist, inventor, and author Hans G. Schantz)

This RTF lecture featured special guest Hans Schantz who tackled the topic of the intellectual cage of scientism established by occultist an...

  • Sunnycare Aged Care Week 10
    https://advanceinstitute.com.au/2024/04/24/sunnycare-aged-care-week-10/?page_id=...
  • [New post] weather
    barbaraturneywielandpoetess posted: " life on a rooftop can be short ; depends whether one looks down or up . ...
  • [New post] County-Military Installation Coexistence: Partnerships for Success
    Victo...

Search This Blog

  • Home

About Me

RelationDigest
View my complete profile

Report Abuse

Blog Archive

  • October 2025 (59)
  • September 2025 (53)
  • August 2025 (54)
  • July 2025 (59)
  • June 2025 (53)
  • May 2025 (47)
  • April 2025 (42)
  • March 2025 (30)
  • February 2025 (27)
  • January 2025 (30)
  • December 2024 (37)
  • November 2024 (31)
  • October 2024 (29)
  • September 2024 (28)
  • August 2024 (2729)
  • July 2024 (3249)
  • June 2024 (3152)
  • May 2024 (3259)
  • April 2024 (3151)
  • March 2024 (3258)
  • February 2024 (3046)
  • January 2024 (3258)
  • December 2023 (3270)
  • November 2023 (3183)
  • October 2023 (3243)
  • September 2023 (3151)
  • August 2023 (3241)
  • July 2023 (3237)
  • June 2023 (3135)
  • May 2023 (3212)
  • April 2023 (3093)
  • March 2023 (3187)
  • February 2023 (2865)
  • January 2023 (3209)
  • December 2022 (3229)
  • November 2022 (3079)
  • October 2022 (3086)
  • September 2022 (2791)
  • August 2022 (2964)
  • July 2022 (3157)
  • June 2022 (2925)
  • May 2022 (2893)
  • April 2022 (3049)
  • March 2022 (2919)
  • February 2022 (2104)
  • January 2022 (2284)
  • December 2021 (2481)
  • November 2021 (3146)
  • October 2021 (1048)
Powered by Blogger.