0

Getting an error as Arity mismatch error for step defination,I ma using map to send the test data,

Below is my feature file,Step definition and runner class

Feature: CRMPRO Login

Scenario: To verify login functionality

Given user is on CRMPRO Login page
When Enters the userName and password
  |userName||password|
  |test||test12|
And click on login button
Then CRMPRO home page should be displayed


    import java.awt.Robot;
    import java.awt.event.KeyEvent;
    import java.util.List;
    import java.util.Map;

    import org.apache.xpath.Arg;
    import org.junit.Assert;
    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;

    import cucumber.api.DataTable;
    import cucumber.api.PendingException;
    import cucumber.api.java.en.And;
    import cucumber.api.java.en.Given;
    import cucumber.api.java.en.Then;
    import cucumber.api.java.en.When;

    public class StepDefination {

        WebDriver driver;
        String searchKeyword;

        @Given("^user is on CRMPRO Login page$")
        public void user_is_on_CRMPRO_Login_page() throws Throwable {
            // Write code here that turns the phrase above into concrete actions
            System.setProperty("webdriver.chrome.driver", "F://chromedriver.exe");
            driver = new ChromeDriver();
            driver.manage().window().maximize();
            driver.get("https://www.crmpro.com");

        }

        @When("^Enters the userName and password$")
        public void enters_the_userName_and_password(DataTable table) throws Throwable {
            // Write code here that turns the crmpro phrase above into concrete
            // actions
            List<Map<String, String>> s = table.asMaps(String.class, String.class);

            driver.findElement(By.name("username")).sendKeys(s.get(0).get("userName"));
            driver.findElement(By.name("password")).sendKeys(s.get(0).get("password"));

        }

        @When("^click on login button$")
        public void cick_on_login_button() throws Throwable {
            // Write code here that turns the phrase above into concrete actions
            WebElement buttonLogin = driver.findElement(By.xpath("//input[@type='submit']"));
            JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("arguments[0].click()", buttonLogin);

        }

        @Then("^CRMPRO home page should be displayed$")
        public void crpro_home_page_should_be_displayed() throws Throwable {
            // Write code here that turns the phrase above into concrete actions
            driver.switchTo().frame("mainpanel");
            Assert.assertEquals(driver.findElement(By.xpath("//div[@id='handle_CRMBLOG']")).getText(), "CRMPRO News");
        }

    }

package com.mavenDemo;

import org.junit.runner.RunWith;

 import cucumber.api.CucumberOptions;
 import cucumber.api.junit.Cucumber;

 @RunWith(Cucumber.class)
 @CucumberOptions(features = 
"C:/Users/BR/workspace/com.mavenDemo/src/main/java/GmailLogin.feature", 
 glue = {"com.mavenDemo" })
 public class TestRunner {

}

Getting an error as :

cucumber.runtime.CucumberException: Arity mismatch: Step Definition 'com.mavenDemo.StepDefination.enters_the_userName_and_password(DataTable) in file:/C:/Users/BR/workspace/com.mavenDemo/target/classes/' with pattern [^Enters the userName and password$] is declared with 1 parameters. However, the gherkin step has 0 arguments [].

I am not able to resolve above error pleas help me in resolving above error please.

Thanks

Good Vibes
  • 163
  • 2
  • 12
  • Does this answer your question? [What is "cucumber.runtime.CucumberException: Arity mismatch: Step Definition" in java testing?](https://stackoverflow.com/questions/68890409/what-is-cucumber-runtime-cucumberexception-arity-mismatch-step-definition-in) – Marit Jun 16 '23 at 09:13

1 Answers1

2

Can you please modify your data table like below and try to execute (there shall be only one pipe line in middle but you have two)

When Enters the userName and password

|userName|password|
|test|test12|
TheSociety
  • 1,936
  • 2
  • 8
  • 20