top of page

Easy-to-Follow Guide to Integrate Cucumber with Selenium in Eclipse

In our previous article, we talked about how to use Cucumber and Selenium to do web application testing in a behavior-driven way. Now, we'll dig deeper into integrating Cucumber with Selenium and the necessary system requirements for setting up a Selenium Maven testing project in Eclipse.



It's important to follow the key steps for configuring the project and running it efficiently to ensure seamless automation testing.


Integrate Cucumber with Selenium

System requirements

Before creating the Selenium Maven testing Project for cucumber testing in Eclipse, we must have the following dependencies in our computer system:

  1. Set up JDK on your system (JDK 1.8 or the latest version)

  2. Download Apache maven in windows

  3. Install the cucumber plugin - from Eclipse marketplace. – Go to Eclipse -> Help -> Install new software and search for Cucumber Eclipse plugin

Figure 3. Cucumber Eclipse plugin
Cucumber Eclipse plugin

Steps to set up cucumber – Selenium project.

Step 1: To create a Maven Project in Eclipse, click on New → Project → In the wizard, select Maven Project.

Create a Maven Project in Eclipse
Create a Maven Project in Eclipse

Step 2: On the new Maven Project pop-up, select the checkbox to create your project at the default location OR you can also browse and set a new location of your choice. Click on Next to proceed.

Create your project
Create your project

Step 3: On the next screen it will retrieve all the archetypes, please search for maven-archetype-quickstart. It will generate the maven sample project with proper structure.


Generate the maven sample project
Generate the maven sample project

Step 4: In the next screen, you will have to mention a Group ID and Artifact ID of your own choice; this is the name of your Maven project. Once you click the Finish button, a Maven project will be created in Eclipse with the structure highlighted in the image.

Figure 4. Project structure
Project structure

We have apom.xml file created in your Maven project. This file consists of the Group ID and Artifact ID which we have added while creating the project. By default, it consists of dependency for JUnit.

pom.xml of a Maven project
pom.xml of a Maven project

Now, to build a Selenium-Cucumber framework for us to work with, we need to add a dependency for Selenium and Cucumber in pom.xml, which is somewhat similar to adding JAR files. We will be needing dependencies of the following:

  1. Selenium Java - https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java.

  2. Cucumber-core

  3. Cucumber-java

  4. Cucumber-junit

  5. Cucumber-JVM-deps

  6. Cucumber-reporting

We can download all the dependencies from https://mvnrepository.com/search?q=Cucumber and add the required dependency in pom. XML file let's take a simple example of selenium java. Copy the highlighted portion and paste it into the pom.xml file.

Selenium jar maven dependency
Selenium jar maven dependency

Add selenium jar maven dependency to pom.xml file
Add selenium jar maven dependency to pom.xml file

Now update the project:

Right-click on Project name - > Maven - > Update project all the dependencies will be added to the project level. Verify the added jar in the Maven dependency section.


Verify the added jar in Maven dependency section
Verify the added jar in Maven dependency section

Similarly, we can add all the jars in the pom.xml file. After adding the relevant jars, we can create a sample feature file and step definition to run the cucumber project. The sample feature file is depicted in the Figure, we can add a sample step definition file mapped to the feature file.

Step definition file mapped to the feature file
Step definition file mapped to the feature file


Execution

We can execute the code as a maven build.

Steps: Right-click on Project -> Run as -> Select option as maven build.

Then in the dialog box select run configurations as depicted in the image.

Run configuration for the maven project
Run configuration for the maven project

Takeaway

This article provides a comprehensive guide on how to integrate Cucumber with Selenium and set up a Selenium Maven testing project in Eclipse. It includes the necessary system requirements, steps to create a Maven project, and how to add dependencies for Selenium and Cucumber. Additionally, it provides an example of a feature file and step definition file and explains how to execute the code as a Maven build. If you liked this series, do let me know in the comments and follow us on LinkedIn for more insights on Automation Testing.

bottom of page