title: Run Multiple test cases with multiple test data sheet
body: <p>I need help in selenium. I am trying to run multiple test cases with multiple test data sheets with TestNG and Data Provider concept. But I am having issue in running the test data. If I return array in Test, after getting the test data from sheet then starting from the one row of test cases again so it always run 1st row of the Data driven function.</p>
  
  <p>If I return at the end of the DataDriven then last row will print the value in Test rest would get overnight.</p>
  
  <p>Please let me know what I have to do to run the my test cases. I am attaching the code and Test cases and Test data sheet.</p>
  
  <p><a href="http://i.stack.imgur.com/gZDz6.png" rel="nofollow">Test Cases &amp; test data sheet</a></p>
  
  <pre class="lang-java prettyprint-override"><code>package testCases;
  
  import java.util.Properties;
  import operation.ReadObject;
  import operation.UIOperation;
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.ss.usermodel.Sheet;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.testng.annotations.AfterSuite;
  import org.testng.annotations.BeforeSuite;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.lang.reflect.Method;
  import excelExportAndFileIO.ReadExcelFile;
  
  public class Test1 {
      private static final Boolean True = null;
  
      //WebDriver webdriver = null;
      public static WebDriver driver;
  
      private Cell Cell;
      private Cell TCCellValue;
  
      /*  @BeforeSuite
      public static void firefoxSetUp() {
          driver = new FirefoxDriver();
          driver.manage().window().maximize();
      }
  
      @AfterSuite
      public static void closeFirefox(){
         driver.quit();
      }*/
  
      @Test(dataProvider = "hybridData")
      public void Permittee_Registration(String Status, String TC, String Module1, String Module2 )   {               //String Status, String TCName, String TCDesc) throws Exception {
          System.out.println("Status:"+Status +" ; TC:"+TC + " ; Module1:"+Module1 + " ; Module2:"+Module2);
      }
  
      // Call the test data sheet ----- PR = Permittee Registration
      @Test(dataProvider = "hybridData")
      public void PR_Applicant_Information(String TestCase, String URL, String objPermittee, String objPR, String PR_TITLE, String objLegal_Entity_Type, String Permittee_Legal_Name, String EIN  )   {
          System.out.println("PR_Applicant_Information Test");
          if (TestCase!=null){
              System.out.println("");
              System.out.println("TestCase:"+TestCase + " ; PR_Applicant_Information URL:"+URL + " ; objPermittee: "+objPermittee + " ; objPR: " +objPR  + " ; PR_TITLE: " +PR_TITLE + " ; objLegal_Entity_Type: " +objLegal_Entity_Type + " ; Permittee_Legal_Name: " + " ; EIN: " +EIN + "; dd: dd") ;
          }
  
      }
      @Test(dataProvider = "hybridData")
      public void PR_Choose_Qualification(String TC, String URL){
          if (TC!=null){
              System.out.println("");
              System.out.println("PR_Choose_Qualification TC:"+TC + " ; URL: "+ URL);
          }
      }
  
      @DataProvider(name = "hybridData")
      public Iterator[] loginData(Method method) {
          //System.out.println("Hybrid");
          String TCName="";
          Object[][] result = null;
          Object[][] testData = new String[10][10];
  
          Object[][] arrayObject = getExcelData(("user.dir") + "\\TestCaseSheet.xlsx", "TestCases_Modules",TCName);
  
          //K=Row and L=Column
          for (int k=0; k &lt; arrayObject.length; k++){
              int colCount=arrayObject[k].length;
              //System.out.println("Column=arrayObject[k].length:"+arrayObject[k].length);
              if ("YES".equals(arrayObject[k][0])){
                  //System.out.println("arrayObject[k][L]:"+arrayObject[k][L]+" ; K="+k+" ; L="+L);
                  //System.out.println("arrayObject[k][0]----:"+arrayObject[k][0] +" ; K = "+k );
                  for (int L=0; L&lt; colCount ; L++){                   
                      //"Permittee_Registration"                          
                      //System.out.println("Permittee_Registration"+arrayObject[k][2]);
                      if ((arrayObject[k][L] !=null) &amp;&amp; ((String)arrayObject[k][L]).indexOf(",") &gt; 0) {
                          String[] pr = ((String)arrayObject[k][L] ).split(",");
                          //System.out.println("pr:"+pr.length + " ; PRValue:"+pr[0]);
                          for (int prN=0; prN &lt; pr.length; prN++ ){
                              //System.out.println("for (int prN=0; prN &lt; pr.length; prN++ )");
                              //pr=Applicant_Information
                              TCName=(String) arrayObject[k][1];  //fetching the Test Case Name
                              //System.out.println("TCName:"+TCName + " ; equals(pr[prN]) = "+equals(pr[prN]) + " ; pr.length="+pr.length + " ; pr[prN]="+ pr[prN]);
                              if ("Applicant_Information".equals(pr[prN])){                               
                                  System.out.println("if (Applicant_Information.equals(pr[prN]))"+pr[prN] + " ;  pr.length="+pr.length );
                                  if (method.getName().equals("PR_Applicant_Information")) {
                                      System.out.println("Applicant_Information Moni before calling excel sheet function:"+" ; result.length"+result.length);
                                      //result = getExcelData(("user.dir") + "\\TestCaseSheet.xlsx", "Applicant_Information",TCName);
                                      result = getExcelData(("user.dir") + "\\TestCaseSheet.xlsx", pr[prN] ,TCName);
                                      //AI(result);
                                      //System.out.println("Applicant_Information Moni afte calling excel sheet function:"+" ; result.length"+result.length);
                                      //return result;
                                  };
                              }
                              else if ("Choose_Qualification".equals(pr[prN])){
                                  if (method.getName().equals("PR_Choose_Qualification")) {
                                      //System.out.println("Choose_Qualification Moni before calling excel sheet function:"+pr[prN] +" ; result.length"+result.length);
                                      result = getExcelData(("user.dir") + "\\TestCaseSheet.xlsx", "Choose_Qualification",TCName);
                                      System.out.println("Choose_Qualification Moni after calling excel sheet function:"+pr[prN] +" ; result.length"+result.length);
  
                                  };
                              }                           
                          }
                          //return result;
                      }                   
                  }
              }
          }           
          return result;
  
      }
  public void AI(Object result){
      System.out.println("resultAI:"+result);
  }
      /**
       * @param File
       *            Name
       * @param Sheet
       *            Name
       * @return
       */
      public String[][] getExcelData(String fileName, String sheetName, String TCName) {
      //public List&lt;String&gt; getExcelData(String fileName, String sheetName, String TCName) {
          String[][] arrayExcelData = null;
          int a=0;
          int b=0;
          try {
  
              ReadExcelFile file = new ReadExcelFile();
  
              // UIOperation operation = new UIOperation(driver);
              // Read keyword sheet
              Sheet testCaseSheet = file.readExcel(System.getProperty("user.dir") + "\\", "TestCaseSheet.xlsx", sheetName);
              // Find number of rows in excel file
              int rowCount = testCaseSheet.getLastRowNum() - testCaseSheet.getFirstRowNum();
              int coulmnCount = testCaseSheet.getRow(0).getLastCellNum();
              int firstCoulmnCount = testCaseSheet.getRow(0).getFirstCellNum();
              arrayExcelData=new String[rowCount+1][coulmnCount];
              //System.out.println("rowCount:"+rowCount);
              //System.out.println("coulmnCount:"+coulmnCount);
              //Looping the row   
  
              for (int i = testCaseSheet.getFirstRowNum(); i &lt; (testCaseSheet.getLastRowNum()+1) ; i++) {
                  // Loop over all the rows               
                  //Row row=testCaseSheet.getRow(i + 1);
                  int j;
                  if ("" != (TCName)){
                      //Object TCCellValues = null;
                  }
                  for (j = firstCoulmnCount; j &lt; coulmnCount ; j++) {
                      Cell = testCaseSheet.getRow(i).getCell(j);
                      //System.out.println("TCName in recurring function :"+TCName);
                      //System.out.println("Cell:"+Cell);
                      //if TCName is equal to particular row then pick only that cell data.
  
                      TCCellValue = testCaseSheet.getRow(i).getCell(0);
                      String TCCellValues = TCCellValue.getStringCellValue();
                      //System.out.println("if ( != (TCCellValue)): " +TCCellValue + " ; TCName=" + TCName + " ; i="+i);                                      
                          String CellData="";
                          //System.out.println("Cell inside:"+Cell);
                          if (Cell!=null){
                              CellData = Cell.getStringCellValue();
                              //System.out.println(i+":"+CellData);
                          }                                           
                          if (TCName.equals("")||(TCName.equals(TCCellValues))){
  
                              arrayExcelData[i][j]=CellData;
                              //System.out.println("arrayExcelData[i][j]=CellData;"+CellData + " ; i="+i +" ; j="+j + " ; TCName="+TCName + " ; a="+a +" ; b="+b );
                          }
                  }                   
              }
  
          } catch (Exception e) {
              System.out.println("Error " + e);           
          }
          //System.out.println("Stop_arrayExcelData:");
          return arrayExcelData;
          //return new List&lt;String&gt;{{arrayExcelData}};
      }
  }
  </code></pre>