I want to run selenium tests in TestNg in parallel that use the @dataprovider. Ideally tests are parallel by method (one test = one method) and not simple suite parallelism by
You don't really need to use a Factory. If I were you I would call this code within the dataprovider method:
driver = getBrowser(browser);
Then, return the driver instances as a 2nd column of args to the test method. Doing it that way allows the dataprovider to generate browser instances. To improve on that, you could instead use the builder design pattern, in the form of a DriverHelper class, that could replace the getBrowser method with a way to generate a much more specific driver configuration before passing the driver instance into the test method.
NOTE: Keep in mind that if you ever want to use Spring to load your drivers in the future, then this method won't work at all. In fact, you wont be able to use a DataProvider at all. But, if your not using Spring, then I would say this is the most elegant way of doing it.