Cucumber – Environment

we will see the environment setup for Cucumber with Selenium WebDriver and Java, on Windows Machine.

Prerequisites for Environment Setup

Following are the prerequisites required to set up with βˆ’

Java

Why we need βˆ’ Java is a robust programming language. Cucumber supports Java platform for the execution.

How to install βˆ’

Step1 βˆ’ Download jdk and jre from the following link http://www.oracle.com/technetwork/java/javase/downloads/index.html

Step2 βˆ’ Accept license agreement.

Step3 βˆ’ Install JDK and JRE.

Step4 βˆ’ Set the environment variable as shown in the following screenshots.

Eclipse

Why we need βˆ’ Eclipse is an Integrated Development Environment (IDE). It contains a base workspace and an extensible plug-in system for customizing the environment.

How to install βˆ’

Step1 βˆ’ Make sure JAVA is installed on your machine.

Step2 βˆ’ Download Eclipse from https://eclipse.org/downloads/

Step3 βˆ’ Unzip and Eclipse is installed.

Maven

Why we need βˆ’ Maven is a build automation tool used primarily for Java projects. It provides a common platform to perform activities like generating source code, compiling code, packaging code to a jar, etc. Later if any of the software versions gets changed, Maven provides an easy way to modify the test project accordingly.

How to install βˆ’

Step1 βˆ’ Download Maven from the following link βˆ’ https://maven.apache.org/download.cgi

Step2 βˆ’ Unzip the file and remember the location.

Step3 βˆ’ Create environment variable MAVEN_HOME as shown in the following screenshot.

Step 4 βˆ’ Edit Path variable and include Maven as shown in the following screenshot.

Step5 βˆ’ Download MAVEN plugin from Eclipse.

Step6 βˆ’ Open Eclipse.

Step7 βˆ’ Go to Help β†’ Eclipse Marketplace β†’ Search Maven β†’ Maven Integration for Eclipse β†’ INSTALL.

Configure Cucumber with Maven

Step 1 βˆ’ Create a Maven project.

  • Go to File β†’ New β†’ Others β†’ Maven β†’ Maven Project β†’ Next.
  • Provide group Id (group Id will identify your project uniquely across all projects).
  • Provide artifact Id (artifact Id is the name of the jar without version. You can choose any name, which is in lowercase). Click on Finish.

Step 2 βˆ’ Open pom.xml.

  • Go to package explorer on the left hand side of Eclipse.
  • Expand the project CucumberTest.
  • Locate pom.xml file.
  • Right-click and select the option, open with β€œText Editor”.

Step 3 βˆ’ Add dependency for selenium: This will indicate Maven which Selenium jar files are to be downloaded from the central repository to the local repository.

  • Open pom.xml is in the edit mode, create dependencies tag (<dependencies></dependencies>), inside the project tag.
  • Inside the dependencies tag, create dependency tag (<dependency></dependency>).
  • Provide the following information within the dependency tag.
<dependency> 
   <groupId>org.seleniumhq.selenium</groupId> 
   <artifactId>selenium-java</artifactId> 
   <version>2.47.1</version> 
</dependency>

Step 4 βˆ’ Add dependency for Cucumber-Java: This will indicate Maven, which Cucumber files are to be downloaded from the central repository to the local repository.

  • Create one more dependency tag.
  • Provide the following information within the dependency tag
<dependency> 
   <groupId>info.cukes</groupId> 
   <artifactId>cucumber-java</artifactId> 
   <version>1.0.2</version> 
   <scope>test</scope> 
</dependency>

Step 5 βˆ’ Add dependency for Cucumber-JUnit: This will indicate Maven, which Cucumber JUnit files are to be downloaded from the central repository to the local repository.

  • Create one more dependency tag.
  • Provide the following information within the dependency tag
<dependency> 
   <groupId>info.cukes</groupId> 
   <artifactId>cucumber-junit</artifactId> 
   <version>1.0.2</version> 
   <scope>test</scope> 
</dependency>

Step 6 βˆ’ Add dependency for JUnit: This will indicate Maven, which JUnit files are to be downloaded from the central repository to the local repository.

  • Create one more dependency tag.
  • Provide the following information within the dependency tag.
<dependency> 
   <groupId>junit</groupId> 
   <artifactId>junit</artifactId> 
   <version>4.10</version> 
   <scope>test</scope> 
</dependency>

Step 7 βˆ’ Verify binaries.

  • Once pom.xml is edited successfully, save it.
  • Go to Project β†’ Clean βˆ’ It will take a few minutes.

You will be able to see a Maven repository like shown in the following screenshot.

  • Create a feature file (to be covered later).
  • It a step definition file (to be covered later).
  • Create a JUnit runner to run the test (to be covered later).

Leave a Reply