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

蓝咒 提交于 2021-01-27 03:52:27

问题


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 [].

回答1:


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:

@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.



来源:https://stackoverflow.com/questions/37041622/what-is-the-error-of-cucumber-runtime-cucumberexception-arity-mismatch-step-de

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!