我使用黃瓜,硒和Excel作爲我的數據文件Excel文件,我的問題是我怎麼可以運行基於我對Excel中的數據我有文件的多個時間。例如,我在Excel中有10行數據,並希望逐一運行它,在第一行數據移動到下一行並執行它之後。黃瓜硒使用數據表
特性文件: 方案:登錄
Given I open the browser and access this URL
When I enter the "<Username>" and "<Password>"
Then I am able to login
步驟定義: 公共類登錄{
WebDriver driver = null;
String url;
@Given("^I open the browser and access this URL$")
public void navigateToUrl() throws Throwable{
System.setProperty("webdriver.chrome.driver", "");
driver = new ChromeDriver();
url = DataTable.getDataTableValue(0, 2, 2);
driver.get(url);
driver.manage().window().maximize();
}
@When("^I enter the \"([^\"]*)\" and \"([^\"]*)\"$")
public void enterCredentials(String userName, String password) throws Throwable {
userName = DataTable.getDataTableValue(0, 1, 1);
password = DataTable.getDataTableValue(0, 1, 2);
driver.findElement(By.id("username")).sendKeys(userName);
driver.findElement(By.id("password")).sendKeys(password);
}
@Then("^I am able to login$")
public void clickLoginButton() throws Throwable {
driver.findElement(By.id("Login")).click();
}
}
這裏是我的數據表(Excel文件)
| ID | UserName |密碼
| ID1 | username1 | password1
| ID2 | username2 |密碼2
| ID3 | username3 |密碼3
| ID4 | username4 | password4
我也在努力學習硒在這些日子裏。你應該搜索「Apache POI」API。我認爲這將解決您的問題 – limonik
感謝您的迴應。我已經使用Excel作爲數據表,但我不知道如何在Cucumber-Selenium上迭代。 基本上問題是不使用功能文件中的示例表,我想使用Excel,因爲我正在處理數千個數據。 – Sachi
@Sachi我不認爲這是可能的。我不確定你想實現的是數據驅動的方法,還是隻想將數據抽象到不同的excel文件中。如果以後你可以用Apache POI來做到這一點,但首先是不可能的。 –