What is cucumber.runtime.CucumberException error: Arity mismatch: determining a step in selenium using Java

I wrote a properties file to test the button for creating items. But it generates an error message

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

I don’t know why this is happening since I am new to automation testing.

Below is the code I wrote.

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

The error I received 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 []. 
+5
source share
1 answer

In your create_elements_for_attributes method create_elements_for_attributes you expect one argument of type WebElement , but your regular expression does not accept any arguments. Instead, it should look something like this:

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

And then in your properties file:

 When create elements "element" 

But this will not work, because you cannot pass the WebeElement object from your Cucumber function file. You should only work with primitive values ​​and DataTables. Other types (e.g. WebeElement) must be created inside the glue code itself.

+3
source

All Articles