image.png
- DataProvider 配合使用CSV做批量數(shù)據(jù)參數(shù)化
通過@DataProvider(name=""數(shù)據(jù)集名稱) 注解方法提供數(shù)據(jù);
通過 @Test(dataProvider="數(shù)據(jù)集名稱關(guān)聯(lián)配對").
//@Test()執(zhí)行的時候傳參 這里的dataProvider目的是提供關(guān)聯(lián)
@Test(dataProvider = "value")
//通過 @Test(dataProvider="數(shù)據(jù)集名稱關(guān)聯(lián)配對")
public void query(String realName,String username,String password) {
driver.get("http://47.98.226.232:8080/guoya-medium/jsp/user/login.jsp");
driver.findElement(By.xpath("http://input[@name='userName']")).sendKeys(username);
driver.findElement(By.xpath("http://input[@name='password']")).sendKeys(password);
driver.findElement(By.xpath("http://input[@id='checkCode']")).sendKeys("1234");
driver.findElement(By.xpath("http://input[@id='loginBtn']")).click();
driver.findElement(By.name("realName")).sendKeys(realName);
driver.findElement(By.xpath("http://input[@value='查詢']")).click();
}
//提供數(shù)據(jù)的
@DataProvider(name = "value")
//通過@DataProvider(name=""數(shù)據(jù)集名稱) 注解方法提供數(shù)據(jù)
//方法名前面的是返回的數(shù)據(jù)類型
public static Object[][] getCsv() {
// 提供數(shù)據(jù) 一種讀取CSV文件 返回 二維數(shù)組
//讀取二維數(shù)組保存至data數(shù)組變量中 相對路徑從src開始
Object[][] result = readCSV("src/main/resources/csvData/queryrealname.csv");
return result;
//另一種直接寫二維數(shù)組返回
// return CSVReader.readCSV("src/main/resources/csvData/queryuser.csv");