Example usage for org.openqa.selenium.firefox FirefoxBinary FirefoxBinary

List of usage examples for org.openqa.selenium.firefox FirefoxBinary FirefoxBinary

Introduction

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

Prototype

public FirefoxBinary() 

Source Link

Usage

From source file:com.example.calculator.CalculatorIntegrationTest.java

License:Apache License

@Before
public void openWebDriver() {
    testServerPort = System.getProperty("test.server.port", "8080");
    String display = System.getProperty("test.xvfb.display", null);
    FirefoxBinary firefox = new FirefoxBinary();
    if (display != null) {
        firefox.setEnvironmentProperty("DISPLAY", display);
    }//from   w ww  .  j a  va 2s  . c o  m
    webDriver = new FirefoxDriver(firefox, null);
}

From source file:com.yufei.dataget.dataretriver.HttpDataRetriverUsingFirefoxDriver.java

@Override
public void connect() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("permissions.default.stylesheet", 2);
    profile.setPreference("permissions.default.image", 2);
    profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
    //profile.setPreference("DISPLAY", ":10");
    FirefoxBinary fb = new FirefoxBinary();
    fb.setEnvironmentProperty("DISPLAY", ":10");
    // sudo Xvfb :10 -ac 
    driver = new FirefoxDriver(fb, profile);
    driver.get(this.url.toString());

}

From source file:de.learnlib.alex.learning.entities.webdrivers.FirefoxDriverConfig.java

License:Apache License

@Override
public WebDriver createDriver() throws Exception {
    final FirefoxBinary binary = new FirefoxBinary();
    if (headless) {
        binary.addCommandLineOptions("-headless");
    }//from   ww  w . j a  va2s .  co  m

    final Map<String, String> environmentVariables = new HashMap<>();
    final WebDriver driver = new FirefoxDriver(new GeckoDriverService.Builder().usingFirefoxBinary(binary)
            .withEnvironment(environmentVariables).build());
    manage(driver);

    return driver;
}

From source file:de.ppi.selenium.browser.DefaultWebDriverFactory.java

License:Apache License

