Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 1.17 KB

step_definitions.md

File metadata and controls

47 lines (35 loc) · 1.17 KB

Step definitions

Step definitions (Given, When, Then) are the glue between features written in Gherkin and the actual tests implementation.

Cucumber supports two types of expressions:

  • Cucumber expressions
  • Regular expressions

See also the reference documentation.

Cucumber expressions

Cucumber expressions

The following Gherkin step:

Given I have 42 cucumbers in my belly

Can be implemented with following Cucumber Expression in Groovy:

Given("I have {int} cucumbers in my belly"){ int cucumberCount ->
  // Do something    
}

Regular expressions

The following Gherkin step:

Given I have 42 cucumbers in my belly

Can be implemented with following Regular Expression in Groovy:

Given(~/'^I have (\d+) cucumbers in my belly$'/){ int cucumberCount ->
  // Do something    
}

To implement multiple gherkin steps in a single cucumber step:

Given([~/^I have (\d+) cuke in my belly/, ~/^I have (\d+) cukes in my belly/] as Pattern[]) { int cukes ->
  // Do something 
}