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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:08:15  来源:igfitidea点击:

what is the error of cucumber.runtime.CucumberException: Arity mismatch: Step Definition in selenium with Java

javaselenium-webdrivercucumberautomated-tests

提问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_attributesmethod you are expecting one argument of type WebElementbut 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 WebeElementobject 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)应该在粘合代码本身内部创建。