功能:测试登录功能
方案概述:测试登录功能 给定用户打开浏览器并导航 然后用户输入和 然后点击登录按钮 然后,用户导航到FB主页
Examples:
| username | | password |
| asd | | 123 |
错误 给定用户打开浏览器并浏览#stepDef.Testlogin.user_open_the_browser_and_navigated() 然后,用户输入asd和123#stepDef.Testlogin.user_enter_username_and_password(java.lang.String,java.lang.String) io.cucumber.core.exception.CucumberException:步骤[用户输入(。)和(。)]在'stepDef.Testlogin.user_enter_username_and_password(java.lang.String,java。 lang.String)'。 但是,小黄瓜步骤具有0个参数。 步骤文字:用户输入asd和123
Runner类文件。
公共类Testlogin { 静态WebDriver驱动程序;
@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() {
}
答案 0 :(得分:0)
您在Scenario Outlie
和Examples
中使用了 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 |
,但是您没有通过相同的Cucumber步骤,但是您已经为它写了参数。
你的嫩黄瓜应该像。
@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() {
}
步骤定义应该类似。
A1