Search code examples
cucumbercucumber-jvmgherkin

How to avoid digit being captured as numeric argument in Gherkin?


I am new to Gherkin.

I am writing the following statement in Gherkin:

Given user have institution_1 in database

And here institution_1 for me is just a regular noun, I do not want it to be a variable or have index "1".

The Java function auto-generated by Cucumber-JVM is:

@Given("^user have institution_(\\d+) in database as follows:$")
public void user_have_institution__in_database(int arg1) throws Throwable {
}

How do I rewrite it so that Cucumber-JVM will recognize that "1" does not have special meaning, and return to me something like:

@Given("^user have institution_1 in database as follows:$")
public void user_have_institution_1_in_database() throws Throwable {
}

Thanks!

EDIT: My question is: Cucumber-JVM see every number is Gherkins as numeric argument, for example,

"institution_1" 

is converted to:

 "institution_(\\d+)" 

and the java function will have a

(int arg1) 

argument.

What I want is to have Cucumber-JVM not to convert to:

@Given("^user have institution_(\\d+) in database as follows:$")

but to something like:

@Given("^user have institution_1 in database as follows:$") 

or some other form where regular expression will catch it but not having an argument. Because in common sense, 1 in XXXXX_1 is not meant be a numeric argument, but a character.

If that's not possible, how can I have this to work?

@Given("^user have institution_(\\d+) in database as follows:$")
public void user_have_institution__in_database() throws Throwable {
}

Solution

  • Manually edit the generated Gherkin to:

    @Given("^user have institution_1 in database as follows:$")
    public void user_have_institution_in_database() throws Throwable {
    }