Skip to content

Instantly share code, notes, and snippets.

@eliasnogueira
Last active January 21, 2020 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasnogueira/3413c5622716e6d73a6eaf9e59f296b1 to your computer and use it in GitHub Desktop.
Save eliasnogueira/3413c5622716e6d73a6eaf9e59f296b1 to your computer and use it in GitHub Desktop.
public class LocalDriverManager {
// to make this work just pass the browser name, that must match from the DriverManagerType class
public WebDriver createInstance(String browser) {
WebDriver driver = null;
try {
DriverManagerType driverManagerType = DriverManagerType.valueOf(browser.toUpperCase());
Class<?> driverClass = Class.forName(driverManagerType.browserClass());
WebDriverManager.getInstance(driverManagerType).setup();
driver = (WebDriver) driverClass.newInstance();
} catch (IllegalAccessException | ClassNotFoundException e) {
// exception or log for class not found
} catch (InstantiationException e) {
// exception of log for instantiation problem
}
return driver;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment