I am using Cucumber-Selenium and Excel as my Data file, my question is how can I run my feature file multiple time based on the data I have on the Excel. For Example I have 10 rows of data in Excel and wanted to run it one by one, after the first row of data it will move to the next row and execute it.
Feature File:
Scenario: Login
Given I open the browser and access this URL
When I enter the "<Username>" and "<Password>"
Then I am able to login
Step Definition:
public class 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();
}
}
Here is my Data Table(Excel File)
|ID | UserName | Password
|ID1 |username1 |password1
|ID2 | username2 | password2
|ID3 | username3 | password3
|ID4 | username4 | password4
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…