How Cucumber Works

Profile picture for user devraj

You can understand How Cucumber works by looking at its Testing Stack.

Cucumber Testing Stack allows for visualization of the hierarchy of your project, starting from features down to automation libraries and systems. This diagram of the Cucumber Stack gives you a much clearer view of the structure of the Cucumber tests

Cucumber Testing Stack

This Testing Stack can be divided into two major categories:

  1. Business Facing: The Features, Scenarios, and Steps make up the Business Facing components of the Cucumber stack. The feature is the Front-End File that Business Analysts, Developers, QA Analysts use to define testing requirements.
  2. Technology Facing: For the Business Components to work, there needs to be some underlying technology that runs the tests on a desktop, mobile device, emulator, simulator, etc. These components bring us to the Technology Facing components of the Cucumber Test Stack.

How Cucumber Works - Step By Step 

  1. Find the Feature File: Cucumber first looks for your features files with tagged scenarios written in Gherkin language during execution. Features file consist of Scenario, Scenario Outlines, Steps, Tags, Examples, etc. Each test case in Cucumber is called a scenario. A feature file is a group of this Scenario. For example, a Search Feature file consists of many search test cases. 
  2. Look for Linked Step Definition File: Each Scenario has a corresponding mapped step definition. A step definition is written in specific programming languages like Java, Ruby, Python, etc. Step definitions include the step of code which is mapped to a single or many scenarios. This code is linked with other code and automation libraries like Selenium. This code interacts with browsers using browser-specific drivers.
  3. Mark Scenario Pass or Fail: If the code in the step definition executes without error, Cucumber proceeds to the next step in the Scenario. During execution, if Cucumber reaches the end of the Scenario without any of the steps fail, it marks the Scenario as passed. In other cases, if any Step in the Scenario fails, Cucumber marks the Scenario as failed and moves on to the following Scenario. 
  4. Write results to reports and console: As the scenarios run, Cucumber prints out the results in the console or the Report you have enabled, showing you precisely what is working and what isn’t.