Java 无法使用selenium BDD框架运行登录测试
功能:测试登录功能 场景概要:测试登录功能 给定用户打开浏览器并进行导航 然后用户输入 然后单击登录按钮 然后用户导航到FB主页Java 无法使用selenium BDD框架运行登录测试,java,selenium,cucumber,bdd,Java,Selenium,Cucumber,Bdd,功能:测试登录功能 场景概要:测试登录功能 给定用户打开浏览器并进行导航 然后用户输入 然后单击登录按钮 然后用户导航到FB主页 Examples: | username | | password | | asd | | 123 | 错误 给定用户打开浏览器并导航#stepDef.Testlogin.User_打开_浏览器并导航() 然后用户输入asd和123#stepDef.Testlogin。用户输入#用户名#和#密码(java.lang.String、j
Examples:
| username | | password |
| asd | | 123 |
错误
给定用户打开浏览器并导航#stepDef.Testlogin.User_打开_浏览器并导航()
然后用户输入asd和123#stepDef.Testlogin。用户输入#用户名#和#密码(java.lang.String、java.lang.String)
io.cucumber.core.exception.CucumberException:Step[用户输入(.)和(.)]在“stepDef.Testlogin.User_输入用户名和密码(java.lang.String,java.lang.String)”处定义了两个参数。
但是,小黄瓜步骤有0个参数。
步骤文本:用户输入asd和123
运行程序类文件
公共类Testlogin{
静态网络驱动程序
@Given("User open the Browser and navigated")
public void user_open_the_browser_and_navigated() throws IOException {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
driver =new ChromeDriver(options);
driver.get("http://www.facebook.com");
}
@Then("User enter (.*) and (.*)")
public void user_enter_username_and_password (String username,String password) {
System.out.println("The cell value is: "+username);
driver.findElement(By.id("email")).sendKeys(username);
//System.out.println("The cell value is: "+password);
driver.findElement(By.id("pass")).sendKeys(password);
}
@Then("Click the login button")
public void click_the_login_button() {
driver.findElement(By.name("login")).click();
driver.manage().window().maximize();
}
@Then("User navigated to FB home page")
public void user_navigated_to_fb_home_page() {
}
在这里,您使用了
场景大纲
和示例
,但是您没有通过相同的cucumber步骤,但是您已经为相同的步骤编写了参数
你这个小黄瓜应该是这样的
Scenario Outline: Test login function
Given User open the Browser and navigated
When User enter "<username>" and "<password>"
And Click the login button
Then User navigated to FB home page
Examples:
| username | | password |
| asd | | 123 |
@Given("User open the Browser and navigated")
public void user_open_the_browser_and_navigated() throws IOException {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
driver =new ChromeDriver(options);
driver.get("http://www.facebook.com");
}
@When("User enter (.*) and (.*)")
public void user_enter_and(String username,String password) {
System.out.println("The cell value is: "+username);
driver.findElement(By.id("email")).sendKeys(username);
//System.out.println("The cell value is: "+password);
driver.findElement(By.id("pass")).sendKeys(password);
}
@And("Click the login button")
public void click_the_login_button() {
driver.findElement(By.name("login")).click();
driver.manage().window().maximize();
}
@Then("User navigated to FB home page")
public void user_navigated_to_fb_home_page() {
}
先生,我已经像您上面提到的那样传递了参数,但是当我复制粘贴步骤时,它被重新格式化了。这里的问题是步骤2有一个错误,即:io.cumber.core.exception.cumberexception:Step[User enter(.*)和(.*)是在'stepDef.Testlogin.User_enter_username_和_password(java.lang.String,java.lang.String)处用两个参数定义的“。但是,小黄瓜步骤有0个参数。步骤定义的代码已更新。当用户输入”“和”“时,请立即检查步骤
。问题是我忘记在步骤定义文件中添加^和$符号。