【发布时间】:2019-07-16 00:05:12
【问题描述】:
我已经用java在黄瓜中编写了一个功能文件,用于登录操作。 我只想在应用程序启动后多次执行登录操作而不关闭应用程序。
这里是功能文件
Feature: Login Scenario
Scenario Outline: Execute me multiple times
Given I open the application
When I enter `"<username>"` and `"<password>"`
Then I click on Login button
And I close the application
Examples:
| username | password |
| user1 | password1 |
| user2 | password2 |
| user3 | password3 |
| user4 | password4 |
| user5 | password5 |
在这种情况下,每次启动和关闭应用程序时。但是我只想启动和关闭一次并执行多个登录操作。
跑步者类:
import cucumber.api.CucumberOptions;
@CucumberOptions(features="feature",glue= {"steps"})
public class TestRunner {}
和步骤定义:
public class TestMe {
WebDriver driver;
String chrome="webdriver.chrome.driver";
String path="./drivers/chromedriver1.exe";
@Given("^I open the application$")
public void i_open_the_application() throws Throwable {
System.setProperty(chrome, path);
driver=new ChromeDriver();
driver.get("file:///C:/Users/AZ/Desktop/webpages/loginPage.html");
}
@When("^I enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void i_enter_and(String user, String pass) throws Throwable {
driver.findElement(By.id("user")).sendKeys(user);
driver.findElement(By.id("pass")).sendKeys(pass);
}
@Then("^I click on Login button$")
public void i_click_on_Login_button() throws Throwable {
driver.findElement(By.id("btn")).click();
}
@Then("^I close the application$")
public void i_close_the_application() throws Throwable {
driver.close();
}
}
网页 HTML 代码:
<html>
<head>
<title>Login</title>
</head>
<body>
<div align="center">
Username<input type="text" id="user"></br></br>
Password<input type="password" id="pass"></br></br>
<input type="button" value="Login" id="btn">
</div>
</body>
</html>
预期结果:仅启动和关闭一次,登录操作多次。
实际结果:多次启动,登录操作并关闭。
【问题讨论】: