DevLabs Alliance - WhatsApp
DevLabs Alliance Logo

Home / Tutorial /Installing Cucumber...

Installing Cucumber - Tutorial - Setup Guide

Srinivasan G

2024-01-04

DevLabs Alliance Tutorial Page

0 mins read

installing-cucumber-write-and-execute-first-cucumber-test-1

Download Cucumber JVM for Eclipse

The functionality of the cucumber is abstracted out in jars and to execute a Cucumber test

using Java in Eclipse, you need various Cucumber jars or modules.


There are various ways to download Cucumber jars for Eclipse; choose one from the alternatives

listed below:


  • Download Cucumber Jars from Online Maven Repository
  • Download Cucumber Jars from oss.sonatype.org
  • Download Cucumber Jars from Maven dependencies (Easiest)


We will talk about Downloading Cucumber Jars from Maven dependencies

Download Cucumber Jars from Maven dependencies

Download Cucumber Jars from Maven dependencies


The most popular and efficient method of configuring cucumber with eclipse is downloading Cucumber Jars from Maven dependencies. But those who are unfamiliar with Maven may find this to be somewhat challenging and end up losing a lot of time. Few conditions must be met in order to configure cucumber in eclipse.


  1. Install Maven in Eclipse IDE
  2. Create a New maven Project in Eclipse


Navigation flow: File->New->Others->Maven project.


The user needs to type the name of the Project folder in a new window that appears. Below is a screenshot for the same.



Click on Maven Project > Next



Select the Checkbox to create a simple project > Next



User need to give Group id Name And  Artifact id Name > Finish



Observe the package Explorer > POM.xml



By default, pom.xml will be generated like this:


<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>DLA_CucumberJava</groupId>

       <artifactId>DLA_CucumberJava</artifactId>

       <version>0.0.1-SNAPSHOT</version>

</project>

Add Dependencies for Cucumber Java|Cucumber JUnit | JUn

The next step is to add cucumber dependencies to the project once Maven has been installed on Eclipse and a Maven project has been created.


Add the below dependency to pom.xml


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

    <dependency>

        <groupId>io.cucumber</groupId>

        <artifactId>cucumber-java</artifactId>

        <version>7.8.1</version>

    </dependency>

</dependencies>



Below dependencies will get added after successful build.



Create Folder Structure

Let's make a good folder structure for the project before moving on to write the first script.


Create a new Package by right-click on the src/test/resources folder and select New > Package.



A new pop-up window will open. Specify the name as DLA_Feature and click on Finish.



Now the folder structure will look like:



Create a new file under DLA_Feature folder:



A pop-up window will open.

Provide the file name as DLA_Login.feature and click on Finish.




Installing Cucumber Eclipse Plugin

1. Go to Help menu in Eclipse IDE and click on “Eclipse Market Place”.



2. Add the cucumber eclipse plugin.



After successful installation of Cucumber Eclipse plugin, feature file will look like this:



Adding steps in created feature file:



Right click on Feature file and run as Cucumber Feature:



It will give the below message in Console to write the missing steps:



Adding Step Definitions

Create new folder under src/test/java and name it as Step_Definitions.

Follow the below steps to create a new folder:


  • Right click on src/test/java -> New -> Other



  • New wizard will get opened, search for folder, select folder under General and click on Next.



  • Give the folder name as ‘Step_Definitions’ and click on Finish.



Create new class file under Step_Definitions folder and name it as DLALoginSteps and click on Finish.



Copy the missing steps from Console and paste it in DLALoginSteps file:



You can write your code in the Step Definition file for further implementation.




Adding JUnit dependencies on POM.xml file

Add the below dependency in pom.xml to run the tests as JUnit test.


<dependency>

    <groupId>junit</groupId>

    <artifactId>junit</artifactId>

    <version>4.13.2</version>

    <scope>test</scope>

</dependency>



Adding Cucumber JUnit Dependencies on POM.xml file.


<dependency>

        <groupId>io.cucumber</groupId>

        <artifactId>cucumber-junit</artifactId>

        <version>7.8.1</version>

        <scope>test</scope>

</dependency>




Junit Test Runner Class

By right-clicking the "src/test/java" package and choosing New > Class, create a new Class file with the name "Test Runner" in it. This class only requires annotations to make it clear that cucumber features will be processed through it, and you can specify which feature files to pick up in addition to the location of the steps package.



Add code in TestRunner class

Add the below lines of code in Test Runner class:


package Step_Definitions;

import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
		features = "src\\test\\resources\\DLA_Feature"
		,glue={"stepDefinition"}
		)

public class TestRunner {

}



Run As Junit testcase




Meet The Author

DevLabs Alliance Blogs Author

Srinivasan G


Author


DevLabs Alliance Blogs Twitter IdDevLabs Alliance Blogs linkdinDevLabs Alliance Blogs instagram

Author Bio

IT industry professional with over 9 years of experience. His expertise lies in architecting and implementing IoT solutions using various Azure services such as IoT Hub, Event Hub, IoT Edge, DPS, Stream Analytics, Storage accounts, Azure Databricks, and Cosmos DB.

INQUIRY

Want To Know More


Email is valid



Phone


By tapping continuing, you agree to our Privacy Policy and Terms & Conditions

“ The hands-on projects helped our team put theory into practice. Thanks to this training, we've achieved seamless collaboration, faster releases, and a more resilient infrastructure. ”
DevLabs Alliance Blogs Page Review
Vijay Saxena

SkillAhead Solutions

Lets get started today!

and get that DREAM JOB

DevLabs Alliance Footer section
DevLabs Alliance LinkedIn ProfileDevLabs Alliance Twitter ProfileDevLabs Alliance Facebook ProfileDevLabs Alliance Facebook Profile
DevLabs Alliance Logo

USA

1603, Capitol Avenue, Suite 413A, 2659, Cheyenne, WY 82001, USA

DevLabs Alliance ISO 9001

DevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer SectionDevLabs Alliance Footer Section

`Copyright © DevLabs Alliance. All rights Reserved`

|

Refund & Reschedule Policy

Privacy Policy

Terms of Use