@Override
public WebDriver createWebDriver(Map<String, String> options, DesiredCapabilities capabilities)
        throws IOException {
    ClientProperties properties = new ClientProperties(options.get(CLIENT_PROPERTIES_KEY));

    WebDriver wd = null;// ww  w.  j  a  v  a2  s  . c  om
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities(capabilities);
    String browser = properties.getBrowser();

    if (properties.isUseGrid()) {
        RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(properties.getGridUrl()), capabilities);
        remoteWebDriver.setFileDetector(new LocalFileDetector());
        wd = remoteWebDriver;
    } else {
        if (browser == null || browser.equals("")) {
            throw new RuntimeException(
                    "Browser cannot be null. Please set 'browser' in client properties. Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit.");
        } else if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore")
                || browser.equalsIgnoreCase("*iexplore")) {
            String webdriverIEDriver = properties.getWebDriverIEDriver();

            if (webdriverIEDriver != null) {
                System.setProperty("webdriver.ie.driver", webdriverIEDriver);
            }

            String browserVersion = properties.getBrowserVersion();

            if (browserVersion == null || browserVersion.equals("")) {
                throw new RuntimeException(
                        "When using IE as the browser, please set 'browser.version' in client properties");
            } else {
                if (browserVersion.startsWith("9")) {
                    desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
                    desiredCapabilities.setCapability(
                            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
                    wd = new InternetExplorerDriver(desiredCapabilities);
                } else {
                    wd = new InternetExplorerDriver(desiredCapabilities);
                }
            }
        } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) {
            final String ffProfileFolder = properties.getFirefoxProfileFolder();
            final String ffProfileFile = properties.getFirefoxProfileFile();
            final String path = properties.getFfBinaryPath();
            final FirefoxProfile ffp;
            if (ffProfileFolder != null) {
                ffp = new FirefoxProfile(new File(ffProfileFolder));
            } else {
                ffp = new FirefoxProfile();
            }

            if (ffProfileFile != null) {
                addPreferences(ffp, ffProfileFile);
            }

            addPreferences(ffp, properties);

            List<String> ffExtensions = properties.getFirefoxExtensions();
            if (ffExtensions != null && ffExtensions.size() > 0) {
                addExtensionsToFirefoxProfile(ffp, ffExtensions);
            }

            if (path != null) {
                FirefoxBinary fireFox = getFFBinary(path);
                wd = new FirefoxDriver(fireFox, ffp, desiredCapabilities);
            } else {
                wd = new FirefoxDriver(new FirefoxBinary(), ffp, desiredCapabilities);

            }
        } else if (browser.equalsIgnoreCase("chrome")) {

            final String webdriverChromeDriver = properties.getWebDriverChromeDriver();

            if (webdriverChromeDriver != null) {
                System.setProperty("webdriver.chrome.driver", webdriverChromeDriver);
            }

            final ChromeOptions chromeOptions = new ChromeOptions();
            final String chromeBinaryPath = properties.getChromeBinaryPath();
            if (chromeBinaryPath != null) {
                chromeOptions.setBinary(chromeBinaryPath);
            }

            if (properties.getAcceptedLanguages() != null) {

                final Map<String, Object> prefs = new HashMap<String, Object>();
                prefs.put("intl.accept_languages", properties.getAcceptedLanguages());
                chromeOptions.setExperimentalOption("prefs", prefs);
            }
            desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

            wd = new ChromeDriver(desiredCapabilities);

        } else if (browser.equalsIgnoreCase("safari")) {
            wd = new SafariDriver(desiredCapabilities);
        } else if (browser.equalsIgnoreCase("htmlunit")) {
            final BrowserVersion browserVersion = BrowserVersion.FIREFOX_45;
            if (properties.getAcceptedLanguages() != null) {
                browserVersion.setBrowserLanguage(properties.getAcceptedLanguages().split(",")[0]);
            }
            wd = new HtmlUnitDriver(browserVersion);
            ((HtmlUnitDriver) wd).setJavascriptEnabled(true);
        } else if (browser.equalsIgnoreCase("phantomjs")) {
            final String webdriverPhantomJSDriver = properties.getWebDriverPhantomJSDriver();
            if (properties.getAcceptedLanguages() != null) {
                desiredCapabilities.setCapability("phantomjs.page.customHeaders.Accept-Language",
                        properties.getAcceptedLanguages());
            }

            if (webdriverPhantomJSDriver != null) {
                desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                        webdriverPhantomJSDriver);
                wd = new PhantomJSDriver(desiredCapabilities);
            } else {
                wd = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(),
                        desiredCapabilities);
            }
        } else {
            throw new IllegalArgumentException("Unsupported browser type: " + browser
                    + ". Supported browser types: IE, Firefox, Chrome, Safari, HtmlUnit, phantomjs.");
        }

        // move browser windows to specific position. It's useful for
        // debugging...
        final int browserInitPositionX = properties.getBrowserInitPositionX();
        final int browserInitPositionY = properties.getBrowserInitPositionY();
        if (browserInitPositionX != 0 || browserInitPositionY != 0) {
            wd.manage().window().setSize(new Dimension(1280, 1024));
            wd.manage().window().setPosition(new Point(browserInitPositionX, browserInitPositionY));
        }
        wd.manage().timeouts().implicitlyWait(properties.getAppearWaitTime(), TimeUnit.MILLISECONDS);
    }

    return wd;
}

From source file:edu.usc.cs.ir.selenium.handler.Arguntrader.java

License:Apache License

public static void main(String[] args) {
    Arguntrader glocktalk = new Arguntrader();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
    profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
    profile.setPreference("permissions.default.stylesheet", 1);
    profile.setPreference("permissions.default.image", 1);

    FirefoxBinary binary = new FirefoxBinary();
    binary.setTimeout(TimeUnit.SECONDS.toMillis(180));

    WebDriver driver = new FirefoxDriver(binary, profile);
    driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS);

    try {/*from   w  w  w  . ja  v  a  2  s  .  co  m*/
        driver.get("http://arguntrader.com/viewforum.php?f=8");
        System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
    } catch (Exception e) {
        if (e instanceof TimeoutException) {
            System.out.println("Timeout Exception");

            try {
                System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }
        e.printStackTrace();
    } finally {
        if (driver != null) {
            driver.close();
            driver.quit();
        }
    }
}

From source file:edu.usc.cs.ir.selenium.handler.Glocktalk.java

License:Apache License

