Created
September 11, 2020 18:50
-
-
Save bharadwaj-pendyala/f33544a6bbcdb329c7fcad5e513cf7dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment