Source:
private WebDriver createWebDriver(TestName testName) throws IOException { String browser = System.getenv("BROWSER"); if (browser==null) browser = "firefox"; browser = browser.toLowerCase(Locale.ENGLISH); switch (browser) { case "firefox": FirefoxProfile profile = new FirefoxProfile(); profile.setAlwaysLoadNoFocusLib(true); profile.setPreference(LANGUAGE_SELECTOR, "en"); profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, 600); profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, 600); FirefoxBinary binary = new FirefoxBinary(); String display = getBrowserDisplay(); if (display != null) { binary.setEnvironmentProperty("DISPLAY", display); } return new FirefoxDriver(binary, profile); case "ie": case "iexplore": case "iexplorer": return new InternetExplorerDriver(); case "chrome": Map<String, String> prefs = new HashMap<String, String>(); prefs.put(LANGUAGE_SELECTOR, "en"); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); return new ChromeDriver(options); case "safari": return new SafariDriver(); case "htmlunit": return new HtmlUnitDriver(true); case "saucelabs": case "saucelabs-firefox": DesiredCapabilities caps = DesiredCapabilities.firefox(); caps.setCapability("version", "29"); caps.setCapability("platform", "Windows 7"); caps.setCapability("name", testName.get()); String tag = System.getenv("BUILD_TAG"); if (tag!=null) caps.setCapability("build", tag); return new SauceLabsConnection().createWebDriver(caps); case "phantomjs": DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setCapability(LANGUAGE_SELECTOR, "en"); capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en"); return new PhantomJSDriver(capabilities); case "remote-webdriver-firefox": String u = System.getenv("REMOTE_WEBDRIVER_URL"); if (StringUtils.isBlank(u)) { throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set"); } return new RemoteWebDriver( new URL(u), DesiredCapabilities.firefox()); default: throw new Error("Unrecognized browser type: "+browser); } }

Target:
private WebDriver createWebDriver(TestName testName) throws IOException { String browser = System.getenv("BROWSER"); if (browser==null) browser = "firefox"; browser = browser.toLowerCase(Locale.ENGLISH); switch (browser) { case "firefox": FirefoxProfile profile = new FirefoxProfile(); profile.setAlwaysLoadNoFocusLib(true); profile.setPreference(LANGUAGE_SELECTOR, "en"); profile.setPreference(DOM_MAX_SCRIPT_RUN_TIME, (int)getElasticTime().seconds(600)); profile.setPreference(DOM_MAX_CHROME_SCRIPT_RUN_TIME, (int)getElasticTime().seconds(600)); FirefoxBinary binary = new FirefoxBinary(); String display = getBrowserDisplay(); if (display != null) { binary.setEnvironmentProperty("DISPLAY", display); } return new FirefoxDriver(binary, profile); case "ie": case "iexplore": case "iexplorer": return new InternetExplorerDriver(); case "chrome": Map<String, String> prefs = new HashMap<String, String>(); prefs.put(LANGUAGE_SELECTOR, "en"); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); return new ChromeDriver(options); case "safari": return new SafariDriver(); case "htmlunit": return new HtmlUnitDriver(true); case "saucelabs": case "saucelabs-firefox": DesiredCapabilities caps = DesiredCapabilities.firefox(); caps.setCapability("version", "29"); caps.setCapability("platform", "Windows 7"); caps.setCapability("name", testName.get()); String tag = System.getenv("BUILD_TAG"); if (tag!=null) caps.setCapability("build", tag); return new SauceLabsConnection().createWebDriver(caps); case "phantomjs": DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setCapability(LANGUAGE_SELECTOR, "en"); capabilities.setCapability(LANGUAGE_SELECTOR_PHANTOMJS, "en"); return new PhantomJSDriver(capabilities); case "remote-webdriver-firefox": String u = System.getenv("REMOTE_WEBDRIVER_URL"); if (StringUtils.isBlank(u)) { throw new Error("remote-webdriver-firefox requires REMOTE_WEBDRIVER_URL to be set"); } return new RemoteWebDriver( new URL(u), DesiredCapabilities.firefox()); default: throw new Error("Unrecognized browser type: "+browser); } }