gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:03:52 27 4
gpt4 key购买 nike

步骤定义时出现 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 [^Enters the userName and password$] is declared with 1 parameters. However, the gherkin step has 0 arguments [].

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

谢谢

最佳答案

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

何时输入用户名和密码

|userName|password|
|test|test12|

关于java - cucumber .runtime.CucumberException : Arity mismatch: Step Definition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55442304/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com