title: TestNG: Iterate through array using the Dataprovider
body: <p>I'm conducting Automation testing using Selenium Webdriver,  this code is for TestNg <code>dataprovider</code>, Summary:  I am taking data from Excel sheet to data,
  it's working fine.   When I'm debugging the code, I'm getting TestData as <code>testGoogle1(String search1, String Search2)</code>  for 1st Iteration it <code>Search1 = Webdriver, Search2 = Qtp, so on,,,,</code>
  What I want is that it should directly return the array of values something like <code>testGoogle1(String search[])</code> so that in the <code>@Test</code> itself I can add my function iterate all the rows and columns and test them.</p>
  
  <p>Can anyone please give me the idea how to write it.</p>
  
  <p>Test Data sheet</p>
  
  <p><img src="https://i.stack.imgur.com/nrHpW.jpg" alt="Test Data "></p>
  
  <p>here is my code</p>
  
  <pre><code>package ExcelTest;
  import com.thoughtworks.selenium.*;
  import static org.testng.AssertJUnit.*;
  import java.io.IOException;
  import jxl.Cell;
  import jxl.CellType;
  import jxl.Sheet;
  import jxl.Workbook;
  import jxl.read.biff.BiffException;
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.testng.annotations.AfterClass;
  import org.testng.annotations.BeforeTest;   
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;   
  import org.testng.annotations.AfterTest;
  import java.io.File;
  import java.io.FileInputStream;
  import java.util.Iterator;
  import jxl.*;
  
  
  public class Sample{
  
        WebDriver driver;
  
          @BeforeTest
          public void startTest(){
              driver = Startup.basic();
          } 
  
  
  @DataProvider(name = "DP1")
  public Object[][] createData1() throws Exception{
       Object[][] retObjArr=getTableArray("G:\\Selenium Jar Files\\TestData\\Data.xls","DataPool");
      return(retObjArr);
  
  }
  
  @Test (dataProvider = "DP1")
  public void testGoogle1(String search1, String Search2) throws Exception{
  //selenium.open("http://www.google.co.in/");
  //  driver.get("http://www.google.co.in/");
  
      //String hello = search.length;
  //for(int i=0; i&lt; search.length ;i++)
  //{
  System.out.println("param   " +search);
  Thread.sleep(3000);
  System.out.println("Opened");
  WebElement element = driver.findElement(By.name("q"));
  element.sendKeys(search);
  element.submit();
  System.out.println("Clicked");
  }
  //}
  
  @AfterClass
  public void tearDown() throws Exception {
  //selenium.stop();
  }
  
  
  public String[][] getTableArray(String xlFilePath,String sheetName) throws Exception{
  
      String[][] tabArray=null;
  
  
        File inputWorkbook = new File(xlFilePath);
          Workbook w;
          int startRow,startCol, endRow, endCol,ci,cj;
          try {
              //w = Workbook.
              w = Workbook.getWorkbook(inputWorkbook);
              // Get the first sheet
              Sheet sheet = w.getSheet(sheetName);
              // Loop over first 10 column and lines
              endRow = sheet.getRows();
              endCol = sheet.getColumns();
              tabArray=new String[endRow-1][endCol-1];
  
              ci=0;
  
              for (int i=1;i&lt;endRow;i++,ci++){
                  cj=0;
                  for (int j=1;j&lt;endCol;j++,cj++){
  
                    Cell cell = sheet.getCell(j, i);
                  tabArray[ci][cj] = cell.getContents(); 
  
                  }
              //    System.out.println("");
              }
              //file.close();
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
  
  
  
         return(tabArray);
      }
  
  }
  </code></pre>
  
  <p>Can anyone please share any idea ?
  Thanks</p>
  
  <p>Edited Code: </p>
  
  <pre><code>public class Sample{
  
        WebDriver driver;
  
          @BeforeTest
          public void startTest(){
              driver = Startup.basic();
          } 
  
  
  @DataProvider(name = "DP1")
  public Object[][][] createData1() throws Exception{
       Object[][][] retObjArr=getTableArray("G:\\Selenium Jar Files\\TestData\\Data.xls","DataPool");
      return (retObjArr);
  
  }
  
  @Test (dataProvider = "DP1")
  public void testGoogle1(String search, String het) throws Exception{
  
  System.out.println("param   " +search);
  Thread.sleep(3000);
  System.out.println("Opened");
  WebElement element = driver.findElement(By.name("q"));
  element.sendKeys(search);
  element.submit();
  System.out.println("Clicked");
  }
  //}
  
  @AfterClass
  public void tearDown() throws Exception {
  //selenium.stop();
  }
  
  
  public Object[][][] getTableArray(String xlFilePath,String sheetName) throws Exception{
  
      Object[][] tabArray=null;
  
  
        File inputWorkbook = new File(xlFilePath);
          Workbook w;
          int startRow,startCol, endRow, endCol,ci,cj,ck;
          try {
              //w = Workbook.
              w = Workbook.getWorkbook(inputWorkbook);
              // Get the first sheet
              Sheet sheet = w.getSheet(sheetName);
              // Loop over first 10 column and lines
              endRow = sheet.getRows();
              endCol = sheet.getColumns();
              tabArray=new String[endRow-1][endCol-1];
  
              ci=0;
  
              for (int i=1;i&lt;endRow;i++,ci++){
                  cj=0;
  
                  for (int j=1;j&lt;endCol;j++,cj++){
  
                    Cell cell = sheet.getCell(j, i);
                  tabArray[ci][cj] = cell.getContents(); 
  
                  }
              //    System.out.println("");
              }
              //file.close();
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
  
  
  
         return(tabArray);  /// Here Getting the error **Type mismatch: cannot convert from Object[][] to Object[][][]**
      }
  
  }
  </code></pre>