title: DataProvider in TestNG to pass data from excel
body: <p>I started learning Selenium2 (WebDriver) with Eclipse and TestNG. I have a question about DataProvider. I have a login page having user, password and login button for example. I have written a test in TestNG. I have used pageobject for UI objects (have separate class) and actual test in another class.</p>
  
  <p>Here glogin is a class and login is the function where finding elements and sending keys is done and this is called in another class gtest(which is main test) which has TestNG annotations.</p>
  
  <p>I access that class in main script which will take values.</p>
  
  <pre><code>@test(Dataprovide = "test")
  public void glogin(String user, String pass)
  {
    glogin log1 = new login;
    log1.login(user,pass);
  }
  </code></pre>
  
  <p>I have the following excel sheet</p>
  
  <pre><code>user      pass    
  John      Smith      
  Carson    Black    
  Carla     ck23
  test      test4
  </code></pre>
  
  <p>When I use dataprovider and get data from the excel sheet as array and use it in Test then the following error is displayed:</p>
  
  <pre><code>org.testng.TestNGException: 
  
  The data provider is trying to pass 4 parameters but the method plus.gmail#glogin takes 2
      at org.testng.internal.Invoker.injectParameters(Invoker.java:1337)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1225)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
      at org.testng.TestRunner.privateRun(TestRunner.java:767)
      at org.testng.TestRunner.run(TestRunner.java:617)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
      at org.testng.SuiteRunner.run(SuiteRunner.java:240)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
      at org.testng.TestNG.run(TestNG.java:1036)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
  </code></pre>
  
  <p>Any help is really appreciated.</p>
  
  <p>Here is code for method annotated with Dataprovider and </p>
  
  <pre><code>    @DataProvider(name="test")
          public Object[][] createdata1()throws Exception
          {
              Object[][] retobj = getexcel();
              return retobj;              
          }
  
          private String[][] getexcel() throws Exception
          {
              // TODO Auto-generated method stub
  
              String[][] tabarray = null;
              try {
                  Workbook wb1 = Workbook.getWorkbook(new 
  
  File("F:/testdata.xls"));
  
                  Sheet sheet = wb1.getSheet("userlogin");
  
                  Cell tablestart = sheet.findCell("login");
  
                  int startrow = tablestart.getRow();
                  int startcol = tablestart.getColumn();
  
                  Cell tableend = sheet.findCell("login",startcol+1,startrow+1, 
  
  100, 64000, false);
  
                  int endrow = tableend.getRow();
                  int endcol = tableend.getColumn();
  
                  System.out.println("startRow="+startrow+", endRow="+endrow+", 
  
  " + "startCol="+startcol+", endCol="+endcol);
  
                   tabarray = new String[endrow - startrow + 1][endcol - 
  
  startcol + 1];
  
                  int ci = 0;
                  for(int i = startrow +1 ;i&lt;endrow;i++,ci++)
                  {
  
                      int cj = 0;
                      for(int j = startcol + 1;j&lt;endcol;j++,cj++)
                      {
                          tabarray[ci][cj] = sheet.getCell(j, 
  
  i).getContents();
                          System.out.println(tabarray[ci][cj]);
  
                      }   
                  }
  
              } catch (BiffException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              return tabarray;
          }
  
  test(Dataprovider = "test")
  public void glogins(String user, String pass)
  {
    glogin log1 = new glogin(driver);
    log1.login(user,pass);
  }
  </code></pre>
  
  <p>When I executed the test, I received data from excel as </p>
  
  <pre><code>john
  smith
  carson
  Black
  carla
  ck23
  test
  test4
  </code></pre>
  
  <p>as output</p>