55555.0.0 • Public • Published


Fluent, painless, and beautiful synchronous/asynchronous step definitions for Cucumber.js. Supports promises, generators, and async functions, powered by co.

Oh, and listen to some nice chill trap and artstep.

Note: v55555 works with Cucumber 0.9. For older versions of Cucumber (v0.4), please use v5555.


When creating step definitions for cucumber-js, I always feel like this:

Y U NO...

It simply sucks. As of v0.4.8: Not so much anymore:

  • If you forget to call the callback function, the event queue is drained and Cucumber simply exits without reporting anything. It now times out. Hurray!
  • No support for promises or generators. It now supports Promises.
  • Having to use this. every time to define a single step.

So I created some wrapper functions for them and then turn it into a library.


var steps = require('artstep')

Returns a function that can be exported as a Cucumber steps definitions.

The returned function also has several methods, which can be used to define steps. These methods are all fluent, meaning that they all return the same function.


var steps = require('artstep')
module.exports = steps()
.Given(pattern, handler)
.When(pattern, handler)
.Then(pattern, handler)
.before(...tags, handler)
.after(...tags, handler)

Note: Both PascalCase and lowerCamelCase versions are available for all these methods.

Handler Function

A handler is:

  • A synchronous function. Handler will finish running immediately:

    .Then('the title contains "..."', function(text) {
  • A function that returns a Promise:

    .When('I select the $n song', function(n) {
      n = parseInt(n, 10)
      return driver.findElements(By.css(' > li'))
      .then(function(items) {
        return items[- 1].click()

    In CoffeeScript, it looks very beautiful:

    .When 'I select the $n song', (n) ->
      n = parseInt(n, 10)
      driver.findElements(By.css(' > li')).then (items) ->
        items[- 1].click()
  • An ES6 generator function:

    .When('I select the $n song', function*(n) {
      n = parseInt(n, 10)
      var items = yield driver.findElements(By.css(' > li'))
      yield items[- 1].click()

    You can yield promises, generators, thunks, arrays, or objects. Then the resolved value will be given back unto you. This is possible because of the amazing co library.

  • An ES7 asynchronous function:

    .When('I select the $n song', async function(n) {
      n = parseInt(n, 10)
      var items = await driver.findElements(By.css(' > li'))
      await items[- 1].click()
  • An async function from asyncawait, which makes this CoffeeScript steps definitions extremely beautiful!

    .When 'I select the $n song'async ->
      = parseInt(n10)
      items = await driver.findElements(By.css(' > li'))
      await items[- 1].click()
  • null, false or undefined. In this case, the steps will be marked as "pending."

Around Hooks

The semantic of around hooks changed a little bit. It passes a function that, when called, runs the scenario, and returns a Promise which will be resolved when the scenario finishes executing.

That promise can be yielded.

  • ES5 + Promises:

    .Around(function(run) {
      return stuffBefore()
  • ES6 Generators:

    .Around(function*(run) {
      var start =
      yield run()
      var finish =
      console.log('It took', finish - start, 'ms')
  • ES7 Async Functions:

    .Around(async function(run) {
      var start =
      await run()
      var finish =
      console.log('It took', finish - start, 'ms')

Package Sidebar


npm i artstep

Weekly Downloads






Last publish


  • dtinth