How to Integrate BDD Cucumber In Cypress 10
How to Integrate BDD Cucumber In Cypress 10

How to Integrate BDD Cucumber In Cypress 10

This blog covered about how we can support cucumbers in Cypress 10 version.

Problem Statement

After Cypress Version 10 some changes are required to implement Cucumber in Cypress.

In this blog, I am covering those changes and will tell you what are the dependencies that need to update.

The existing implementation of cucumber in cypress (Before Cypress 10) is here

What are Cucumber and BDD?

Cucumber is a testing tool that supports behavior-driven development (BDD).

BDD aqueducts the space between business stakeholders and the technical team through a standard platform and communication among the team becomes more transparent.
Gherkin language is used to write test cases in a straightforward format and even be read and modified by a non-technical user.

In BDD, “Given-When-Then” is the suggestive approach for writing test cases.

Here is an example for better understanding:

Given the user has entered valid credentials
When a user clicks on the sign-in button
Then validates the content on the home page after login

Installing Cypress

Step 1:

Create a folder and Generate package.json

  • Create a project, here naming it as Cypress10_With_Cucumber
  • Use the npm init command to create a package.json file

Step 2:

Install Cypress

To install Cypress, still, in the project folder, run > npm install cypress — save-dev

Once installed, Cypress version 10.9.0 is reflected as seen below

Installing Cucumber

We have to install two dev dependencies for Cucumber to run the test case in Cypress 10

Step 1:

Install the @badeball/cypress-cucumber-preprocessor using the command npm install -D @badeball/cypress-cucumber-preprocessor

Step 2:

Next, install one more dependencies ‘@bahmutov/cypress-esbuild-preprocessor’ using the commands npm install -D @bahmutov/cypress-esbuild-preprocessor.

We Can see both above dependencies are installed

Step 3:

Add below lines in cypress.config.js for cucumber preprocessor

const { defineConfig } = require(“cypress”);
const createBundler = require(“@bahmutov/cypress-esbuild-preprocessor”);
const addCucumberPreprocessorPlugin =
const createEsbuildPlugin =
module.exports = defineConfig({
e2e: {
async setupNodeEvents(on, config) {
const bundler = createBundler({
plugins: [createEsbuildPlugin(config)],

on(“file:preprocessor”, bundler);
await addCucumberPreprocessorPlugin(on, config);

return config;
specPattern: “cypress/e2e/**/*.feature”,

Covering the below scenarios in this blog

For demo purposes, I have taken the example of the site

Scenario Covered :

Scenario 1
Open the Url
Verify Menu in Home Page
Validate the Title after login

Scenario 2
Open the Url
Search the blog
Verify the correct blog name searched

Create Feature file


Create a HomeTest feature file that covers verification of Menus in the site also verify the title of the site

Feature: Home Page

Given I navigate to the Website
Scenario: I want to verify content in Home Page
Then Validate the menus in home page

| menu_name |
| Home |
| Blogs |
| Contact Us |
Scenario: I want to validate title of home page
Then Validate the title after login
| title |
| About Us — QAAutomationLabs |


Create a SearchProductTest feature file which covers searching the blog and verifies the searched text “Cypress” in the search result

Feature: Search Product

Given I navigate to the Website

Scenario: I want to search the product in home page
Then Search the blog
| blog |
| Cypress |
Then Verify correct blog name searched
| searchValue |
| Cypress |

Folder structure looks like the attached below

Create Cypress Test cases

Create TestClass

Create HomeTest.spec.js under Tests ->HomeTest

/// <reference types=”cypress” />
import { Given, Then } from “@badeball/cypress-cucumber-preprocessor”;
import homePage from “../../Pages/HomePage/HomePage.spec”;
beforeEach(() => {
cy.viewport(1600, 720);
Given(“I navigate to the Website”, () => {
Then(“Validate the menus in home page”, (datatable) => {
datatable.hashes().forEach((element) => {
Then(“Validate the title after login”, (datatable) => {
datatable.hashes().forEach((element) => {

Create SearchProductTest.spec.js under Tests ->SearchProductTest

/// <reference types=”cypress” />
import { Given, When, Then } from “@badeball/cypress-cucumber-preprocessor”;
import searchProduct from “../../Pages//SearchProductPage/SearchProductPage.spec”;
import homePage from “../../Pages/HomePage/HomePage.spec”;

Given(“I navigate to the Website”, () => {
When(“Search the blog”, (datatable) => {
datatable.hashes().forEach((element) => {
Then(“Verify correct blog name searched”, (datatable) => {
datatable.hashes().forEach((element) => {

Create PageClass

HomePage.spec.js under Pages ->HomePage Folder

/// <reference types =”cypress”/>

class HomePage {
enterURL() {
validateMenus(menus) {
return this;
verifyPageTitle() {
return cy.title().should(“eq”, “About Us — QAAutomationLabs”);
const homepage = new HomePage();
export default homepage;

SearchProductPage.spec.js under Pages ->SearchProductPage Folder

class SearchProduct {
SearchProduct(searchProductName) {
cy.get(“#top-nav > .page-item-5 > a > span”).click({ force: true });
.click({ force: true })
cy.get(“[id=’search-icon’]”).click({ force: true });
verifyProduct(searchProductName) {
const searchProduct = new SearchProduct();
export default searchProduct;

Run Test cases

Run the command: yarn run cypress open.In the below screenshot here we can see two feature files are displaying

Run HomeTest.feature

In below screenshot we can see menus in the Home page and the title of the site is verified

Run SearchProductTest.feature

In the below screenshot we can see the site is open, search the text “Cypress” and verify the search text in the search results

☕️ Happy testing! ☕️

Leave a Reply

Your email address will not be published.