Hi,
I am trying to parameterize my form which has 4 fields and I am trying to parametrize it through excel. I am using data provider with testng. But the problem is that my last value is returning as NULL..
Code is below:
@Test(dataProvider="CreateUsers", priority=4)
public void addNewUsers(String userid, String fname, String lname, String email)
{
System.out.println("Hello Parameterization");
/* driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.findElement(By.xpath("html/body/div[3]/div[2]/div/div/div/p/a")).click();
driver.findElement(By.id("userAccount_Email")).sendKeys(userid);
driver.findElement(By.id("userAccount_FName")).sendKeys(fname);
driver.findElement(By.id("userAccount_LName")).sendKeys(lname);
driver.findElement(By.id("userAccount_EmailContact")).sendKeys(email);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.findElement(By.id("CreateUserBtn")).click();*/
//String s=new String()
}
@DataProvider(name="CreateUsers")
public Object[][] getDataFromExcel() throws IOException
{
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
FileInputStream fis=new FileInputStream("E:\\Selenium Project\\JavaDemo\\Data Set\\Add_User_Sheet.xlsx");
XSSFWorkbook wb= new XSSFWorkbook(fis);
XSSFSheet ws= wb.getSheet("Add_User");
int rows=ws.getPhysicalNumberOfRows();
int col=ws.getRow(0).getLastCellNum();
System.out.println("rows "+rows +"col "+col);
/*System.out.println("get10 "+ws.getRow(1).getCell(0).getStringCellValue());
System.out.println("get11 "+ws.getRow(1).getCell(1).getStringCellValue());
*/
Object[][] data=new Object[rows][col];
System.out.println("Hello before for loop");
for(int i=1; i<rows+1; i++)
{
data[i-1][0]=ws.getRow(i).getCell(0).getStringCellValue().toString();
data[i-1][1]=ws.getRow(i).getCell(1).getStringCellValue().toString();
data[i-1][2]=ws.getRow(i).getCell(2).getStringCellValue().toString();
data[i-1][3]=ws.getRow(i).getCell(3).getStringCellValue().toString();
// data[i][4]=ws.getRow(i).getCell(4).getStringCellValue();
}
/*for(int i=1;i<rows;i++)
{
for(int j=0;j<col;j++)
{
try
{
System.out.print(data[i][j] +"\t");
}
catch(Exception e)
{
System.out.println("excepsion found");
}
}
System.out.println();
}*/
System.out.println("Hello Excel");
wb.close();
return data;
}
OUTPUT: