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?

1 Answer 1


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);
  FormData formData2 = DataFactory.createFormData(form2);
  FormData formData3 = DataFactory.createFormData(form3);


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

  • Thanks Joas Farias. Little confused with datadriven part. But I am using 3 different @Test . i.e : [(Test (1) for first form - whose data should be from first excel sheet , Test (2) for second form - whose data should be from second excel sheet and Test (3) for third form - whose data should be from third excel sheet)] only after completing these 3 form i can add a entry in a list. So this process continues for second form submission with different set of data's from three excel sheets. Jus can u suggest me some simple way to crack this.
    – Akshara
    May 24, 2019 at 13:02
  • Any particular reason for having three @Test? I've edited the answer to show my understanding of what you've said. May 24, 2019 at 13:22
  • I got it what you have - my edit is an alternative that uses only one test. Do you need three @Test necessarily? May 24, 2019 at 13:39
  • I meant three different Test annotations (for three forms) with priority . first TestMethod with first row of data set in sheet 1 , second TestMethod with first row of data set in sheet 2 , Third TestMethod with first row of data set in sheet 3 and to submit the first form. Then again the test methods with second rows of data.
    – Akshara
    May 24, 2019 at 13:39
  • Ok - do you think the code above does follow what you described, beside the architectural fact that it has only one @Test? May 24, 2019 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.