在步骤定义中获得Arity不匹配错误,我可能会使用地图发送测试数据,
下面是我的特征文件,步骤定义和流道类
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不匹配:步骤定义'com.mavenDemo.StepDefination.enters_the_userName_and_password(DataTable)在文件:/ C:/Users/BR/workspace/com.mavenDemo/target/classes/中,其模式为[ ^输入用户名,并使用1个参数声明密码$]。但是,小黄瓜步骤具有0个自变量[]。
我无法解决以上错误,请帮助我解决以上错误。
谢谢
答案 0 :(得分:1)
能否请您像下面那样修改数据表并尝试执行(中间只有一条管道,但是您有两条)
输入用户名和密码时
E/SQLiteLog: (1) near "TABLEtbRegister": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: pk.edu.vu.agentpawnbroker, PID: 27838
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10826)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10826)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.database.sqlite.SQLiteException: near "TABLEtbRegister": syntax error (code 1): , while compiling: CREATE TABLEtbRegister(IDINTEGER PRIMARY KEY AUTOMATIC,First NameTEXT NOT NULL,Last NameTEXT NOT NULL,Registration DateTEXT NOT NULL,User IDTEXT NOT NULL,PasswordTEXT NOT NULL )
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "TABLEtbRegister": syntax error (code 1): , while compiling: CREATE TABLEtbRegister(IDINTEGER PRIMARY KEY AUTOMATIC,First NameTEXT NOT NULL,Last NameTEXT NOT NULL,Registration DateTEXT NOT NULL,User IDTEXT NOT NULL,PasswordTEXT NOT NULL ))
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1058)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:623)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1812)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1743)
at pk.edu.vu.agentpawnbroker.Database.DBHelper.onCreate(DBHelper.java:37)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at pk.edu.vu.agentpawnbroker.Database.DBHelper.addUser(DBHelper.java:50)
at pk.edu.vu.agentpawnbroker.RegisterActivity.register(RegisterActivity.java:40)
... 12 more