What are Features and Step Definitions in Cucumber?

Features: File with “.feature” extension are called features file. A Feature file will contain one feature with one or more Scenarios. A line started with Keyword “Feature” in Feature file is the test feature that cucumber going to execute. Each Scenario in Feature contains number of steps written using Gherkin language.
Step Definitions: Each step in a Scenario mapped to Step definition. When Cucumber executes a Step Scenario it looks for a matching Step Definition to execute. Each step definition is a piece of code defined for certain task. Each step definition is attached with a reference pattern, which is used for map between steps in scenario and step definitions.

Advertisements

Downloading Cucumber JVM and Selenium Jars

To write/run Cucumber Scenarios with Java in Eclipse the below Jar files are required. Please follow the steps and all download the all listed jar files.

  • junit
  • gherkin
  • Cucumber-core
  • Cucumber-java
  • Cucumber-junit
  • Cucumber-jvm-deps
  • Cucumber-reporting
  • mockito-all
  • cobertura

Step 1: Search all the above terms in the Maven Central Repository one by one and download latest Jar file. Click Here!! for Maven repository.

scrn11

Step 2: Now search for “junit”, you could see the list of Jars listed. Select the latest Jar and download it.

scrn12

Step 3: Repeat the same procedure for remaining Jars and Keep them in a folder as below.

scrn13

Step 4: Download the Selenium Standalone Server from Download Selenium Standalone Jar

Step 5: Add all the above Jars in the project build.

Installing Cucumber Eclipse Plugin

Why Cucumber Eclipse Plugin needed? This plugin highlights the Syntax’s or Keywords; basically it distinguishes syntax keywords from other sentences. That is fine if we do not install it but the entire scripts appears as plain text as in a notepad. So it is recommended to install Cucumber Eclipse Plugin.

Installation Steps:

Step 1: launch Eclipse IDE and Go to “Install New Software…” option.

scrn1

Step 2: In the new dialog window click on “Add” button.

scrn2

Step 3: Give the Name as “Cucumber” (you can give any name) and paste below URL in Location and click OK.

http://cucumber.github.com/cucumber-eclipse/update-site

scrn3

Step 4: You must see the Cucumber Eclipse Plugin in the software list. Select the Cucumber check-box and Click on Next.

scrn4

Step 5: Accept the Terms and Conditions and Click on Finish.

scrn6

Step 6: Installation will start and you may see “Security Warning” just click OK.

scrn7

scrn8

Step 7: After Installation completed it will ask Eclipse restart say yes.

scrn9

Step 8: Now go to Eclipse Help Installation Details. You must is Cucumber Eclipse Plugin in the Installed Software list.

scrn10

Why Selenium with Cucumber?

In the agile world, the Stake Holders or Business Analysts or Product Owners decides the behavior of systems first and writes System Requirements or System Scenarios in Customer’s point of view. These requirements are reviewed and singed off to Developers for development, this is BDD.

Now the above System Requirements can be easily converted to end user tests using BDD approach. The code can easily read/understandable to Product Owners or Business Analysts. So Selenium with Cucumber is good choice for executing the tests.

Cucumber Introduction

  • Cucumber is an open source software tool used to test the other software. It is a Behavior Driven Development tool.
  • Writing tests is easy and persons with no technical knowledge can understand the tests.
  • Though Cucumber is written in Ruby, supports other languages like Java, Scala, Groovy and etc. Cucumber supports web environment only.
  • Cucumber plugins works faster compared to UFT and Selenium. So the execution is quick in cucumber.