cucumber.runtime.CucumberException: Arity Mismatch: Step Definition in selenium with Java 的错误是什么

2024-03-30

我编写了一个功能文件来测试创建元素按钮。但它会生成一条错误消息

cucumber.runtime.CucumberException: Arity mismatch: Step Definition. 

我不知道为什么会发生这种情况,因为我是自动化测试的新手。

以下是我编写的代码。

@When("^create elements$")
public void create_elements_for_attributes(WebElement elementToClick) throws Throwable {
driver.findElement(By.id("newElement")).click();
}

我收到的错误如下。

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

In your create_elements_for_attributes您期望一个类型参数的方法WebElement但你的正则表达式没有捕获任何参数。它应该看起来像这样:

@When("^create elements \"([^\"]*)\"$")

然后在你的功能文件中:

When create elements "element"

但这也行不通,因为你无法通过WebeElement来自 Cucumber 功能文件的对象。您应该只使用原始值和数据表进行操作。其他类型(如WebeElement)应该在粘合代码本身内部创建。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

cucumber.runtime.CucumberException: Arity Mismatch: Step Definition in selenium with Java 的错误是什么 的相关文章

随机推荐