I have a .xlsx file with 6 rows and 3 columns. I need to run my test three times with different data.
@DataProvider(name ="excel-data")
public Object[][] excelDP() throws IOException{
Object[][] arrObj = getExcelData("C:\\Users\\atugusov\\atugusov-aut06\\fwk\\java\\src\\test\\resources\\TestData.xlsx","sheet1");
return arrObj;}
public String[][] getExcelData(String fileName, String sheetName){
String[][] data = null;
try
{
FileInputStream fis = new FileInputStream(fileName);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sh = wb.getSheet(sheetName);
XSSFRow row = sh.getRow(0);
int noOfRows = sh.getPhysicalNumberOfRows();
int noOfCols = row.getLastCellNum();
Cell cell;
data = new String[noOfRows-1][noOfCols];
for(int i =1; i<noOfRows;i++){
for(int j=0;j<noOfCols;j++){
row = sh.getRow(i);
cell= row.getCell(j);
data[i-1][j] = cell.getStringCellValue();
}
}
}
catch (Exception e) {
System.out.println("The exception is: " +e.getMessage());
}
return data;
}
There is my data provider code.
@Test(dataProvider = "excel-data")
public void testgf(String name, String fname, String lname, String password, String confirmPassword, String role){
registrationPage.registration(name,fname,lname,password,confirmPassword,role);
headerPage.logout();
loginPage.openRegistrationPage();
}
I run my test, it goes one circle and displays a message that it completed successfully. I need some advice what to do to fix it.
Aucun commentaire:
Enregistrer un commentaire