Example usage for org.openqa.selenium.firefox FirefoxOptions addPreference

List of usage examples for org.openqa.selenium.firefox FirefoxOptions addPreference

Introduction

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

Prototype

public FirefoxOptions addPreference(String key, Object value) 

Source Link

Usage

From source file:io.github.bonigarcia.wdm.test.WebRtcFirefoxTest.java

License:Apache License

@Before
public void setupTest() {
    FirefoxOptions options = new FirefoxOptions();

    // This flag avoids granting the access to the camera
    options.addPreference("media.navigator.permission.disabled", true);

    // This flag force to use fake user media (synthetic video of multiple
    // color)//from  w ww . ja  va  2  s.c o m
    options.addPreference("media.navigator.streams.fake", true);

    driver = new FirefoxDriver(options);
}

From source file:objective.taskboard.it.AbstractUIIntegrationTest.java

License:Open Source License

@Before
public final void setupUIIntegrationTest() {

    String driverPath = "drivers/" + getOs() + "/marionette/64bit/geckodriver";

    if (System.getProperty("webdriver.gecko.driver") == null)
        System.setProperty("webdriver.gecko.driver", driverPath);

    if (!new File(driverPath).exists())
        throw new IllegalStateException(
                "To run integration tests, you must run 'mvn clean install' at least once to download gecko driver");

    FirefoxOptions options = new FirefoxOptions();

    options.addPreference("dom.file.createInChild", true);
    options.addPreference("browser.link.open_newwindow", 3);
    options.addPreference("browser.link.open_newwindow.restriction", 2);
    options.addPreference("intl.accept_languages", "en");

    try {//  w ww  . jav  a2  s.  c o  m
        webDriver = new FirefoxDriver(options);
    } catch (WebDriverException ex) {
        System.err.println("UI Integration Tests Aborted: It wasn't possible to instantiate the WebDriver.");
        System.err.println("You could check if Firefox AND geckodriver are up to date.");
        System.exit(1);
    }
    webDriver.manage().window().setSize(new Dimension(1280, 1080));
}

From source file:org.testeditor.fixture.web.WebDriverFixture.java

License:Open Source License

private void populateFirefoxOption(List<BrowserSetting> options, FirefoxOptions firefoxOptions) {
    StringBuffer buffer = new StringBuffer();
    if (options != null) {
        options.forEach((option) -> {
            Object value = option.getValue();
            switch (value.getClass().getSimpleName()) {
            case "String":
                buffer.append(" key:" + option.getKey() + " value:" + (String) option.getValue() + " ");
                firefoxOptions.addPreference(option.getKey(), (String) option.getValue());
                break;

            case "Integer":
                buffer.append(" key:" + option.getKey() + " value:" + (Integer) option.getValue() + " ");
                firefoxOptions.addPreference(option.getKey(), (Integer) option.getValue());
                break;

            case "Boolean":
                buffer.append(" key:" + option.getKey() + " value:" + (Boolean) option.getValue() + " ");
                firefoxOptions.addPreference(option.getKey(), (Boolean) option.getValue());
                break;

            default:
                logger.error("Only Strings, Integer or Boolean values are allowed for Option values.");
                throw new RuntimeException(
                        "Only Strings, Integer or Boolean values are allowed for Option values but was: "
                                + value.getClass().getSimpleName());

            }/*from  w w  w .j  a va  2s  .  com*/

        }

        );
    }
    logger.trace("All Firefox options: {}", buffer.toString());
}