Cucumber Tutorials

How to integrate Cucumber with Selenium webdriver

Selenium Cucumber Tutorials

Welcome to all of you for another series “Cucumber tutorials”. In this post, we will discuss how to integrate cucumber with selenium webdriver.

What is BDD-  BDD stands for Behavior driven development– This mainly deals with the behavior of the application.

In BDD we only focus on application behavior, all requirements will be in the plain text file and in pure English language. It helps client, developer and tester to understand the requirement easily.

 

What is Cucumber– It is BDD tool which will allow you to perform the test in an easy way.

It is purely written in Ruby and we can implement cucumber in multiple languages. Here we will mainly focus on Java part so complete series will be cucumber with selenium webdriver using Java.

 

Cucumber with Selenium webdriver

Once you are done with this tutorial you will get a clear picture of Cucumber with Selenium webdriver and advantage of using the same.

We will also use Gherkins keywords in our feature files which make our task easy to write user stories in a more efficient way.

 

Below is the example of some Gherkins keyword

  • Feature
  • Scenario
  • Given, When, Then, And, But (Steps)
  • Background
  • Scenario Outline
  • Examples

 

Check example of feature file

Feature: Test Facebook smoke scenario

Scenario: Test login with valid credentials
Given Open firefox and start application
When I enter valid username and valid password
Then user should be able to login successfully

 

Steps for configuring Cucumber with Selenium webdriver

Precondition- Selenium basic is required if you have not gone through Basic tutorials then below link will help you.

Basic Selenium webdriver tutorials

Step 1- Create Java project

Step 2- Add Selenium jars and add Cucumber jars

Step 3- Create feature file and write scenarios.

Step 4- Write TestRunner and execute the same.

Step 5- Once TestRunner execution complete, you will get all methods with default implementation (Copy all of them).

Step 6- Create Java program and paste the code which we have copied in Step 5

Step 7- Write the code for methods which has no body

Step 8- Execute the Test Runner and check the result.

 

Complete project structure will be like

Cucumber with Selenium webdriver

I have also uploaded the complete video on Cucumber with Selenium webdriver

 

 

In next post,we will see the writing of  TestRunner and  stepDefination and feature file.

 

author-avatar

About Mukesh Otwani

I am Mukesh Otwani working professional in a beautiful city Bangalore India. I completed by BE from RGPV university Bhopal. I have passion towards automation testing since couple of years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli, Selenium Builder etc.

22 thoughts on “How to integrate Cucumber with Selenium webdriver

  1. Apu says:

    Hi Mukesh ,

    Can you please send me the link for reading data from excel using cucumber with selenium.

    Regards
    Apu

    1. Hi Apu,

      As such I don’t have such post where reading excel during BDD execution. But reading excel is nowhere related to BDD or any other framework. You need to implement your own custom method to read data according to your need. You can check this link which mentions how to read excel file using Apache POI https://vistasadprojects.com/mukeshotwani-blogs-v2/read-and-write-excel-files-in-selenium/

  2. Atul Vani says:

    Hi Mukesh, I’m using cucumber 1.1.2 jars as you mentioned in your first video tutorial, but by using this jar file at “@Cucumber.Options ” I am unable to pass plugin parameter for generate HTML report. you also mentioned in your “Maven setup video tutorial” that for “@CucumberOptions” we need to configure latest jars. which jar file versions supported for “@CucumberOptions”, please guide me for this problem.

  3. Suba Kumaran says:

    Hi Mukesh,
    Thank you very much.

    1. Welcome Suba. Keep learning.

  4. akhil says:

    Is it possible to use TestnG and Cucumber together

    1. Nopes as of now only Junit is supportable.

  5. swathi says:

    hey mukesh, i need a suggestion!

    I started my carrer in testing with selenium webdriver with java , i dont know the logic coding in java and worried about java so i think to change into selenium webdriver with python ? is there future for python ? selenium webdriver in cucumber with java or python is preffered ???

    Please describe with your valuable suggestions for my future

    Thanks in advance

    1. Hi Swathi,

      Java and Python both are good. I would suggest continue with Java-Selenium-Cucumber.

  6. puneeth says:

    Hi Mukesh, i am facing an issue with the TestRunner.java class when i am using the plugin option.
    It says “The attribute plugin is undefined for the annotation type CucumberOptions”.

    It plugin option is not given in the suggestion by eclipse. Please suggest.

  7. Ali says:

    Hi Mukesh,

    I am learning automation from past 4 months i got a good rasp over selenium.Now, i want to use cucumber (BDD Framework)with selenium,please share videos on “selenium with Cucumber” on my mail account as youtube.com is not permitted in my office.

    1. Hey Ali,

      You can download from outside network and try the same.

  8. pankaj says:

    Hi mukesh
    i am trying to integerate cucumber maven with jenkins but it ask for maven path but i am not downloading the maven i just add the dependencies in pom.xml file .then what i need to do to execute my cucumber pom.xml with jenkins

    1. Hey Pankaj,

      Jenkins check local maven first to run maven project.

  9. Richa Bansal says:

    Hi Mukesh!

    Thank you very much..
    I have extracted all the jars individually..

    1. Great Richa keep exploring

  10. Vishal Kopkar says:

    Hi Mukesh,
    Thanks a lot for this useful information. for an update @Cucumber.Options annotation is deprecated and you need to use @CucumberOptions instead.

    1. Thanks Vishal I will update the same.

  11. swati says:

    Hi Mukesh,

    I’m using a selenium hybrid framework where we are using batch excel to execute the testmethods. I want to integrate this with Jenkins. Is it possible to integrate with any framework type or do I specifically need TestNG framework?

    I have come across only TestNG integration examples. Can you please suggest on this?

    Thanks,
    Swati

    1. Hey Swati,

      if you have batch file then in Jenkins you can run any batch file. Select execute window command and mention batch file.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.