top of page
Writer's pictureAnupama Binoy

An easy explanation of Cucumber BDD framework

what is Cucumber BDD framework?

If you are exploring software testing a lot you would have heard about selenium, maven, cucumber BDD framework

What is this cucumber BDD framework, how we implement this in a project. I am going to explain this topic in a simple way so that a beginner can understand and learn this topic.

cucumber BDD framework

Cucumber is a testing tool that supports Behavior Driven Development (BDD). It offers a way to write tests that anybody can understand, regardless of their technical knowledge.

The behavior-driven development’s approach involves the usage of shared language that enhances communication between various tech and non-tech teams. In BDD, we use “Given”, “When” and “Then”  keywords for writing test cases.

It emerged from test-driven development (TDD), where tests are written before code and passing the tests is the critical driver of software development. BDD makes use of the general techniques and principles of TDD while providing all relevant teams with a shared process to collaborate on software development.

The scenarios are written based on the expected behavior of the software and it is tested to check if it matches said scenarios. These scenarios are documented using a Domain Specific Language such as Gherkin. In each test scenario, natural language constructs constituting small English-like phrases are used to describe the behavior and expected outcome of an application. This is done using a dedicated software tool like Cucumber, that allows the execution of automated acceptance tests written in Gherkin.



How to setup cucumber BDD on Elipse

  1. First we have to create a new maven project





2.  Maven Project > Next > Next



Put Group id and Artifact id . Here I have given newcucumberBDD as Group id and Artifact id

Click on Finish



We have to add some dependencies which are

Selenium Java maven dependencies, Cucmber java maven dependencies,

Cucmber JVM : JUnit4, cucumber JVM : TestNG

Try to add the latest version




Help > Eclipse Marketplace > Cucumber Eclipse Plugin (install this)

Right click on the project > Configure > Convert to Cucumber Project

You are good to go now.

What is cucumber in selenium?

Cucumber Framework in Selenium is an open-source testing framework that supports Behavior Driven Development for automation testing of web application. The tests are first written in a simple scenario form that describes the expected behavior of the system from the user’s perspective.


The Cucumber BDD framework for Selenium

Cucumber BDD framework mainly consists of three parts – Feature File, Step Definitions, and the Test Runner File.


  • What is Feature File



This is how we write a feature file using Given, When and Then keywords. A feature file contains multiple scenarios.

  • Scenario: Scenario describes the steps and expected outcome for a particular test case.

  • Scenario Outline: Same scenario can be executed for multiple sets of data using scenario outline. The data is provided by a tabular structure separated by (I I).

  • Given: It specifies the context of the text to be executed. By using datatables “Given”, step can also be parameterized.

  • When: “When” specifies the test action that has to performed

  • Then: The expected outcome of the test can be represented by “Then”

The Given-When-Then formula is a template intended to guide the writing of acceptance tests for a User Story: (Given) some context. we can say this is the precondition. (When) some action is carried out. (Then) a particular set of observable consequences should obtain. This is basically the Result.



  •  What is Step definition File


How to write a Step definition file?

WE can write a step definition file by following these steps

1) Create a new Class file in the ‘Step definition‘ package and name it as loginPage.java,  by right click on the package and select New > Class, click on Finish button.

When Cucumber executes a Step in a Scenario, it will look for a matching Step Definition to execute. You can see some yellow lines shows in login.feature, which signifies steps within the defined feature that are not yet implemented. The easiest way to auto generate the step definitions steps is to just run your feature file to get step definition suggestions in the console. You can see, the eclipse console window says 'You can implement missing steps with the snippets below:'. It is very easy to implement all the steps, all you need to do is to copy the complete text and paste it into the above created stepdefinition class.

Here we have a snapshot of Step definition file, which is written as per the feature file that is mentioned above.



  • What is Test Runner File.

  • Test Runner File: In Cucumber, the test runner file executes the Cucumber feature files and coordinates the steps defined in those feature files with the corresponding step definitions. Here I have used @CucumberOptions.



Reports

Reports are basically the structured as well as a graphical way to produce the execution results of tests.

In Jenkins's perspective, different formats of reports are available. It depends on us that in which format we want to publish our results. These reports can be graphical, tabular, or in other detailed formats. The Jenkins reporting capabilities majorly depend on third-party plugins. So, we will need to install and configure a compatible plugin for the same whatever the report's expected format.

Here you can see the snapshots of different reports


  • Allure report


  • Extent Report




  • Cucumber Report


  • TestNG Report

TestNG Reports are the default HTML reports which are generated once the test cases are executed using TestNG. These reports help to identify the information about test cases and the status of a project.




I hope This topic is clear and easy to understand .

Happy learning.......



651 views

Recent Posts

See All
bottom of page