Cucumber

Deepak Kashyap
4 min readJun 14, 2019

For Beginners

This article covers the important and key pointers to be considered when using Cucumber. First things first, Cucumber is not only for testers or a testing tool. It is more like a collaborative tool for developers,testers and business analysts to sit together brainstorm and come-up with the implementation of the software solution they are planning to develop.

Testing — Cucumber Way
@basics @introduction @start
Feature: Cucumber Basics
Read this article to know the basics of Cucumber

@start
Scenario: Beginner Start
Given I want to learn basics of Cucumber
And get idea about what is BDD all about
When I complete this article
And do some samples
Then I should be confident to work with Cucumber
And Explore more on the topic

Trivia — How did the name originate

Aslak Hellesøy creator of Cucumber was working on extensions/hack of BDD tools and had initially named the whole thing as “Stories”. Then one day on a 3-hour bus journey with his fiancee Patty, he did check with her for a catchy,non-geeky sounding name for the tool he was developing and Patty out of no where said “Cucumber” and the creator thought that looks cool and thought he can rename again if he finds something more interesting and rest is history.

Few key definitions and explanations

BDD : BDD is an acronym for Business Driven Development where main stakeholders of the software solution (Business/Developers/Testers) sit together to discuss and clarify any misunderstanding about the process and implementation before starting the development.

Cucumber: Cucumber is a tool which is used to support BDD (Business Driven Development). It can be basically considered as a JUnit Extension.

Gherkin: Gherkin is like coding/programming in English like language syntax using some keywords which Cucumber understands. As it is written in plain text it can be easily understandable even by non-technical team members.
Gherkin is line oriented language similar to YAML or Python.

Feature: Feature is logical group of similar scenarios from business perspective

Scenario: Small blocks/unit of functionality which belongs to a feature.

Scenario Outline: Similar to scenario but used for a data-set instead of single instance.

Background: Background acts as precondition for all the scenarios within a feature.If we need to provide different background for scenarios then it is better to create different features.

Given: Given is similar to background i.e acts as a precondition for the scope of Given is restricted to only one scenario.

When: When identifies the actual condition/action.

Then: Then captures the expected system/solution behavior of the application to be tested.

Sample Feature File

When we create a new feature in Eclipse along with the cucumber plugin it comes with comments and template which are more than enough to get started.

#Author: your.email@your.domain.com
#Keywords Summary :
#Feature: List of scenarios.
#Scenario: Business rule through list of steps with arguments.
#Given: Some precondition step
#When: Some key actions
#Then: To observe outcomes or validation
#And,But: To enumerate more Given,When,Then steps
#Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
#Examples: Container for s table
#Background: List of steps run before each of the scenarios
#””” (Doc Strings)
#| (Data Tables)
#@ (Tags/Labels):To group Scenarios
#<> (placeholder)
#””
## (Comments)
#Sample Feature Definition Template
@tag
Feature: Title of your feature
I want to use this template for my feature file
@tag1
Scenario: Title of your scenario
Given I want to write a step with precondition
And some other precondition
When I complete action
And some other action
And yet another action
Then I validate the outcomes
And check more outcomes
@tag2
Scenario Outline: Title of your scenario outline
Given I want to write a step with <name>
When I check for the <value> in step
Then I verify the <status> in step
Examples:
| name | value | status |
| name1 | 5 | success |
| name2 | 7 | Fail |

One of the best parts of Cucumber is its ease of use and it is very well documented for any beginner with zero knowledge to start with.This article is more like a teaser and I definitely recommend you all to follow the below link to learn more.

FAQs

  1. Is Continuous Build possible in Cucumber
    The cucumber executable will exit with an exit status different from 0 if one or more scenarios are failing which can be picked up by CI Server. So, yes Cucumber supports continuous build and primary build tools like Ant/Maven
  2. Invalid CEN Header (Bad Signature) Error
    Usually when we build the maven project we can notice the error “Invalid CEN Header (Bad Signature)” along with “No backends were found. Please make sure you have a backend module on your CLASSPATH”. To resolve this delete the cucumber-java dependency or the jar file from the maven repository and rebuild the project. If this solution doesn't work then try to a use a different version of jar in pom dependencies.
  3. What are the basic tools/software needed to start with Cucumber
    Java, Maven and an IDE (Eclipse + Cucumber Plugin)
  4. Which is easy way to create Cucumber Project
    By using maven-plugin ‘cucumber-archetype’.
    Other way is to start with a POM file with basic cucumber dependencies like cucumber-java,cucumber-junit,junit and creating new Maven project
  5. How are Tags conditions considered
    Tags basically follow logical Boolean conditions and can be clubbed together.
@basics @introduction @end
Feature: Cucumber Basics
Read this article to know the basics of Cucumber

@end
Scenario: Beginner End
Given I have completed the article
When I apply this learning
And do some samples
Then I will share my experience in comments

Please share your experiences,tips, FAQs about Cucumber from which we all can be mutually benefited.

--

--