Search in sources :

Example 11 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project wcomponents by BorderTech.

the class FirefoxWebDriverType method getDriverImplementation.

/**
 * {@inheritDoc}.
 */
@Override
public FirefoxDriver getDriverImplementation() {
    WebDriverManager.getInstance(DriverManagerType.FIREFOX).setup();
    FirefoxOptions options = new FirefoxOptions(getCapabilities());
    FirefoxBinary binary = getFirefoxBinary();
    FirefoxProfile profile = getFirefoxProfile();
    if (profile != null) {
        // it gets angry if you give it a null profile
        options.setProfile(profile);
    }
    // options.setHeadless(true);
    options.setBinary(binary);
    return new FirefoxDriver(options);
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 12 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project nutch by apache.

the class HttpWebClient method getDriverForPage.

public static WebDriver getDriverForPage(String url, Configuration conf) {
    WebDriver driver = null;
    long pageLoadWait = conf.getLong("page.load.delay", 3);
    try {
        String driverType = conf.get("selenium.driver", "firefox");
        boolean enableHeadlessMode = conf.getBoolean("selenium.enable.headless", false);
        switch(driverType) {
            case "firefox":
                String geckoDriverPath = conf.get("selenium.grid.binary", "/root/geckodriver");
                driver = createFirefoxWebDriver(geckoDriverPath, enableHeadlessMode);
                break;
            case "chrome":
                String chromeDriverPath = conf.get("selenium.grid.binary", "/root/chromedriver");
                driver = createChromeWebDriver(chromeDriverPath, enableHeadlessMode);
                break;
            // break;
            case "remote":
                String seleniumHubHost = conf.get("selenium.hub.host", "localhost");
                int seleniumHubPort = Integer.parseInt(conf.get("selenium.hub.port", "4444"));
                String seleniumHubPath = conf.get("selenium.hub.path", "/wd/hub");
                String seleniumHubProtocol = conf.get("selenium.hub.protocol", "http");
                URL seleniumHubUrl = new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath);
                String seleniumGridDriver = conf.get("selenium.grid.driver", "firefox");
                switch(seleniumGridDriver) {
                    case "firefox":
                        driver = createFirefoxRemoteWebDriver(seleniumHubUrl, enableHeadlessMode);
                        break;
                    case "chrome":
                        driver = createChromeRemoteWebDriver(seleniumHubUrl, enableHeadlessMode);
                        break;
                    case "random":
                        driver = createRandomRemoteWebDriver(seleniumHubUrl, enableHeadlessMode);
                        break;
                    default:
                        LOG.error("The Selenium Grid WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
                        driver = createDefaultRemoteWebDriver(seleniumHubUrl, enableHeadlessMode);
                        break;
                }
                break;
            default:
                LOG.error("The Selenium WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
                FirefoxOptions options = new FirefoxOptions();
                driver = new FirefoxDriver(options);
                break;
        }
        LOG.debug("Selenium {} WebDriver selected.", driverType);
        driver.manage().timeouts().pageLoadTimeout(pageLoadWait, TimeUnit.SECONDS);
        driver.get(url);
    } catch (Exception e) {
        if (e instanceof TimeoutException) {
            LOG.error("Selenium WebDriver: Timeout Exception: Capturing whatever loaded so far...");
            return driver;
        } else {
            LOG.error(e.toString());
        }
        cleanUpDriver(driver);
        throw new RuntimeException(e);
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) URL(java.net.URL) TimeoutException(org.openqa.selenium.TimeoutException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 13 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project nutch by apache.

the class HttpWebClient method createFirefoxWebDriver.

public static WebDriver createFirefoxWebDriver(String firefoxDriverPath, boolean enableHeadlessMode) {
    System.setProperty("webdriver.gecko.driver", firefoxDriverPath);
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    if (enableHeadlessMode) {
        firefoxOptions.addArguments("--headless");
    }
    WebDriver driver = new FirefoxDriver(firefoxOptions);
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver)

Example 14 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project nutch by apache.

the class HttpWebClient method createFirefoxRemoteWebDriver.

public static RemoteWebDriver createFirefoxRemoteWebDriver(URL seleniumHubUrl, boolean enableHeadlessMode) {
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    if (enableHeadlessMode) {
        firefoxOptions.setHeadless(true);
    }
    RemoteWebDriver driver = new RemoteWebDriver(seleniumHubUrl, firefoxOptions);
    return driver;
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver)

Example 15 with FirefoxOptions

use of org.openqa.selenium.firefox.FirefoxOptions in project drools by kiegroup.

the class FEELShowcaseIT method getFirefoxOptions.

private FirefoxOptions getFirefoxOptions() {
    final FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setHeadless(HEADLESS);
    firefoxOptions.setProfile(getFirefoxProfile());
    return firefoxOptions;
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions)

Aggregations

FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)21 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)17 WebDriver (org.openqa.selenium.WebDriver)9 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)7 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)6 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)6 File (java.io.File)5 URL (java.net.URL)5 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)5 Before (org.junit.Before)4 Dimension (org.openqa.selenium.Dimension)3 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)3 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)3 SafariDriver (org.openqa.selenium.safari.SafariDriver)3 IOException (java.io.IOException)2 TimeoutException (org.openqa.selenium.TimeoutException)2 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)2 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)2 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)2 OperaDriver (org.openqa.selenium.opera.OperaDriver)2