I have an Excel sheet with data as below
LoginPageValidation|
LoginPage_login | username1 | password1
LoginPage_login | username2 | password2
LoginPage_login | username3 | password3
I am returning "array of arrays" to @Dataprovider
form class reading ExcelSheet(Excelutility.java)
Is there any way to write @DataProvider
which handles nullpointerException while reading data from rows with single column data.
public static Object[][] getTableArray() throws Exception
{
String[][] tabArray = null;
try {
FileInputStream ExcelFile = new FileInputStream(FilePath);
// Access the required test data sheet
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
int startRow = 0;
int totalRows = ExcelWSheet.getLastRowNum()-ExcelWSheet.getFirstRowNum()+1;
System.out.print("\nTOTAL ROWS "+totalRows+"\n");
String a[][]=new String[totalRows][];
for(int i=0;i<totalRows;i++)
{
int ColnumForRow=ExcelWSheet.getRow(i).getLastCellNum();
a[i]=new String [ColnumForRow];
for (int j=0;j<ExcelWSheet.getRow(i).getLastCellNum();j++)
{
if(getCellData(i,j).isEmpty())
{System.out.println("\nEMPTY \n");}
else
{ a[i][j]=getCellData(i,j);
System.out.println("\nTABLE ARRAY : "+ a[i][j]);
}}
}}
return(tabArray);
}
public static String getCellData(int RowNum, int ColNum) throws Exception
{try{
Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
int dataType = Cell.getCellType();
String CellData = Cell.getStringCellValue();
return CellData;
}
}
}
/testClass/
public class test1 { @Test(dataProvider="access") public void AADLoginLogoutTest(String test,String username,String pwd) throws IOException { System.out.println("CLAASS name AADLOGINLOGOUT"+this.getClass().getSimpleName()); } @DataProvider public Object[][] access() throws Exception { Object[][] testObjArray = ExcelUtils.getTableArray(); return (testObjArray); } }