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).