Last active
March 14, 2021 17:22
-
-
Save eliasnogueira/594eaa9a79b8caac2d85a70660483a14 to your computer and use it in GitHub Desktop.
Basic implementation of a factory pattern to create browser instances using Selenium WebDriver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DriverFactory { | |
public WebDriver createInstance(String browser) { | |
WebDriver driver; | |
BrowserList browserType = BrowserList.valueOf(browser.toUpperCase()); | |
switch (browserType) { | |
case CHROME: | |
driver = new ChromeDriverManager().createDriver(); | |
break; | |
case FIREFOX: | |
driver = new FirefoxDriverManager().createDriver(); | |
break; | |
case EDGE: | |
driver = new EdgeDriverManager().createDriver(); | |
break; | |
case SAFARI: | |
driver = new SafariDriverManager().createDriver(); | |
break; | |
case OPERA: | |
driver = new OperaDriverManager().createDriver(); | |
break; | |
case IE: | |
driver = new IEDriverManager().createDriver(); | |
break; | |
default: | |
throw new BrowserNotSupportedException(browser); | |
} | |
return driver; | |
} | |
public enum BrowserList { | |
CHROME, FIREFOX, EDGE, SAFARI, OPERA, IE | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment