webdriver 的CSV数据驱动
1.获取CSV数据内容
public static Object[][] getFromCSV(String filename) {
if (!(new
File(filename)).exists()){
return
null;
}
Object[][]
content;
CSVReader reader;
try
{
reader = new CSVReader(new
FileReader(filename));
Vector<String[]> vec =
new Vector<String[]>();
String[]
nextLine;
reader.readNext(); //skip
title
while ((nextLine = reader.readNext()) != null)
{
vec.add(nextLine);
}
content = new
Object[vec.size()][];
for (int i = 0; i <
vec.size(); i++){
content[i] =
vec.get(i);
}
return
content;
} catch (Exception e)
{
System.out.println("Read CSV File:" + filename +
"failed.");
e.printStackTrace();
}
return null;
}
2.定义数据驱动
String file = "src/test/java/data/page/TaxIssueAnswerTest.csv";
@DataProvider(name="CsvDataProvider")
public Object[][]
inputData(){
return getFromCSV(file);
}
3.使用数据驱动
@Test(dataProvider = "CsvDataProvider",description
="正常业务场景测试")
public void answerIssue(String caseId, String
description,String userName, String pwd){
//执行用例
}
4.图例文件路径