getting null value in data provider while printing the excel on console provide expected result.

1,148 views
Skip to first unread message

Satya Prakash

unread,
Apr 18, 2016, 2:04:19 PM4/18/16
to webdriver
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:


Auto Generated Inline Image 1

Bill Ross

unread,
Apr 18, 2016, 2:30:38 PM4/18/16
to webd...@googlegroups.com
You don't show the output.

Bill
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at https://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

⇜Krishnan Mahadevan⇝

unread,
Apr 18, 2016, 11:29:27 PM4/18/16
to webdriver
Satya,

It looks like you may perhaps have a blank row as the last row in your .xls file.

Take a look at this link : http://www.techrepublic.com/blog/microsoft-office/a-quick-way-to-delete-blank-rows-in-excel/ to remove the blank row and try again.

All said and done, your query doesnt seem to be related to Selenium/WebDriver and looks more to be a query related to reading .xls using java. Please help keep this forum relevant by posting queries that are related to Selenium/webdriver.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Satya Prakash

unread,
Apr 19, 2016, 4:59:56 AM4/19/16
to webdriver
Hi Bill,

Above is a code snippet. Please do the rest according without modifying the original one.

I am using testng to do parameterization.

Thanks
Satya Prakash Mishra
Reply all
Reply to author
Forward
0 new messages