CodeceptJS Cucumber BDD Framework

5.0.0 · active · verified Sun Apr 19

codeceptjs-cucumber is an E2E testing framework that integrates CodeceptJS with Cucumber, enabling Behavior-Driven Development (BDD) workflows. It facilitates running tests across multiple browsers and offers out-of-the-box integration for Sauce Labs, allowing for efficient parallel test execution in the cloud. The current stable version is 5.0.0, released in late 2023. This package typically follows a major release cadence of approximately one to two years, aligning with updates in its core dependencies like CodeceptJS and Cucumber. It leverages the Should.js assertion library by default. As an opinionated framework, its key differentiator lies in simplifying the setup and configuration required to combine these powerful testing tools, particularly for complex cloud-based, cross-browser test automation scenarios, reducing the boilerplate often associated with such integrations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart sets up a basic CodeceptJS-Cucumber project to perform a Google search. It demonstrates the `package.json` for dependencies, `codecept.conf.js` to configure the Playwright helper and the Cucumber integration, a Gherkin `.feature` file defining a search scenario, and corresponding JavaScript step definitions. Execute tests using `npm test`.

/* package.json */
{
  "name": "codeceptjs-cucumber-example",
  "version": "1.0.0",
  "description": "Example usage of codeceptjs-cucumber",
  "scripts": {
    "test": "codeceptjs run --steps"
  },
  "devDependencies": {
    "codeceptjs": "^3.0.0",
    "@cucumber/cucumber": "^10.0.0",
    "codeceptjs-cucumber": "^5.0.0",
    "playwright": "^1.0.0",
    "should": "^13.0.0"
  }
}

/* codecept.conf.js */
const { setWorldConstructor } = require('@cucumber/cucumber');

exports.config = {
  output: './output',
  helpers: {
    Playwright: {
      url: 'https://www.google.com',
      show: true,
      browser: 'chromium'
    },
    Cucumber: {
      require: './step_definitions',
      features: './features/*.feature'
    }
  },
  include: {
    I: './steps_file.js'
  },
  gherkin: {
    features: './features/*.feature',
    steps: ['./step_definitions/steps.js']
  },
  plugins: {
    allure: {
      enabled: true
    },
    retryFailedStep: {
      enabled: true
    },
    screenshotOnFail: {
      enabled: true
    }
  },
  bootstrap: null,
  teardown: null,
  mocha: {},
  name: 'codeceptjs-cucumber-example'
};

/* features/search.feature */
Feature: Google Search Functionality
  As a user, I want to search on Google
  So that I can find information

  Scenario: Search for a specific term
    Given I am on the Google homepage
    When I search for "CodeceptJS Cucumber"
    Then I should see "CodeceptJS Cucumber" in the search results

/* step_definitions/steps.js */
const { I } = inject();
const { Given, When, Then } = require('@cucumber/cucumber');

Given('I am on the Google homepage', () => {
  I.amOnPage('/');
});

When('I search for "{string}"', async (searchTerm) => {
  I.fillField('textarea[name="q"]', searchTerm);
  I.pressKey('Enter');
});

Then('I should see "{string}" in the search results', async (expectedText) => {
  I.see(expectedText);
});

view raw JSON →