Environment Setup

This tutorial is focused on those who want to learn the combination of Cucumber-Java. Hence we need to have following tools or software installed in your machine to complete the environment setup.

  • Java
  • Maven
  • Eclipse/IntelliJ IDEA
  • Cucumber

Step 1 : Installing and setting up Java environment

You can follow this blog link for installation and configuration of java.

Step 2 : Setting up Maven environment

To setup maven environment you can follow this blog link How to setup maven environment.

Step 3 : Setting up IDE

You can install either Eclipse or IntelliJ IDEA.

    Step 4: Setting up Cucumber

    Once the IDE setup is completed, we can proceed with the cucumber configuration.

    Cucumber environment setup consist of installing required plugins for IDE and adding required dependencies for the project.

    Note:

    Cucumber project creation will remain the same for all future chapter.

    For IntelliJ IDEA

    Let's first install required plugins.

    1. Click on File > Settings > Plugins
    2. First Search for following plugin Cucumber for Java and install
    3. Second Search for following plugin Gherkin and install

    Now let's create a new project and configure cucumber.

    1. Create new project
    2. Under Generators, select Maven Archeteype
    3. Enter name of project
    4. Select project location
    5. Select JDK : Leave as default
    6. Select Catalog : Leave as default
    7. Select Archetype: maven-archetype-quickstart
    8. Click on Create

    Once the project is created open the POM file add the dependency for Cucumber and JUnit.

    XML
    Copy
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>7.14.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.2</version>
      <scope>test</scope>
    </dependency>
    

    After making the above update on pom.xml reload the maven dependencies by pressing CTRL + SHIFT + A in windows or COMMAND + SHIFT + A on Mac.

    For Eclipse

    To setup Cucumber environment on Eclipse you can follow below steps:-

    1. Open eclipse
    2. Click on Help Menu > Eclipse Marketplace
    3. Type Cucumber in find textbox and click on Go
    4. You may see Cucumber Eclipse Plugin
    5. Click on Install
    6. It will ask for Confirm Selected Features
    7. Click on Confirm
    8. This will take bit time to install depending on your internet speed.

    Once the plugin is installed, create a new maven project. The steps to create the project is as follows:-

      Click on File menu > New > Others
    1. Select Maven Project from Wizard
    2. Click on Next
    3. Click on maven-archetype-quickstart and click on Next
    4. Enter the following for Archtype parameters
    5. groupId : com.example.simpletest
    6. artifactId : simpletest
    7. version : 1.0.0
    8. package : com.example.simpletest
    9. Click on Finish

    With the above steps you have successfully created the maven project. Now we need to add the POM dependencies. For that open pom.xml and add the following.

    Once the project is created open the POM file add the dependency for Cucumber and JUnit.

    XML
    Copy
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <version>7.14.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.2</version>
      <scope>test</scope>
    </dependency>