Cucumber.js

Cucumber for JavaScript

README


  Cucumber

Automated tests in plain language, for Node.js

#StandWithUkraine npm build coverage backers sponsors pull requests issues

Cucumber is a tool for running automated tests written in plain language. Because they're
written in plain language, they can be read by anyone on your team. Because they can be
read by anyone, you can use them to help improve communication, collaboration and trust on
your team.

This is the JavaScript implementation of Cucumber. It runs on maintained versions of Node.js. You can quickly try it via CodeSandbox, or read on to get started locally in a couple of minutes.

Looking to contribute? Read our code of conduct first, then check the contributing guide to get up and running.

Install


Cucumber is available on npm:

  1. ``` sh
  2. $ npm install @cucumber/cucumber
  3. ```

Get Started


Let's take this example of something to test:

  1. ``` js
  2. class Greeter {
  3.   sayHello() {
  4.     return 'hello'
  5.   }
  6. }
  7. ```

First, write your feature in features/greeting.feature:

  1. ```gherkin
  2. Feature: Greeting

  3.   Scenario: Say hello
  4.     When the greeter says hello
  5.     Then I should have heard "hello"
  6. ```

Next, implement your steps in features/support/steps.js:

  1. ``` js
  2. const assert = require('assert')
  3. const { When, Then } = require('@cucumber/cucumber')
  4. const { Greeter } = require('../../src')

  5. When('the greeter says hello', function () {
  6.   this.whatIHeard = new Greeter().sayHello()
  7. });

  8. Then('I should have heard {string}', function (expectedResponse) {
  9.   assert.equal(this.whatIHeard, expectedResponse)
  10. });
  11. ```

Finally, run Cucumber:

  1. ``` sh
  2. $ npx cucumber-js
  3. ```

And see the output:

Terminal output showing a successful test run with 1 scenario and 2 steps, all passing

If you learn best by example, we have a repo with several example projects, that might help you get going.

Documentation


The following documentation is for main, which might contain some unreleased features. See documentation for older versions if you need it.

Support Code
  Hooks
  World
Guides

Support


Support is available from the community if you need it.