0

I have the below DataProvider in TestNG. It has List of custom Objects called DataSheet[]. I need to pass it to Test method individually but it returns as array.

@DataProvider(name="accountsDetails") 
    public static Object[][] getData() 
    { 
    List<DataSheet> csvValues= CSVReaderUtils.getCSVValues(csvFilePath);
    DataSheet[] array = csvValues.toArray(new DataSheet[csvValues.size()]);

        return new Object[][]{{array}};
    }

    @Test(dataProvider="accountsDetails")
    public void loginTest(DataSheet data)
    {

    }

I don't have to iterate in the Test method, It is possible to return ? How to return from data provider method.

Any help is much appreciated.

Beginner
  • 313
  • 1
  • 4
  • 15

1 Answers1

1

you can always do something like this:

@DataProvider(name="accountsDetails") 
    public static Object[][] getData() 
    { 
    List<DataSheet> csvValues= CSVReaderUtils.getCSVValues(csvFilePath);
    DataSheet[] array = csvValues.toArray(new DataSheet[csvValues.size()]);
Object[][] obj=new Object[numberOfRows][numberOfColumns];
for(int i=0;i< array.length; i++) {
obj[i][0]=array[i];
}
        return obj;
    }

Please note this is not tested code. but you should get the basic idea.

Mrunal Gosar
  • 4,595
  • 13
  • 48
  • 71