【问题标题】:cucumber.runtime.CucumberException: Arity mismatch: Step Definitioncucumber.runtime.CucumberException:Arity 不匹配:步骤定义
【发布时间】:2019-03-31 15:10:13
【问题描述】:

由于步骤定义的 Arity 不匹配错误,我会使用 map 发送测试数据,

下面是我的功能文件,步骤定义和跑步者类

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 {

}

得到一个错误:

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 [ ^输入用户名和密码$] 用 1 个参数声明。但是,小黄瓜步骤有 0 个参数 []。

我无法解决上述错误,请帮助我解决上述错误。

谢谢

【问题讨论】:

    标签: java cucumber


    【解决方案1】:

    你能不能像下面这样修改你的数据表并尝试执行(中间应该只有一条管道,但你有两条)

    当输入用户名和密码时

    |userName|password|
    |test|test12|
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-26
      • 2014-09-26
      • 1970-01-01
      • 2018-06-20
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      相关资源
      最近更新 更多