There is a way easier way of doing this. If you put all your parameters for a test on a single Excel spreadsheet row, then just read all the parameters into a single object. Then, in your dataprovider, return a single object containing all those parameters.
@Test(dataProvider = "Reg")
public void login(WebDriver drvInstance, HashMap params) {
This is how I used to do it. Then, within the dataprovider, I just create the new driver instance for each test and collect all the params in one object, then return those 2 items. Also, I use Apache MetaModel to read the spreadsheet.
In your dataprovider, do something like this:
@DataProvider(name = "test1")
public Object[][] prepareTestData() {
Object[][] vals = new Object[columns][rows];
for each row in spreadsheet {
get rows from spreadsheet into a hashmap
create new Capabilities object from hashmap values
create webdriver from capabilities
add driver and hashmap to object[][]
}
return vals;
}
The beauty of this, which you might not realize, is that those 2 parameters your passing back to the method are also accessible from the @BeforeMethod
phase of configuration. Something that JUnit cant do. Also, doing it this way, TestNG handles your threading for multiple browser instances.
Also, Rudziankoŭ has a point. You can use the Builder pattern within the dataprovider method to construct the objects, but I would do that later after you get it working.