My First Cucumber Test


Cucumber is a testing tool that supports Behavior Driven Development (BDD). The main advantage is, it is written in plain simple English which clients and business users with limited technical knowledge can easily understand.


Let us see, how to create a simple cucumber test in java where we check if google search is working as expected.


Before we begin, the following should be installed in your system.

  1. Java

  2. Eclipse IDE

  3. Maven

After installing, lets proceed with the following steps to create our first test.


  • In eclipse, navigate to Help --> Marketplace. In the search, type in "Cucumber" and hit "Go"

  • Choose the Cucumber Eclipse Plugin 1.0.0.202106240526 and click "Install". Agree to the terms and conditions.


  • You may get security warning. Click on "Install Anyway"


  • You will be prompted to restart eclipse after installation. Restart eclipse.

  • Now, goto "File" menu --> "New" --> "Other" --> "Maven Project"


  • In the POM.xml include the dependencies. At the time of writing, these are the versions of Dependencies added from https://mvnrepository.com

io.cucumber cucumber-java Version 6.10.4

junit junit Version 4.13.2

test io.cucumber cucumber-junit Version 6.10.4

test org.seleniumhq.selenium selenium-java Version3.141.59

Code to be included in POM.xml is as follows


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>CucumberDemo</groupId>

<artifactId>CucumberDemo</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>CucumberDemo</name>

<description>CucumberDemo</description>


<dependencies>


<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->

<dependency>

<groupId>io.cucumber</groupId>

<artifactId>cucumber-java</artifactId>

<version>6.10.4</version>

</dependency>


<!-- https://mvnrepository.com/artifact/junit/junit -->

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.13.2</version>

<scope>test</scope>

</dependency>


<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->

<dependency>

<groupId>io.cucumber</groupId>

<artifactId>cucumber-junit</artifactId>

<version>6.10.4</version>

<scope>test</scope>

</dependency>


<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>selenium-java</artifactId>

<version>3.141.59</version>

</dependency>


</dependencies>

</project>


  • Now Clean and Build the Project for the dependencies to be reflected in the project.

  • It's time to get more organized and create some folders and packages.

  • Under src/test/resources, Right click --> "New" --> "Folder" --> Give folder name as "Features"

  • Under the Features folder, Right click --> "New" --> "File" --> Give name as "GoogleHomeTest.feature". (Note: File extension should be .feature). A file with some auto-generated contents will be created. Clear all the auto-generated contents.