TestNG with multiple datadriven



  • My code structure logic is this: I have to fill three sequential forms to add a entry in a list whose data is from Excel. I need each form to have entries from different Excel sheet, i.e first form's data from first Excel sheet, second form's data from second sheet, and third from third sheet. How can I work this using simple logic on datadriven framework along with testNG annotations?



  • You can indicate the file names in the Data Provider

    @DataProvider(name = "formFillingData")
    public static Object[][] formFillingData() {
       return new Object[][] {
          { "form1_1.xls", "form2_1.xls", "form3_1.xls" },
          { "form1_2.xls", "form2_2.xls", "form3_2.xls" },
       };
    }
    

    And in the test you can get each set of three files, feeding a factory that creates the objects which represent your data:

    @Test(dataProvider = "formFillingData", dataProviderClass = FormFillingData.class)
    public void FormFillingTest(String form1, String form2, String form3) {
      FormData formData1 = DataFactory.createFormData(form1);
      fillFirstForm(formData1);
      FormData formData2 = DataFactory.createFormData(form2);
      fillSecondForm(formData2);
      FormData formData3 = DataFactory.createFormData(form3);
      fillThirdForm(formData3);
    
      addEntryInList();
    }
    

    This will run the @TestMethod for the first row on the data provider, after that the second row, and so on...



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2