Example usage for org.openqa.selenium.firefox GeckoDriverService GECKO_DRIVER_EXE_PROPERTY

List of usage examples for org.openqa.selenium.firefox GeckoDriverService GECKO_DRIVER_EXE_PROPERTY

Introduction

In this page you can find the example usage for org.openqa.selenium.firefox GeckoDriverService GECKO_DRIVER_EXE_PROPERTY.

Prototype

String GECKO_DRIVER_EXE_PROPERTY

To view the source code for org.openqa.selenium.firefox GeckoDriverService GECKO_DRIVER_EXE_PROPERTY.

Click Source Link

Document

System property that defines the location of the GeckoDriver executable that will be used by the #createDefaultService() default service .

Usage

From source file:com.seleniumtests.ut.browserfactory.TestMarionetteCapabilitiesFactory.java

License:Apache License

@Test(groups = { "ut" })
public void testCreateMarionetteCapabilitiesStandardDriverPathLocal() {
    System.clearProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
    try {//from  w w w .  j a  va  2 s . c o m
        Mockito.when(config.getMode()).thenReturn(DriverMode.LOCAL);

        new FirefoxCapabilitiesFactory(config).createCapabilities();

        Assert.assertTrue(System.getProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY)
                .replace(File.separator, "/").contains("/drivers/geckodriver"));
    } finally {
        System.clearProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
    }
}

From source file:com.seleniumtests.ut.browserfactory.TestMarionetteCapabilitiesFactory.java

License:Apache License

@Test(groups = { "ut" })
public void testCreateMarionetteCapabilitiesOverrideDriverPathLocal() {
    System.clearProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
    try {/*from ww w .j  av a 2  s. c  o  m*/
        Mockito.when(config.getMode()).thenReturn(DriverMode.LOCAL);
        Mockito.when(config.getGeckoDriverPath()).thenReturn("/opt/firefox/driver/geckodriver");

        new FirefoxCapabilitiesFactory(config).createCapabilities();

        Assert.assertEquals(
                System.getProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY).replace(File.separator, "/"),
                "/opt/firefox/driver/geckodriver");
    } finally {
        System.clearProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
    }
}

From source file:com.seleniumtests.ut.browserfactory.TestMarionetteCapabilitiesFactory.java

License:Apache License

@Test(groups = { "ut" })
public void testCreateMarionetteCapabilitiesStandardDriverPathGrid() {
    System.clearProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY);
    Mockito.when(config.getMode()).thenReturn(DriverMode.GRID);

    new FirefoxCapabilitiesFactory(config).createCapabilities();

    Assert.assertNull(System.getProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY));
}

From source file:org.apache.zeppelin.WebDriverManager.java

License:Apache License

public static WebDriver getWebDriver() {
    WebDriver driver = null;/*ww w . j  av  a2 s  .c om*/

    if (driver == null) {
        try {
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                // run with DISPLAY 99
            }
            int firefoxVersion = WebDriverManager.getFirefoxVersion();
            LOG.info("Firefox version " + firefoxVersion + " detected");

            downLoadsDir = FileUtils.getTempDirectory().toString();

            String tempPath = downLoadsDir + "/firefox/";

            downloadGeekoDriver(firefoxVersion, tempPath);

            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.dir", downLoadsDir);
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", true);
            profile.setPreference("app.update.auto", false);
            profile.setPreference("app.update.enabled", false);
            profile.setPreference("dom.max_script_run_time", 0);
            profile.setPreference("dom.max_chrome_script_run_time", 0);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
            profile.setPreference("network.proxy.type", 0);

            System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, tempPath + "geckodriver");
            System.setProperty(SystemProperty.DRIVER_USE_MARIONETTE, "false");

            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setBinary(ffox);
            firefoxOptions.setProfile(profile);
            driver = new FirefoxDriver(firefoxOptions);
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }

    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }

    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);

    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }

    if (loaded == false) {
        fail();
    }

    driver.manage().window().maximize();
    return driver;
}