Search code examples
javacucumber-java

Cucumber Capture Custom Expressions Java - How to allow for string entry in feature steps?


We are attempting to switch over entirely to Cucumber expressions and no longer use Regex. My question is it possible to create a type that allows for a String entry in the feature file?

For example: (the "second" user is ) instead of (the second user is )

Here is the custom paramType method I am using.

registry.defineParameterType(new ParameterType<>(
                "universalKey",
                "1st|first|2nd|second|3rd|third",
                String.class,
                (String arg) -> arg
        ));

Currently it allows for no strings entry but I would like to keep it with quotes to avoid having to redo a lot of feature files/steps.


Solution

  • I ended up figuring out although not using it but the following is how we did it:

    registry.defineParameterType(new ParameterType<>(
                "numbers",
                "\"(1st)"\|\"(first)"\|\"(2nd)"\|\"(second)"\",
                String.class,
                (String arg) -> arg
        ));