Cucumber Tutorial for Beginners:Part 1

Cucumber Tutorial for Beginners:Part 1

2019 / 9 / 6

Cucumber, Selenium, Data Driven Testing, Eclipse

Cucumber is a buzz these days. So, let's discuss what cucumber is and what software model it uses.

Cucumber is a testing framework which supports BDD (Behavior Driven Development). It helps us to define the application behavior in a simple plain english using a simple grammar defined language Gherkin. Cucumber is written in Ruby, but it can be used to test code written in Ruby, Java, C#, Python and many more.

In this series of articles we will be discussing

  1. Setup Cucumber with Selenium in Eclipse
  2. Cucumber Basics
  3. Data driven Testing

Let's start with Part 1 i.e. Setup Cucumber with Selenium in Eclipse

Setting up Cucumber is not a simple tsk. It has some prerequisites softwares that need to setup correctly in order to use Cucumber. We will start discussing installation of each of the software in detail.

  1. Download and Install Java
  2. Download and Install Eclipse
  3. Install Cucumber Eclipse Plugin
  4. Download Cucumber for Eclipse
  5. Download Webdriver Java Client
  6. Configure Eclipse with Cucumber

Download and Install Java:

Since our tests will be written using Java language, so we will be requiring JDK- Java Development Kit.

  1. Go to the link https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and Download JDK.
  2. Double click the JDK and follow the installation steps.
  3. Next step is to setup the Path variable in System Variables.
  4. Set Path variable to the path of bin folder in jdk directory like “C:\Program Files\Java\jdk-12.0.2\bin”

NOTE: Replace this with path of bin folder in your jdk directory. This is for illustration purpose only.

  1. Open a command prompt and type java. If you can see some output, it means the path is set correctly and now jdk ready for use.

JAVA

Download and Install Eclipse:

Eclipse is an Integrated Development Environment (IDE). We are going to use eclipse to write, compile and run test scripts.

  1. Go to the link https://www.eclipse.org/downloads/packages/ and Download the Eclipse.
  2. Double click the downloaded file and follow the steps to install eclipse.

Install Cucumber Eclipse Plugin

Cucumber Eclipse Plugin is not the main cucumber eclipse plugin for running the test as BDD. When you write feature file for the cucumber test, the code for the feature file is not highlighted.

Cucumber Eclipse Plugin helps eclipse understand the basic Gherkin syntax and works like a syntax highlighter. Highlighting syntax makes it more readable and clear. It also helps to run feature file without the help of JUnit.

  1. Launch Eclipse IDE and from the Help Menu, Click "Install New Software"
  2. You will see a dialog box, Click "Add" button in front of "Work With" field.
  3. Enter "Name- Cucumber" and "Location- http://cucumber.github.com/cucumber-eclipse/update-site" and Click on "OK" button.

Eclipse IDE

  1. You will return to the previous window, but you will be able to see "Cucumber Eclipse Plugin" option in the available software list.

Cucumber Eclipse

  1. Just select the check box and press the "Next" button.
  2. Click on Next and then again Next and in the final window accept the license agreement and Click on the Finish button.
  3. This will install the plugin, it will take a few seconds to complete.

Download Cucumber for Eclipse:

In this step we will download the cucumber jar files for Eclipse. Cucumbers functionality is abstracted in jars. We will be using Online Maven Repository to download the jar files.

  1. Cucumber-core
  2. Cucumber-java
  3. Cucumber-junit
  4. Cucumber-jvm-deps
  5. Cucumber-reporting
  6. Gherkin
  7. Junit
  8. Mockito-all
  9. cobertura

Steps to download all the above mentioned jar files:

  1. Go to https://search.maven.org
  2. Search for cucumber-core in the Central Maven Repository. It will return the list of cucumber core jars. Click on the download button. I have downloaded jar file with Group Id-

Maven

  1. It will display a popup and ask to save the “cucumber core jar” file.

Cucumber

Cucumber

  1. Just like this, search for all the jar files mentioned in the list above and download one by one.
  2. Please Note the version of cucumber core, cucumber java, cucumber junit jar files should be the same.

I have downloaded following versions

Libraries GroupID Version
cucumber-core io.cucumber 4.7.2
cucumber-java io.cucumber 4.7.2
cucumber-junit io.cucumber 4.7.2
cucumber-jvm-deps io.cucumber 1.0.6
cucumber-reporting net.masterthought 4.9.0
gherkin info.cukes 2.12.2
junit junit 4.13-beta-3
mockito-all org.mockito 2.0.2-beta
cobertura net.sourceforge.cobertura 2.1.1

Download Webdriver Java Client:

Selenium supports many languages and each language has its own client driver. Here we are configuring Selenium 4 with java so we need "Webdriver Java Client Driver".

  1. Go to https://docs.seleniumhq.org/download/ Webdriver Java client download page for Webdriver download file. Click on the "Download" option in front of Java Client Driver.

Webdriver

  1. Save the .zip file to the disk.
  2. Extract the zip file
  3. Open the Selenium folder, you will find a libs folder, 2 jar files and a change log. We will be using these to configure Webdriver in Eclipse.

Selenium

Configure Eclipse with Cucumber

In order to configure Cucumber with Eclipse. We first need to launch the Eclipse, create a workspace, create a new Project and finally add External Libraries to the Project. Follow the steps below to correctly Configure Cucumber with Eclipse. If you listen to my advice, It is better to read one step and execute it at you end before going to the next step.

  1. Launch Eclipse. The first time you launch eclipse, you will be prompted for the path for the Workspace folder, where all projects will be saved. There is also an option to Switch the workspace, in case in future you want to switch the workspace.
  2. Create a new Java Project by clicking on File-> New->Java Project.

Eclipse Project

  1. Give your project a name” Online Shopping” .

Eclipse Project

  1. Add Selenium Jars: Right Click on project “Online Shopping”-> Select Properties->Java Build Path.

Selenium JAR

Selenium JAR

  1. Navigate to Libraries tab and click Add External JARs.

Selenium External JAR

  1. Add all the jar files from the Selenium folder and libs folder inside selenium folder.

JAR

JAR

  1. Click OK Button
  2. Add Cucumber JARs: Right Click on project “Online Shopping”-> Select Properties->Java Build Path.
  3. Add all Cucumber Jar Files and Click the Open button.

Cucumber JAR

  1. Click the Apply button.

Cucumber JAR

  1. Click the Apply and Close button.
  2. This is how the project looks like in Eclipse.

Eclipse Project

With this we are done with all the configuration part in Eclipse. Now we will discuss how to write basic cucumber script in the next blog post. Till then, get your setup ready and stay tuned.

You might also like