Search code examples
javatestingcucumberbddgherkin

Why can't cucumber create step definition of bdd sentences that is end with ')' or '.'?


I can't create step definition of bdd sentences which ends with some punctuation mark.

It creates this sentences as 'null'

When I search "user X" in search field 'id (username)'
And I click on search button
@When("null")
    public void ıSearchInSearchFieldidUsername(String arg0) {
    }

I expect something like that:

@When("^I search \"([^\"]*)\" in search field 'id (username)")

Edit: I've just got same result for this sentence also:

When I search "user X" in search field 'id. username'

Solution

  • Gherkin is meant to be a more natural language expression of the business requirements, not the actual syntax from the developer. In other words, you probably want to simply describe the field instead of using the exact field name from code. There is no need to make a variable (using quotation marks or other special characters) in that sentence unless you intend to use it in your test code. But it looks like in this example you don't have any alternate variables to supply, it appears you are only setting up the scenario. So just describe the basic scenario. Try something that sounds more like natural language, like:

    When I enter a name in the username search field
    And I click on the search button
    

    Check the Gherkin documentation to see how to use variables and other special characters.