title: Taking Data From Multiple Table using TestNG Data Provider
body: <p>I am Using Selenium RC with TestNG to do some kind of keyword driven testing.For the same purpose i want to read some data from an excel sheet and use it.Here I have used Data Provider annotation of TestNG.but My problem is that i want to read data from multiple tables and use them in a single test method using only one data provider.But I am Getting Problem in it.Can somebody Help me in Doing so.</p>
  
  <p>Thanks</p>
  
  <p>Here Is my Code:</p>
  
  <pre><code>@DataProvider(name = "DP1")
  
  public Object[][] createData1() throws Exception {
  
    return new Object[][] {
  
      {getTableData.getTableArray(" Xls File Path", "Sheet name", "Table1")},
  
      {getTableData.getTableArray(" Xls File Path", "Sheet name", "Table2")}
  
    };
  
  }
  </code></pre>
  
  <p>This Is My Test Method:</p>
  
  <pre><code>@Test (dataProvider = ("DP1"))
  
  public void testallpivot(String Command, String Target, String Value) throws Exception {
  
    //Test Code here
  
  
  }
  </code></pre>
  
  <p>But This Code is Showing Array Index Out of Bound Exception..
  Somebody Please Help me.....</p>
  
  <p>Well this is how getTableArray looks..</p>
  
  <pre><code>public static Object[][] getTableArray(String xlFilePath, String sheetName, String     tableName) throws Exception{
      Object[][] tabArray;
  
          Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
          Sheet sheet = workbook.getSheet(sheetName); 
          int startRow,startCol, endRow, endCol,ci,cj;
          Cell tableStart=sheet.findCell(tableName);
          //System.out.println(tableName);
          startRow=tableStart.getRow();
          startCol=tableStart.getColumn();
  
          Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000,  false);                
  
          endRow=tableEnd.getRow();
          endCol=tableEnd.getColumn();
          System.out.println("startRow="+startRow+", endRow="+endRow+", " +
                  "startCol="+startCol+", endCol="+endCol);
          tabArray=new String[endRow-startRow-1][endCol-startCol-1];
          ci=0;
  
          for (int i=startRow+1;i&lt;endRow;i++,ci++){
              cj=0;
              for (int j=startCol+1;j&lt;endCol;j++,cj++){
                  tabArray[ci][cj]=sheet.getCell(j,i).getContents();
              }
          }
  
  
      return(tabArray);
  }
  </code></pre>
  
  <p>And this is the Stack Trace.....</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 1
  at org.testng.internal.Invoker.injectParameters(Invoker.java:1144)
  at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1020)
  atorg.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:137)
  at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:121)
  at org.testng.TestRunner.runWorkers(TestRunner.java:953)
  at org.testng.TestRunner.privateRun(TestRunner.java:633)
  at org.testng.TestRunner.run(TestRunner.java:505)
  at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
  at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
  at org.testng.SuiteRunner.privateRun(SuiteRunner.java:316)
  at org.testng.SuiteRunner.run(SuiteRunner.java:195)
  at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:903)
  at org.testng.TestNG.runSuitesLocally(TestNG.java:872)
  at org.testng.TestNG.run(TestNG.java:780)
  at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:75)
  at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:127)
  </code></pre>