Java cucumber.runtime.CucumberException:算术不匹配:步骤定义
获取一个错误作为步骤定义的算术不匹配错误,我使用map发送测试数据 下面是我的功能文件、步骤定义和runner类Java cucumber.runtime.CucumberException:算术不匹配:步骤定义,java,cucumber,Java,Cucumber,获取一个错误作为步骤定义的算术不匹配错误,我使用map发送测试数据 下面是我的功能文件、步骤定义和runner类 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 log
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 {
}
功能:CRMPRO登录
场景:验证登录功能
给定用户位于CRMPRO登录页面上
当输入用户名和密码时
|用户名| |密码|
|测试| |测试12|
然后点击登录按钮
然后应显示CRMPRO主页
导入java.awt.Robot;
导入java.awt.event.KeyEvent;
导入java.util.List;
导入java.util.Map;
导入org.apache.xpath.Arg;
导入org.junit.Assert;
导入org.openqa.selenium.By;
导入org.openqa.selenium.JavascriptExecutor;
导入org.openqa.selenium.Keys;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.chrome.ChromeDriver;
导入cumber.api.DataTable;
导入cumber.api.PendingException;
导入cucumber.api.java.en.And;
导入cucumber.api.java.en.Given;
导入cumber.api.java.en.Then;
导入cucumber.api.java.en.When;
公共类定义{
网络驱动程序;
字符串搜索关键词;
@给定(“^user位于CRMPRO登录页$”)
public void user_在_CRMPRO_Login_page()上可丢弃{
//在这里编写代码,将上面的短语转化为具体的行动
System.setProperty(“webdriver.chrome.driver”,“F://chromedriver.exe”);
驱动程序=新的ChromeDriver();
driver.manage().window().maximize();
驱动程序。获取(“https://www.crmpro.com");
}
@当(“^输入用户名和密码$”)
public void输入\u用户名和\u密码(DataTable表)抛出Throwable{
//在这里编写代码,将上面的crmpro短语转化为具体内容
//行动
列表s=table.asMaps(String.class,String.class);
driver.findElement(By.name(“用户名”)).sendKeys(s.get(0).get(“用户名”));
driver.findElement(按名称(“密码”)).sendKeys(s.get(0).get(“密码”));
}
@当(“^单击登录按钮$”)
public void cick_on_login_button()抛出可丢弃{
//在这里编写代码,将上面的短语转化为具体的行动
WebElement buttonLogin=driver.findElement(By.xpath(“//input[@type='submit']);
JavascriptExecutor js=(JavascriptExecutor)驱动程序;
js.executeScript(“参数[0]。单击()”,按钮登录);
}
@然后(“^CRMPRO主页应显示$”)
public void crpro_主页应显示()可丢弃{
//在这里编写代码,将上面的短语转化为具体的行动
驱动程序。切换到()框架(“主面板”);
Assert.assertEquals(driver.findelelement(By.xpath(“//div[@id='handle\u CRMBLOG'])).getText(),“CRMPRO新闻”);
}
}
包com.mavenDemo;
导入org.junit.runner.RunWith;
进口cucumber.api.CucumberOptions;
进口cucumber.api.junit.cucumber;
@RunWith(cumber.class)
@黄瓜选项(特征=
“C:/Users/BR/workspace/com.mavenDemo/src/main/java/gmailogin.feature”,
glue={“com.mavenDemo”})
公共类测试运行程序{
}
将错误获取为:
cucumber.runtime.CucumberException:算术不匹配:步骤定义“com.mavenDemo.stepDefinition.在文件:/C:/Users/BR/workspace/com.mavenDemo/target/classes/”中输入用户名和密码($DataTable),模式为[^输入用户名和密码],并用1个参数声明。但是,小黄瓜步骤有0个参数[]
我无法解决上述错误,请帮助我解决上述错误
谢谢请您修改如下数据表并尝试执行(中间只有一条管线,但您有两条)
当输入用户名和密码时
|userName|password|
|test|test12|
请您修改如下数据表并尝试执行(中间只有一条管线,但您有两条)
当输入用户名和密码时
|userName|password|
|test|test12|