Cucumber is available for most programming languages. The official implementations which are maintained are as follows:
Cucumber – JVM (For Java)
Cucumber.js (For Node.js and browsers)
Cucumber.rb (For Ruby and Ruby on Rails)
Cucumber.cpp (For C++)
Android (For Java)
Kotlin (Cucumber JVM with Kotlin)
Behave (For Python)


Here, we will be installing and using Cucumber-JVM, since we will be using Java.

Cucumber-JVM is published in the Central Maven Repository. You can start working on Cucumber-JVM by either adding the following Maven or Gradle dependencies to your project or by directly downloading the jar files and adding them in your project configuration path.

Maven Dependency
Add the following Maven dependencies in your pom.xml file.

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.7.1</version>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.7.1</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.5</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-html</artifactId>
    <version>0.2.7</version>
</dependency>
<dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>cucumber-reporting</artifactId>
    <version>4.8.0</version>
</dependency>

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-core</artifactId>
    <version>1.3</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>2.0.2-beta</version>
    <scope>test</scope>
</dependency>

Gradle Dependency
Add the following Gradle dependencies in your build.gradle file.

dependencies {
    testCompile 'io.cucumber:cucumber-java:4.7.1'
    testCompile 'io.cucumber:cucumber-junit:4.7.1'
    providedCompile group: 'info.cukes', name: 'cucumber-jvm-deps', version: '1.0.5'
    compile group: 'io.cucumber', name: 'cucumber-html', version: '0.2.7'
    compile group: 'net.masterthought', name: 'cucumber-reporting', version: '4.8.0'
    testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
    testCompile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta'
}

repositories {
    mavenCentral()
}

Download as JARs
If you want to use the JAR files, download the following JARs from the Maven Repository and add them directly to your project configuration path:

  • cucumber-core-4.2.6.jar
  • cucumber-java-4.2.6.jar
  • cucumber-junit-4.2.6.jar
    (Remember, the above three jars should have the same version)
  • cucumber-jvm-deps-1.0.5.jar
  • cucumber-html-0.2.7.jar
  • cucumber-reporting-4.7.0.jar
  • gherkin-5.1.0.jar
  • hamcrest-core-1.3.jar
  • mockito-all-2.0.2-beta

Cucumber is a JUnit extension. It is launched by running JUnit from your build tool (e.g. Maven, Gradle) or from your IDE (e.g. Eclipse, Netbeans, IntelliJ etc.)

If you are using Eclipse, you would also like to install the Cucumber-Eclipse-Plugin. To install it, follow the below steps:

Open Eclipse IDE
Go to Help -> Eclipse Marketplace
Enter Cucumber in the Find search box and click on Search
Click on “Install” button for Cucumber Eclipse Plugin

Follow the steps and Cucumber-Eclipse-Plugin will get installed in your Eclipse. Restart Eclipse to view the changes.

Cucumber Installation from Command Line (for Maven Project)

Create a new Maven project by opening the command prompt and going to the directory where you want to create the project. Then run the following command:

mvn archetype:generate                      
   "-DarchetypeGroupId=io.cucumber"           
   "-DarchetypeArtifactId=cucumber-archetype" 
   "-DarchetypeVersion=4.2.6.1"               
   "-DgroupId=HelloCucumber"                  
   "-DartifactId=HelloCucumber"               
   "-Dpackage=helloCucumber"                  
   "-Dversion=1.0.0-SNAPSHOT"                 
   "-DinteractiveMode=false"

Your Maven project will get created. Then open Eclipse and import this Maven project (File -> Import -> Maven -> Existing Maven Projects -> Next -> Browse to the project path -> Finish)
A file RunCucumberTest.java will automatically get created inside the path “/HelloCucumber/src/test/java/helloCucumber/”. Add the below code in the file:

package helloCucumber;

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

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "pretty", features = "src/test/resources/hellocucumber")
public class RunCucumberTest {
}

To verify that the Cucumber installation is successful for the Maven project, run the below command from the command prompt (you should be inside the directory of the project “HelloCucumber”)

mvn test

You should be able to see “BUILD SUCCESS”. This means that Cucumber is successfully installed and you are ready to run your first scenario using Cucumber.

Credits:
https://cucumber.io/docs/cucumber/