Cucumber.js

Specifications Repository & Automation Layer

Cucumber is a framework for defining behavior using a language called Gherkin. The Gherkin syntax uses a combination of keywords and natural language.

Feature files with a .feature extension are parsed with the Gherkin syntax. Consider this feature file:

Feature: One-line description of the feature

	Anything can be used here to provide context for this specification. 
  You may want to use the story format below.

  As an <actor>
  I want <feature>
  So that <benefit>

  Background: The background is optional
    Given something that happens before every scenario
    And something else that happens before every scenario

  Scenario: One-line description of the scenario
    Given some pre-condition with a parameter "myParam"
    And another pre-condition
    When an event is triggered
    Then an expected result happens
    But an unexpected result does not happen

Some things to note about this file:

  • It is the specification of a single feature for the application / system
  • A feature can have freeform context before scenarios are defined.
  • A feature has many scenarios.
  • Each scenario is a unique flow within the feature
  • A scenario has many steps.
  • A step starts with a keyword and contains freeform text
  • A feature may contain an optional background which also contains steps

Steps are the bridge between the feature and the automation layer. They are automated using step definition files. The step definitions can be defined either in javascript or coffee using the --coffee switch. Here is an example:

this.Given(/^some pre-condition with a parameter "([^"]*)"$/, function (arg1) {
  // Write the automation code here
  pending();
});

You will notice the step definition above uses regex to match the step in the feature file. The regex can also extract parameters from the freeform text. The Gherkin syntax also supports tables and multi-line strings amongst other constructs.

This is a very brief overview of Cucumber and the Gherkin syntax. Be sure to check out the further reading section for additional learning resources on the wonderful subject of Behavior Driven Development (BDD).

See the official documentation here:



##Learn the Fundamentals of Testing, Specifications and Become a Chimp Ninja!
Checkout our new book where you can learn how to can use Chimp across the Full Stack from React to Node.JS, Mocha, Meteor and more.

Quality, Faster. By Sam Hatoum, creator of Chimp.