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.
The following Gherkin step:
Given I have 42 cucumbers in my belly
Can be implemented with following Cucumber Expression in Scala:
Given("""I have {int} cucumbers in my belly"""){ (cucumberCount: Int) =>
// Do something
}
The following Gherkin step:
Given I have 42 cucumbers in my belly
Can be implemented with following Regular Expression in Scala:
Given("""^I have (\d+) cucumbers in my belly$"""){ (cucumberCount: Int) =>
// Do something
}