I'm using Selenium 2 and have set up a LoginTest.java file that reads from a data driven excel file. I read in username and password and run it on a login page. It actually runs fine. The data looks like the following:
user1 pw1
user2 pw2
user3 pw3
user4 pw4
The problem is this: if I modify the excel file and change the number of arguments to something like this:
user1 pw1
user2 pw2
and run the same script, the ReadExcel class file returns an error msg:
"There is no support for this type of cell".
What is happening I think, is that rows 3 and 4 used to contain data in their cells (user3 pw3 and user4 pw4) and now they don't...so there is something different about those previously used cells that my ExcelRead() class isn't catching to ignore. I'll bet the cell is now 'null' where it previously wasn't or vice versa. Something is different about the cells which previously held data vs cells that have never held data.
(I found ExcelRead on the internet and am using it. I didn't create it from scratch myself. It seems to work fine reading xcel files except for this one 'issue').
Thanks for any help.
public class ExcelRead {
public Object[][] main( String[] args) throws Exception{
File excel = new File(args[0]);
FileInputStream fis = new FileInputStream(excel);
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet ws = wb.getSheet(args[1]);
int rowNum = ws.getLastRowNum() + 1;
int colNum = ws.getRow(0).getLastCellNum();
String[][] data = new String[rowNum][colNum];
for (int i = 0 ; i < rowNum ; i++) {
HSSFRow row = ws.getRow(i);
for (int j = 0 ; j < colNum ; j++) {
HSSFCell cell = row.getCell(j);
String value = cellToString(cell);
data[i][j] = value ;
//System.out.println("the value is " + value);
}
}
return data;
}
public static String cellToString(HSSFCell cell) {
int type;
Object result;
type = cell.getCellType();
switch (type) {
case 0: // numeric value in Excel
result = cell.getNumericCellValue();
break;
case 1: // String Value in Excel
result = cell.getStringCellValue();
break;
default:
throw new RuntimeException("There is no support for this type of cell");
}
return result.toString();
}