.agents/skills/e2e-cucumber-playwright/references/cucumber-best-practices.md
Use this reference when writing or reviewing Gherkin scenarios, step definitions, parameter expressions, and step reuse.
Official sources:
Cucumber scenarios should describe examples of behavior, not test implementation recipes.
Apply it like this:
A scenario should usually prove one workflow or business outcome. If a scenario wanders across several unrelated behaviors, split it.
Keep each scenario centered on one coherent outcome. Avoid hidden dependencies on another scenario's side effects, and keep unavoidable setup outside the behavior narrative unless the precondition matters to the specification.
Good reuse reduces duplication. Bad reuse hides meaning.
Prefer reuse when:
Write a new step when:
Do not optimize for a low step count by making vague steps. Optimize for a small set of truthful, domain-owned steps.
Use Cucumber Expressions for parameters unless regex is clearly necessary.
Common examples:
{string} for labels, names, and visible text{int} for counts{float} for decimal values{word} only when the value is truly a single tokenKeep expressions readable. If a step needs complicated parsing logic, first ask whether the scenario wording should be simpler.
Use regex for a bounded natural-language alternative only when it keeps Gherkin readable, for example /(Web app|Backend service API)/. Avoid broad regexes that accept unowned language.
Step definitions are glue between Gherkin and automation, not a second abstraction language.
Keep each step to one user-visible action or assertion. In JavaScript and TypeScript, use async function when the step reads Cucumber World state because Cucumber binds this; do not leak state across scenarios through module globals.
Tags should communicate selection or execution intent, not become ad hoc metadata. A tag does not change runtime behavior unless configuration or hooks implement it.