Skip to content

Cucumber Syntax

rlogiacco edited this page Apr 29, 2012 · 1 revision

The following is a list of supported Cucumber syntactical elements with an example Cucumber Feature file. The Cucumber syntax is defined in a Xtext DSL file. The following is an example of a valid Cucumber file:

Feature: Addition
  In order to avoid silly mistakes
  As a math idiot 
  I want to be told the sum of two numbers

  @release1
  Scenario Outline: Add two numbers
    Given I have entered <input_1> into the calculator
    And I have entered <input_2> into the calculator
    When I press <button>
    Then the result should be <output> on the screen

  Examples: sample data
    | input_1 | input_2 | button | output |
    | 20      | 30      | add    | 50     |
    | 2       | 5       | add    | 7      |
    | 0       | 40      | add    | 40     |

  @release1 @regression
  Scenario: Regular numbers
    Given I have entered 3 into the calculator
    And I have entered 2 into the calculator
    And I press divide
    Then the result should be 1.5 on the screen

Feature (read more)

A feature can optionally have Tags, is defined by a mandatory Feature: string followed by a title, can have a multiline description, an optional Background and one or more Scenario or Scenario Outline.

Background (read more)

A background is defined by a mandatory Background: string followed by a title and can have a multiline description.

Scenario (read more)

A scenario is defined by optional Tags, a mandatory Scenario: string followed by a title, an optional multiline description and one or more Steps.

Scenario outlines (read more)

A scenario outline is defined by an optional Tags, a mandatory Scenario Outline: string followed by a title, , an optional multiline description, one or more Steps and one or more Examples.

Step (read more)

A step is defined by a mandatory Given, When, Then, And or But string followed by a step definition and can optionally have an associated Table

Example (read more)

An example is defined by a mandatory Examples: string followed by a multiline description and an optional sequence of Tables.

Table (read more)

A table is defined by a sequence of rows where each cell row is delimited by a pipe | char, like

    | input_1 | input_2 | button | output |
    | 20      | 30      | add    | 50     |
    | 2       | 5       | add    | 7      |
    | 0       | 40      | add    | 40     |

Tag (read more)

Tags can be used before Features, Scenarios or Scenario outlines and are defined by the at @ char followed by a string: Multiple tags can be space or line separated.

Comments

Each line starting with the hash # char will be considered a comment and will be ignored by the parser.