Skip to content

03. CSV TestNG Dataprovider

Hemanth Sridhar edited this page Mar 3, 2022 · 1 revision

CSV TestNG Dataprovider

Assuming that the CSV is defined as below with name random_comma_seperated_value.csv

param1,param2,param3
hi,bye,hello
bye,hi,hello
hello,hi,bye
@DataProvider(parallel=true)
public Object[][] csvDataRead() throws Exception {
  String path = "src/test/resources/random_comma_seperated_value.csv";
  ExtUtils ext = new CSVUtils(path);
  return ext.parseData();
}

If it has column names, we need to skip the first row read.

@DataProvider(parallel=true)
public Object[][] csvDataRead() throws Exception {
  String path = "src/test/resources/random_comma_seperated_value.csv";
  ExtUtils ext = new CSVUtils(path, true);
  return ext.parseData();
}
@Test(dataProvider = "csvDataRead", dataProviderClass = ExtDataProvider.class)
public void csvRead(String param1, String param2, String param3) {
  System.out.print(param1 + ",");
  System.out.print(param2 + ",");
  System.out.print(param3);
  System.out.println();
}