我试图使用getExcelData函数从excel文件中获取测试数据,该函数收集ArrayList对象中的数据,并在执行代码的testclass中的下面。
下面是我的代码:
public class roughTest {
public WebDriver driver;
@BeforeMethod
public void setUp() {
System.setProperty("webdriver.chrome.driver", "D:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("TEST URL LINK");
}
@Test(dataProvider="getData")
public void form(String firstname,String lastname,String date,String continent) {
driver.findElement(By.name("firstname")).clear();
driver.findElement(By.name("firstname")).sendKeys(firstname);
driver.findElement(By.name("lastname")).clear();
driver.findElement(By.name("lastname")).sendKeys(lastname);
driver.findElement(By.xpath("(.//input[@type='text'])[4]")).clear();
driver.findElement(By.xpath("(.//input[@type='text'])[4]")).sendKeys(date);
Select s = new Select(driver.findElement(By.name("continents")));
s.selectByVisibleText(continent);
System.out.println("Value entered successfully");
}
@DataProvider
public Iterator<Object[]> getData() {
ArrayList<Object[]> testData = getDataFromExcel.getExcelData();
return testData.iterator();
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}