Cucumber terminologies and how to do the setup.

Objectives:

Shubham Pandey
Version 1
3 min readSep 29, 2023

--

This article explains the terminologies people use while working on cucumber. It explains what Cucumber is and how to use it.

cucumber.png

What is Behavior-driven development (BDD)?

BDD is an approach in which an application is developed by explaining how it behaves. BDD offers an understanding of the functionality of applications to stakeholders and end users like Scrum Master, Product Owners, Business Analysts etc., who may not even have software development knowledge.

Cucumber:

Cucumber is a tool based on the Behavior Driven Development (BDD) framework which is used to develop tests to test a web application. The test written in Cucumber is readable and easy to understand even if the person is from a technical or non-technical background.

Cucumber uses Gherkin language.

We use multiple keywords while using Cucumber:

  1. Scenario
  2. Feature
  3. Feature File
  4. Scenario Outline
  5. Step Definition

Scenarios:

In Cucumber all the test cases are represented as scenarios. In this scenario, we have all the steps that need to be followed to test the feature. Gherkin language is being used to write the scenario which contains:

  • GIVEN: Preconditions will be available in GIVEN
  • WHEN: It defines the user actions.
  • THEN: This step observes the expected output.
  • AND: This step is an addition to the previous steps.

Feature:

It is a keyword in Cucumber which describes the high-level information of the software feature.

Background:

It describes any common feature that need to be implemented in all the tests.

Step Definition file:

The steps definition file stores the mapping between each step of the scenario defined in the feature file with a code of the function to be executed.
So, now when Cucumber executes a step of the scenario mentioned in the feature file, it scans the step definition file and figures out which function is to be called.

Test Runner file:

It establishes the connection between the feature and the Step definition file. Using the test runner file user can run multiple feature files simultaneously. It contains the path of the feature and the Step definition file.

How to use Cucumber:

Prerequisites:

1. Any IDE (Eclipse, IntelliJ) installed in the local system.

2. Java

Steps to use Cucumber:

Step 1: Open Eclipse in your local system

Step 2: Download the Cucumber eclipse plugin (Go to the help section -> Eclipse Marketplace -> Search “Cucumber eclipse” -> Enter -> Click on Install Button)

eclipse.png

Step 3: Restart the Eclipse.

Sample Feature File:

Feature: Search Facebook on Google Home Page

Scenario: Search Facebook

Given I navigated to Google URL
When I Search Facebook in the Google search text box
And I Hit Enter Button
Then Link to login Facebook should be displayed

Step Definition class:

public class SearchFacebookInGoogle {
@Given("I navigated to Google URL ")
public void i_navigated_to_google_url () {
}
@When("User Search Facebook in the google search text box")
public void user_search_facebook_in_the_google_search_text_box() {
}
@And("I Hit Enter Button")
public void i_hit_enter_button() {
}
@Then("Link to login Facebook should be displayed")
public void link_to_login_facebook_should_be_displayed() {
}

Sample Runner File:

@CucumberOptions(features="<PATH TO FEATURES FILE FOLDER>",
glue="stepDefinitions",monochrome=true,tags="@SmokeTest or @RegressionTest",
plugin = {"pretty", "html:target/cucumber.html","json:target/cucumber.json"} )
public class TestNGRunner extends AbstractTestNGCucumberTests {
}

Conclusion:

Cucumber plays a crucial role in software testing by which a tester can write scripts in easy and understandable ways which helps to involve non-technical person for feedback and their views.

About the author

Shubham Pandey is a Test Engineer here at Version 1.

--

--