cucumber.runtime.CucumberException: Arity mismatch: Step Definition in selenium with Java 的错误是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37041622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the error of cucumber.runtime.CucumberException: Arity mismatch: Step Definition in selenium with Java
提问by Chathurika Prabodani
I have wrritten a feature file to test the create elements button. But it generates an error message of
我写了一个功能文件来测试创建元素按钮。但它会生成一条错误消息
cucumber.runtime.CucumberException: Arity mismatch: Step Definition.
I dont know why its happening since I am new to automation testing.
我不知道为什么会发生这种情况,因为我是自动化测试的新手。
The following is the code that I have written.
下面是我写的代码。
@When("^create elements$")
public void create_elements_for_attributes(WebElement elementToClick) throws Throwable {
driver.findElement(By.id("newElement")).click();
}
The error that I have recieved is as follows.
我收到的错误如下。
cucumber.runtime.CucumberException: Arity mismatch: Step Definition 'mCollector.features.StepDefinitions_mCollector.create_elements_for_attributes(WebElement) in file:/C:/Users/Admin/workspace/MStudio%20-%20eBilling/bin/' with pattern [^create elements$] is declared with 1 parameters. However, the gherkin step has 0 arguments [].
回答by Eugene S
In your create_elements_for_attributes
method you are expecting one argument of type WebElement
but your regex does not capture any arguments. It should look something like that instead:
在您的create_elements_for_attributes
方法中,您需要一个类型的参数,WebElement
但您的正则表达式不捕获任何参数。它应该看起来像这样:
@When("^create elements \"([^\"]*)\"$")
And then in your feature file:
然后在您的功能文件中:
When create elements "element"
But that won't work either because you can't pass a WebeElement
object from your Cucumber feature file. You should only operate with primitive values and DataTables. Other types (like WebeElement)
should be created internally in the glue code itself.
但这也行不通,因为您无法WebeElement
从 Cucumber 功能文件中传递对象。您应该只使用原始值和数据表进行操作。其他类型(比如WebeElement)
应该在粘合代码本身内部创建。