Recognized by Clutch.co as a top-rated Mobile App Development Company.
folio3-mobile
US 408 365 4638
START YOUR PROJECT
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise
    • AR/VR
    • IoT
    • Wearables
    • Field Sales
    • On Demand Apps
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical & Life Sciences
    • Manufacturing
    • Automotive
    • Logistics
    • Education
  • Technologies
    • Native Mobile Apps
      • iOS
      • Android
    • Cross Platform Apps
      • React Native
      • Flutter
      • Ionic
      • Xamarin
      • NativeScript
      • Sencha
  • Portfolio
  • Blog
  • Contact Us
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise
    • AR/VR
    • IoT
    • Wearables
    • Field Sales
    • On Demand Apps
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical & Life Sciences
    • Manufacturing
    • Automotive
    • Logistics
    • Education
  • Technologies
    • Native Mobile Apps
      • iOS
      • Android
    • Cross Platform Apps
      • React Native
      • Flutter
      • Ionic
      • Xamarin
      • NativeScript
      • Sencha
  • Portfolio
  • Blog
  • Contact Us

Automation testing using Cucumber BDD with Selenium

Published by: Noc Folio3 | July 6, 2022 msaqlain
SCROLL AND BE AMAZED!
Home > App Testing • Blog > Automation testing using Cucumber BDD with Selenium

In this blog, I will describe how to integrate Cucumber BDD with Selenium step by step and also explain a simple Test Case to Login to the website. In this article, we will cover the basics of Automation testing using Cucumber BDD with Selenium.

What is Cucumber?

Cucumber is a tool that supports Behavior Driven Development (BDD). Using BDD we can define testing steps in a simple English language (Gherkin) which is easily understandable by any non-technical team member or business stakeholders. Cucumber supports different languages like Java, C#, ruby, python etc.

What is Selenium?

Selenium is an automation testing tool (open source) that can execute several functional test cases for web-based applications across multiple browsers. It supports multiple languages like Java, C#, ruby, python etc.

What is BDD?

Behavior Driven Development (BDD) is an approach to write test cases in a human understandable format with the help of Gherkin. BDD not only bridges the gap between analyst and developers but also between Manual QA and Automation Testers (who write BDD).

Example:

Let us understand with this simple example which we will add in the feature file.

Feature: Login feature.

Scenario: Verify user can log in with a valid username and password.

Given Navigate to the Login page

When User Login with valid user name and password.

Then User should be logged in successfully.

This is the practice where your test cases are written in plain English.

Now let’s understand the purpose of each keyword of Gherkin syntax

Ø  Feature: Feature keyword provides a high-level picture of what the software is supposed to do and each feature may have multiple scenarios.

Ø  Scenario: Scenario of that feature to test.

Ø  Given: Given is basically the initial context before execution or you can say prerequisite as well.

Ø  When: When declares an action performed by the system.

Ø  Then: Then a keyword is used to see the expected result or outcome.

Why use Cucumber with Selenium?

Ø  Cucumber makes it really easy to read and understand the flow of the application.

Ø  While Selenium allows you to run your functional test cases on web browsers.

Ø  With the combination of Cucumber and Selenium the gap between technical and non-technical team members is removed.

Ø  Makes it easier for clients to understand test cases.

Pre-Requisites for Cucumber:

Ø  Download and Install Java.

Ø  Download and Install Eclipse IDE.

Ø  Download Cucumber and Selenium JARs.

Link for downloading: https://www.automationtestinghub.com/download-cucumber-and-selenium-jars/

Ø  Add the Cucumber plugin from the marketplace.

Creation of Project using Cucumber with Selenium:

Scenario: Verify user can log in with a valid username and password.

Step1) Create Project in eclipse:

Create Java Project as shown in the screenshot.

Step2) Adding Jar files in the project:

Right-click on the Project > Properties > Go to Java Build Path. Add all the libraries downloaded earlier as mentioned in Pre-Req.

Step3) Creating Feature file:

Firstly we will create the Feature folder then we will add the feature file with the name Login.feature

Note: Cucumber Eclipse Plugin must be installed as mentioned in the Pre-Requisite for the feature file to work.

Step4) Add scenario in the Cucumber feature file:

Below mentioned lines are written using Gherkin language in the Login.feature file.

Step5) Create Cucumber Test Runner class:

With the help of the Cucumber Test Runner class, we can run the Cucumber feature file.

