Skip to content

[Question]: Supporting OR operator (a|an) in step definitions #368

Description

Question

In Cucumber-style step definitions, it’s common to want a single step to match natural language variations such as:

  • Then I should see an error message
  • Then I should see a success message

If I'm not mistaken, in plain Cucumber with regex-based steps, this can typically be handled with something like:

@Then("I should see (?:a|an) (success|error) message")
public async shouldSeeMessage(result: "success" | "error"): { ... }

However, this approach does not seem to be supported (or at least not recognised correctly) when using playwright-bdd.

It seems it is possible, however, to use a/an and success/error in the regex, but it has the following disadvantages:

  • Is not a capturing group, meaning I can't extract the word
    • Unless I use {word}, at the cost of readability
  • Misaligns with VSCucumberAutoComplete extension, if you use strict validating options:
    "cucumberautocomplete.strictGherkinCompletion": true,
    "cucumberautocomplete.strictGherkinValidation": true,

Unless there is no workaround, would you be open to support this?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions