I want the same Gherkin sentence (with paramaters and without paramaters):
Gherkin with paramaters:
When a 'notify' message is sent to the green box with the properties.
|type|message|
|error|The error message|
Gherkin without paramaters:
When a 'notify' message is sent to the green box with the properties.
Java (cucumber):
@When("^a '(.*)' message is sent to the green box with the properties.$")
public void hello(String name, List<GherkinCondition> conditions) {
...
}
I have a error because java method is is declared with 2 parameters and in the case "without paramaters" I have only one.
stack trace:
cucumber.runtime.CucumberException: Arity mismatch: Step Definition 'steps.CommonSteps.hello(String,GherkinCondition>) in file:/C:/workspace/xxxxx/java/target/classes/' with pattern [^a '(.*)' message is sent to the green box with the properties.$] is declared with 2 parameters. However, the gherkin step has 1 arguments [notify].
Cucumber step definitions do not support optional parameters.
Either you write two different step definitions or you can give an empty datatable for the second case.
When a 'notify' message is sent to the green box with the properties.
|type|message|
or even
When a 'notify' message is sent to the green box with the properties.
|||
I`m doing it this way:
@Then("^Something is (not )?counted$")
public void somethingCounted(String optional) {
//
}
Regex matches both "Something is counted" and "Something is not counted"
For the first case, you'll get "not" value, for the second case you`ll get null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With