We created the “TestRunner” package and then added the “Runner.java” class file under it.

@RunWith annotation tells JUnit to run the class as mentioned with the name “Cucumber.class”. Cucumber is just a class that comes from this library “cucumber.api.junit.Cucumber”.

@CucumberOptions annotation provides the path for our cucumber test like feature file and step definitions. Step Definition class is a java method that is associated with the feature file.
We can define other options as well like Tag, Hooks, DryRun and etc etc. 

Step6) Create Step Definition class:

Step Definition is a Java class which is mapped with the feature files (Gherkin language). Step Definition is nothing but the steps you performed under the methods. Against each step of the feature file, you should add a step definition method. That’s how all your feature file steps (Given/When/Then) will have a method linked with it.

Now, when you run the feature file Cucumber would execute the step definition methods associated with the feature file.

We created the StepDefinition package and then added Steps.java class under it.

Step7) Executing the Script:

We can execute the script by right-clicking on TestRunner > Runner.java class and then select Run As > JUnit Test.

Step8) Output of the script.

On successful execution, this is how the output is shown with each step mentioned.

I hope after reading this blog, you will be able to Kick start Selenium with Cucumber BDD. 

Thank you.


About Noc Folio3

Newsletter

Search

Archives

  • December 2023
  • April 2023
  • March 2023
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • October 2021
  • September 2021
  • May 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • May 2019

Recent Posts

  • Exploring Flutter Navigation: From Basics to Advanced Routes
  • Web UI Test Automation with Pytest-BDD
  • How to fix IOS compass calibration issues
  • Testing Android Applications With Perfect Coverage
  • How to use useRef hook efficiently? – React

Tags

  • android
  • angular-state-management
  • Automation
  • Compass
  • cross-platform
  • css
  • development
  • firebase
  • hooks
  • ios
  • learn-ngrx
  • ngrx-beginner
  • ngrx/store
  • QA
  • react-native
  • reactjs
  • scss
  • stylesheet
  • styling
  • Testing
  • Test Script
  • UI-UX

Newsletter

Newsletter

Post navigation

Previous Getting started with NgRx
Next Parental Control – ScreenTime API iOS
Schedule an Appointment with our Mobile App Development Expert
Footer Menu
  • Company
    • About Us
    • Portfolio
    • Blog
    • Careers
    • Contact Us
  • Solutions
    • Apps Discovery Services
    • Team Augmentation
    • Enterprise App Development
    • AR/VR Application Development
    • IoT Application Development
    • Wearables Apps Development
    • Field Sales
    • On-Demand Apps Development
  • Technologies
    • iOS
    • Android
    • React Native
    • Flutter
    • Ionic
    • Xamarin
    • NativeScript
    • HTML5
    • Sencha
  • Industries
    • Retail
    • Agriculture
    • Healthcare
    • Pharmaceutical
    • Manufacturing
    • Automotive
    • Logistics
    • Education

US Office

Belmont, California – 1301 Shoreway Road, Suite 160, Belmont, CA 94002

Pleasanton, California – 6701 Koll Center Parkway, #250 Pleasanton, CA 94566

Tel: +1 408 365 4638
Support: +1 (408) 512 1812

Mexico Office

Amado Nervo #2200, Edificio Esfera 1 piso 4, Col. Jardines del Sol, CP. 45050, Zapopan, Jalisco, Mexico

Bulgaria Office

49 Bacho Kiro Street, Sofia, 1000, Bulgaria

Canada Office​

895 Don Mills Road, Two Morneau Shepell Centre, Suite 900, Toronto, Ontario, M3C 1W3, Canada

UK Office

Export House, Cawsey Way, Woking Surrey, GU21 6QX

Tel: +44 (0) 14 8361 6611

UAE Office

Dubai, UAE – Dubai Internet City, 1st Floor, Building Number 12, Premises ED 29, Dubai, UAE

Tel: +971-55-6540154
Tel: +971-04-2505173

Pakistan Office

Folio3 Tower, Plot 26, Block B, SMCH Society, Main Shahrah-e-Faisal, Karachi.

First Floor, Blue Mall 8-R, MM Alam Road Gulberg III, Lahore.

Tel: +92-21-3432 3721-4 

© 2025, Folio3 Software Inc., All rights reserved.

  • Privacy policy and terms of use
  • Cookie Policy
Follow us on
Facebook-f Linkedin-in Instagram

Get a free app audit

[contact-form-7 id="3548" title="Float Banner Form"]