public static void main(String[] args) {
    Glocktalk glocktalk = new Glocktalk();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
    profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
    profile.setPreference("permissions.default.stylesheet", 1);
    profile.setPreference("permissions.default.image", 1);

    FirefoxBinary binary = new FirefoxBinary();
    binary.setTimeout(TimeUnit.SECONDS.toMillis(180));

    WebDriver driver = new FirefoxDriver(binary, profile);
    driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS);

    try {/*from  ww w .  j a  v a2  s  .c  o m*/
        driver.get("http://www.glocktalk.com/media?page=6");
        System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
    } catch (Exception e) {
        if (e instanceof TimeoutException) {
            System.out.println("Timeout Exception");

            try {
                System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }
        //e.printStackTrace();
    } finally {
        if (driver != null) {
            driver.close();
            driver.quit();
        }
    }
}

From source file:endtoend.browser.driver.builders.FirefoxDriverBuilderTest.java

License:Apache License

@Test
public void withOptions() {
    // when/*  w w  w.j a  v  a2  s. com*/
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setHeadless(true);
    FirefoxBinary firefoxBinary = new FirefoxBinary();
    $.driver().useFirefox().withOptions(firefoxOptions).withBinary(firefoxBinary).autoDriverDownload();
    // then
    HeadlessTestUtils.assertHeadlessYes($.driver().get());
}

From source file:it.com.pyxis.jira.selenium.WebDriverFactory.java

License:Open Source License

private WebDriver newXvfbDriver(String xvfbDisplayId) {

    FirefoxBinary firefox = new FirefoxBinary();
    firefox.setEnvironmentProperty("DISPLAY", xvfbDisplayId);

    WebDriver driver = new FirefoxDriver(firefox, null);

    setDriverSpeed(driver);/*w  w w  . j  av  a2s .  co  m*/
    setTimeout(driver);

    return driver;
}

From source file:iTests.framework.utils.WebuiTestUtils.java

public static FirefoxDriver createFirefoxDriver() {

    String newmanSystemProperty = System.getProperty("com.gs.test.use.newman");
    LogUtils.log("WebuiTestsUtils, passed newmanSystemProperty=" + newmanSystemProperty);

    boolean useNewman = Boolean
            .parseBoolean(System.getProperty("com.gs.test.use.newman", Boolean.FALSE.toString()));
    LogUtils.log("useNewman=" + useNewman);
    if (useNewman) {
        LogUtils.log("--- createFirefoxDriver ---");
        String Xport = System.getProperty("lmportal.xvfb.id", ":1");
        LogUtils.log("Xport=" + Xport);
        //final File firefoxPath = new File( System.getProperty( "lmportal.deploy.firefox.path", "/usr/bin/firefox" ) );
        FirefoxBinary firefoxBinary = new FirefoxBinary(/*firefoxPath*/);
        LogUtils.log("FirefoxBinary initialized");
        firefoxBinary.setEnvironmentProperty("DISPLAY", Xport);
        LogUtils.log("After set DISPLAY port");

        return new FirefoxDriver(firefoxBinary, null);
    }//from www. j av a2  s .c o  m

    return new FirefoxDriver();
}

From source file:nz.co.testamation.core.WebIntegrationTestAutoConfiguration.java

License:Apache License

@Bean
@Autowired//from w  w w .  jav  a2s  .  c  o m
public WebDriver webDriver(@Value("${web.driver:firefox}") String webDriver,
        @Value("${web.driver.autoDownload.mimeTypes:application/pdf}") String autoDownloadMimeTypes,
        @Qualifier("webDriverDownloadDir") File downloadDir) {

    if ("htmlunit".equals(webDriver)) {
        return new HtmlUnitDriver();
    }

    if ("chrome".equals(webDriver)) {
        return new ChromeDriver();
    }

    if ("firefox".equals(webDriver)) {
        FirefoxBinary firefoxBinary = new FirefoxBinary();
        if (System.getenv("DISPLAY") == null) {
            firefoxBinary.setEnvironmentProperty("DISPLAY", ":99");
        }

        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("browser.download.folderList", 2); // Download to: 0 desktop, 1 default download location, 2 custom folder
        profile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", autoDownloadMimeTypes);
        profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf");
        profile.setPreference("pdfjs.disabled", true);

        return new FirefoxDriver(firefoxBinary, profile);
    }

    if ("ie".equals(webDriver)) {
        return new InternetExplorerDriver();
    }

    if ("safari".equals(webDriver)) {
        return new SafariDriver();
    }

    if ("opera".equals(webDriver)) {
        return new OperaDriver();
    }

    throw new IllegalArgumentException(format("Web driver %s not supported.", webDriver));
}