0
我已经创建了一个读取一个包中的excel值的类,并且还有一个类以testng的形式检查了不同类中的登录。 我的ReadExcelFile.java是 包uat;如何给testng.xml中的路径赋予动态值
public class ReadExcelFile extends BeforeAfterSuite{
@Test
@Parameters("filename")
public void readXLSXFile(String fileName) {
InputStream XlsxFileToRead = null;
XSSFWorkbook workbook = null;
try {
XlsxFileToRead = new FileInputStream(fileName);
//Getting the workbook instance for xlsx file
workbook = new XSSFWorkbook(XlsxFileToRead);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//getting the first sheet from the workbook using sheet name.
// We can also pass the index of the sheet which starts from '0'.
XSSFSheet sheet = workbook.getSheet("Sheet1");
XSSFRow row;
XSSFCell cell;
//Iterating all the rows in the sheet
Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
row = (XSSFRow) rows.next();
//Iterating all the cells of the current row
Iterator cells = row.cellIterator();
while (cells.hasNext()) {
cell = (XSSFCell) cells.next();
if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
System.out.print(cell.getStringCellValue() + " ");
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
System.out.print(cell.getNumericCellValue() + " ");
} else if (cell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
System.out.print(cell.getBooleanCellValue() + " ");
}
}
System.out.println();
try {
XlsxFileToRead.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
和TestNG中我要传递的参数作为文件名与路径一起,但被硬编码,而不是我想送动态值 因为位置我打算以后此举是共享的路径。