Cucumber (Gherkin)

Setting Up Cucumber in Your Project

Estimated reading: 3 minutes 254 views
cucumber-guides-featured-image

In this  guide, we’ll walk you through the essential steps to set up Cucumber in a Java project. Proper setup is crucial for ensuring a smooth workflow for your Behavior-Driven Development (BDD) testing. By following this guide, you’ll be well on your way!

Prerequisites

  • Java Development Kit (JDK) installed.
  • Integrated Development Environment (IDE) Eclipse.
  • Maven for dependency management.

Create a New Maven Project

To embark on your journey with a Cucumber Gherkin project, the first step is to create a new Maven project. If you’re unfamiliar with setting up a Maven project, don’t worry. Our guide here on How To Create A New Maven Project in Eclipse, will walk you through the process step by step.

Once your Maven project is successfully set up, the next crucial task is to add the core Maven dependencies required for your Cucumber Gherkin project. Head over to your pom.xml file and these between your dependencies tag.

adding-dependencies-to-pom-xml
Adding Dependencies To pom.xml
pom.xml
<!-- Selenium Java -->
<dependency>
	<groupId>org.seleniumhq.selenium</groupId>
	<artifactId>selenium-java</artifactId>
	<version>4.20.0</version>
</dependency>

<!-- Cucumber Java -->
<dependency>
	<groupId>io.cucumber</groupId>
	<artifactId>cucumber-java</artifactId>
	<version>7.11.0</version>
</dependency>

<!-- Cucumber JUnit -->
<dependency>
	<groupId>io.cucumber</groupId>
	<artifactId>cucumber-junit</artifactId>
	<version>7.11.0</version>
</dependency>

<!-- JUnit 4 -->
<dependency>
	<groupId>junit</groupId>
	<artifactId>junit</artifactId>
	<version>4.12</version>
	<scope>test</scope>
</dependency>

<!-- Extent Reports Cucumber Adapter -->
<dependency>
	<groupId>tech.grasshopper</groupId>
	<artifactId>extentreports-cucumber7-adapter</artifactId>
	<version>1.14.0</version>
</dependency>

<!-- Extent Reports -->
<dependency>
	<groupId>com.aventstack</groupId>
	<artifactId>extentreports</artifactId>
	<version>5.1.1</version>
</dependency>

<!-- Commons IO -->
<dependency>
	<groupId>commons-io</groupId>
	<artifactId>commons-io</artifactId>
	<version>2.11.0</version>
</dependency>

Organizing Your Project Structure

Now that we have our project created, let’s set up our base folders and directories. To get started, we’ll need to create a few specific folders. In this guide we’ll be incorporating the com.kicksapp package in our project to keep our files organize.
organizing-cucumber-project
Organizing Cucumber Project
  • com/kicksapp/runners - This folder is where our test runner files will be stored. These files are essential for executing our test suites.
  • com/kicksapp/stepdefs - Here, we'll keep our test step definitions. This organization helps in managing the steps involved in our tests, making them easy to locate and modify.
  • src/test/resources/driver - This is the designated folder for our driver files. For this project, we'll be using Chromedriver. Ensuring the driver is in the right place helps in seamless test execution.
  • src/test/resources/features - Most importantly, this folder will store our feature files. Feature files are the cornerstone of our behavior-driven development (BDD) approach, outlining the scenarios and behaviors our application should exhibit.
Tip: Naming Your Package Directory

You can choose to keep you package as simple as src/test/java/runners or src/test/java/stepdefs. However in this guide We’ll be using the com/kicksapp/… package.

Downloading the Cucumber Plugin for Eclipse

Once we have these packages and folders set up, the next step is to download the Cucumber plugin for Eclipse. This plugin is essential for integrating Cucumber with Eclipse, providing a robust environment for running and managing our BDD tests.

Navigate to the top menu and click on Help . From the dropdown menu, select Eclipse Marketplace…

installing-cucumber-plugin-eclipse-marketplace
Installing Cucumber Plugin From The Eclipse Marketplace
  1. Search for Cucumber: In the Eclipse Marketplace window, use the search bar to type in "Cucumber" . Press Enter to view the search results.
  2. Install the Cucumber Plugin: Locate the Cucumber plugin from the list of results. Click the Install button next to the Cucumber plugin entry. Follow the prompts to complete the installation process.
  3. Restart Eclipse: Once the installation is finished, you will be prompted to restart Eclipse. Click Restart Now to apply the changes.

Conclusion

Organizing your project with these folders ensures a streamlined process where each component of your testing framework is easily accessible. This setup not only enhances productivity but also aligns with best practices in test automation, making it easier to scale and maintain your tests.

Now you’re ready to Write Your First Gherkin Feature File. Continue to the next guide to dive into writing Gherkin scenarios.

 
 
 

Leave a Comment

Share this Doc

Setting Up Cucumber in Your Project

Or copy link

CONTENTS
Review Your Cart
0
Add Coupon Code
Subtotal
Total Installment Payments
Bundle Discount