I'm new to Cucumber and want to understand how to use default param in a feature file testcase.feature for example:

And User click Delete on task action

In the step definition, the params could be anything, because I use (.*). However I want user to be limited to one of 3 values such as Create, Edit, Delete.

How can I define it in step definition, below is my current code implementation:

@And("^User search (.*)on tasklist$")
    public void searchTask(String taskObject) throws Throwable {
        TaskboardPage taskboardPage = new TaskboardPage(sbConnect);


Could I user @And(User search (?: Create | Edit | Delete) on tasklist)?

1 Answer 1


Yes. However, you are referencing that string later on; if you use "(?: Create | Edit | Delete)", you will be using a non-capturing regular expression and will not capture the argument into taskObject, meaning you won't have that value when you later attempt "taskboardPage.searchTask(taskObject);"

I suspect you want to use a capturing regular expression:

@And("^User search (Create|Edit|Delete) on tasklist$")

This article has some great information on regular expressions for Cucumber, including a good section on capturing vs. non-capturing groups: http://www.agileforall.com/2010/07/just-enough-regular-expressions-for-cucumber/

In general, with Cucumber you can specify any regular expression within those parentheses, and you will be able to match only strings that match the whole regular expression. Cucumber is just using regular expressions to match steps and to capture arguments.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.