A Cucumber expression is a pattern in a step definition annotation that matches a Gherkin step and passes parts of its text to automation code. It lets a readable scenario supply data—such as a train line, stations, and departure times—without putting every value into the step definition itself. That binding code is often called glue code. section 3.5.3
Reuse a step definition across scenarios
Instead of writing separate methods for Standard and Silver Frequent Flyer members, use `@Given("{word} is a {word} Frequent Flyer member")`. The captured name and status become method parameters. If the status parameter is an enum, `@Given("{word} is a {} Frequent Flyer member")` can use the anonymous `{}` type to convert the scenario text directly. section 8.4.1
Choose a parameter type for the data the scenario supplies:
- `{int}` captures a whole number; `{float}` captures a floating-point number. section 8.4.1
- `{word}` captures one word without whitespace; `{string}` captures text enclosed in double quotes. section 8.4.1
- `{}` matches more general text and attempts conversion to the step method’s declared parameter type. section 8.4.1
Table 8.1 Built-in Cucumber Expression types (view table figure)
| Matches any expression (works with enums and most basic types) |
|||
|
|
|||
Compare the built-in parameter types with the scenario text each one matches before choosing a placeholder. section 8.4.1
Keep small wording differences from forcing duplicate definitions. Parentheses make text optional: `year(s)` matches both “year” and “years.” A slash allows alternative words: `member/customer` accepts either word. Slash alternatives work for words without whitespace; more sophisticated matching calls for regular expressions. section 8.4.2
Map a business step to a task
In Cucumber.js, `When('{actor} signs up using valid traveler details', ...)` matches a scenario step and supplies an actor to a step definition that runs Screenplay Pattern tasks. `{actor}` is not built in: a custom parameter type transforms the captured name into a Serenity/JS actor. A separate `{pronoun}` type can refer to the most recently used actor. section 14.3
