There are lots of ways to do this, but here is an idea. I wrote an example here that does it.
The general gist of the idea is, using the MetaModel api:
public static Object[][] get2ArgArrayFromRows( List<Row> rows ) {
Object[][] myArray = new Object[rows.size()][2];
int i = 0;
SelectItem[] cols = rows.get(0).getSelectItems();
for ( Row r : rows ) {
Object[] data = r.getValues();
for ( int j = 0; j < cols.length; j++ ) {
if ( data[j] == null ) data[j] = ""; // force empty string where there are NULL values
}
myArray[i][0] = cols;
myArray[i][1] = data;
i++;
}
logger.info( "Row count: " + rows.size() );
logger.info( "Column names: " + Arrays.toString( cols ) );
return myArray;
}
public static Object[][] getCsvData( File csvFile )
{
CsvConfiguration conf = new CsvConfiguration( 1 );
DataContext csvContext = DataContextFactory.createCsvDataContext( csvFile, conf );
Schema schema = csvContext.getDefaultSchema();
Table[] tables = schema.getTables();
Table table = tables[0]; // a representation of the csv file name including extension
DataSet dataSet = csvContext.query()
.from( table )
.selectAll()
.where("run").eq("Y")
.execute();
List<Row> rows = dataSet.toRows();
Object[][] myArray = get2ArgArrayFromRows( rows );
return myArray;
}
Now, this code above is just a ROUGH idea. What you really need to do is merge cols and data into a Map<String,String>
object and then pass that as the first argument back to your test, containing all parameters from the CSV file, including browser type. Then, as the second argument, set it like so:
myArray[i][1] = new WebDriverBuilderHelper();
Then, in your @Test annotated method, instantiate the driver:
@Test(dataProvider = "dp")
public void testIt( Map<String,String> map, WebDriverBuilderHelper wdhelper ) {
wdhelper.instantiateBrowser( map.get("browser") );
wdhelper.navigateTo(url);
....