import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.GeckoDriverService; import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; import java.io.IOException; import java.util.logging.Level; public class FirefoxDriverManager extends DriverFactory { GeckoDriverService firefoxDriverService; @Override protected void startBrowser() throws IOException { if (null == firefoxDriverService) { try { firefoxDriverService = new GeckoDriverService.Builder().usingDriverExecutable(new File("geckodriver")).usingAnyFreePort().build(); firefoxDriverService.start(); } catch (Exception e) { e.printStackTrace(); } } } @Override protected void stopBrowser() { if ((null != firefoxDriverService) && firefoxDriverService.isRunning()) firefoxDriverService.stop(); } @Override protected void createDriver() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.no_proxies_on", "localhost"); profile.setPreference("javascript.enabled", true); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); FirefoxOptions options = new FirefoxOptions(); options.merge(capabilities); options.setLogLevel(Level.FINEST); options.addPreference("browser.link.open_newwindow", 3); options.addPreference("browser.link.open_newwindow.restriction", 0); driver = new FirefoxDriver(options); } }