The line marked in star is giving error when the test is run in TestNG
Guys tell me what am I doing wrong in this.
I have attached the excel with 3 rows and 3 columns in 1st sheet.

Data lib code-

package Datalibrery;

import java.io.File;
import java.io.FileInputStream;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

   public class Dataconfig {

      XSSFWorkbook WB;
      XSSFSheet sheet1;

    public Dataconfig(String Excelpath){

    try {
        File src=new File(Excelpath);

        FileInputStream fis=new FileInputStream(src);

        WB=new XSSFWorkbook(fis);

    } catch (Exception e) {
        // TODO Auto-generated catch block


public String getData(int  sheetno,int row,int col){


    **String data=sheet1.getRow(row).getCell(col).getStringCellValue();**

    return data;

public int getRowCount(int sheetindex){

    int row=WB.getSheetAt(sheetindex).getLastRowNum();
    return row;


Script Code-

  package SampleTest;

  import java.util.concurrent.TimeUnit;

  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.testng.annotations.BeforeTest;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;

  import Datalibrery.Dataconfig;

    public class ContactusDDT {

       WebDriver driver;


      public void beforeTest() {

      // If the browser is Firefox, then do this

          driver = new FirefoxDriver();

      // Doesn't the browser type, lauch the Website

      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

public void login(){

    driver.get("Websit URL here");
    driver.findElement(By.xpath("//*[@id='u157-4']/p")).click();// contact

@Test(dataProvider = "Contactdata")
  public void testLogIn(String Harshal1, String harshalb ,String Hi) throws Exception {



@DataProvider(name = "Contactdata")
public Object[][] Testdata()

    Dataconfig conf=new Dataconfig("C:\\Users\\harshadab\\workspace\\Sampledatadiven\\excelData\\Managemygrp.xlsx");
    int rows=conf.getRowCount(0);

    Object[][] data = new Object[rows][3];

    for(int i=0;i<rows;i++)
        ***data[i][0]=conf.getData(1, i, 0);***
        data[i][1]=conf.getData(1, i, 1);
        data[i][2]=conf.getData(1, i, 2);


    return data;


  • 1
    Harsha- It would be better if you- provide the error/exception stack trace in the post. Jan 14, 2016 at 7:28
  • Could you edit in some information about the getData method? Siraj has a potential solution for you, but it would be better to validate that against the parameters he's changing.
    – corsiKa
    Jan 18, 2016 at 17:08

1 Answer 1


In excel sheet always start with 0-column and 0-row and index 0 as well.


 data[i][0]=conf.getData(1, i, 0); 
 data[i][1]=conf.getData(1, i, 1);
 data[i][2]=conf.getData(1, i, 2);


 data[i][0]=conf.getData(0, i, 0);
 data[i][1]=conf.getData(0, i, 1);
 data[i][2]=conf.getData(0, i, 2);
  • Could you add some explanation for the change? When someone comes to this questions later, they'll want to know why it's necessary to change the values as you've suggested.
    – Kate Paulk
    Jan 18, 2016 at 12:52
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. - From Review
    – Kate Paulk
    Jan 18, 2016 at 12:52
  • @KatePaulk Given siraj's edit, I think this is a valid answer now. (Even if not correct... the two are different...) Would you agree?
    – corsiKa
    Jan 18, 2016 at 17:04
  • @siraj It still could be more clear now, though. Are you suggesting that the sheet be zero indexed as well?
    – corsiKa
    Jan 18, 2016 at 17:07
  • I'd agree it's a valid answer now although I would like to see more explanation.
    – Kate Paulk
    Jan 18, 2016 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.