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
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.
Apu says
Hi Mukesh ,
Can you please send me the link for reading data from excel using cucumber with selenium.
Regards
Apu
Mukesh Otwani says
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://learn-automation.com/read-and-write-excel-files-in-selenium/
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.
Mukesh Otwani says
Hi Atul,
Please follow this video https://www.youtube.com/watch?v=WYdTkTzGFxE&index=3&list=PL6flErFppaj1Ogn82-OINRkPwoieZ2dEX&t=2s and use new version
Suba Kumaran says
Hi Mukesh,
Thank you very much.
Mukesh Otwani says
Welcome Suba. Keep learning.
akhil says
Is it possible to use TestnG and Cucumber together
Mukesh Otwani says
Nopes as of now only Junit is supportable.
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
Mukesh Otwani says
Hi Swathi,
Java and Python both are good. I would suggest continue with Java-Selenium-Cucumber.
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.
Mukesh Otwani says
Hey Puneeth,
This will help https://www.youtube.com/watch?v=WYdTkTzGFxE
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.
Mukesh Otwani says
Hey Ali,
You can download from outside network and try the same.
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
Mukesh Otwani says
Hey Pankaj,
Jenkins check local maven first to run maven project.
Richa Bansal says
Hi Mukesh!
Thank you very much..
I have extracted all the jars individually..
Mukesh Otwani says
Great Richa keep exploring
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.
Mukesh Otwani says
Thanks Vishal I will update the same.
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
Mukesh Otwani says
Hey Swati,
if you have batch file then in Jenkins you can run any batch file. Select execute window command and mention batch file.