---数据提供者类---
public class TestData {
@DataProvider(name = "data")
public static Object[][] getTableArray() throws Exception {
File src = new File("D:/Data/Data.xlsx");
FileInputStream fis = new FileInputStream(src);//getting error for this line
Workbook wb = new XSSFWorkbook(fis);
Sheet sh = wb.getSheet("Credentials");
int rowcount = sh.getLastRowNum();
String[][] cred = getCellData(sh,rowcount);
System.out.println(cred[0][0]);
return cred;
}
public static String[][] getCellData(Sheet sh, int rowcount){
int ri=0,ci=0;
Cell cell=null;
String data[][]=null;
int colcount = 2;
for( ri=0;ri<=rowcount;ri++){
for (ci=0;ci<colcount;ci++){
cell = sh.getRow(ri).getCell(ci);
data[ri][ci]=cell.getStringCellValue();
}
System.out.println(cell);
}
return data;
}
- 访问类----
public class Data {
@Test(dataProvider="data", dataProviderClass = TestData.class )
public void read(String username, String password) {
System.out.println(username);
System.out.println(password);
}
}
这是我的代码我在添加评论的行上收到错误。错误是:java.io.FileNotFoundException:?D:\ Data \ Data.xlsx(文件名,目录名或卷标语法不正确)