Java Code Examples for org.openqa.selenium.firefox.FirefoxOptions#setProfile()

The following examples show how to use org.openqa.selenium.firefox.FirefoxOptions#setProfile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirefoxCustomProfile.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 7 votes vote down vote up
public static void main(String... args) throws IOException {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.addExtension(
                new File("./src/test/resources/extensions/xpath_finder.xpi"));

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

        try {
            driver.get("http://www.google.com");
        } finally {
            driver.quit();
        }

    }
 
Example 2
Source File: FirefoxFrozenPreferences.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 6 votes vote down vote up
public static void main(String... args) {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.shell.checkDefaultBrowser", true);
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setAcceptUntrustedCertificates(false);

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);

        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("http://facebook.com");
    }
 
Example 3
Source File: FirefoxWebDriverProvider.java    From submarine with Apache License 2.0 5 votes vote down vote up
@Override
public WebDriver createWebDriver(String webDriverPath) {
  FirefoxBinary ffox = new FirefoxBinary();
  if ("true".equals(System.getenv("TRAVIS"))) {
    // xvfb is supposed to run with DISPLAY 99
    ffox.setEnvironmentProperty("DISPLAY", ":99");
  }
  ffox.addCommandLineOptions("--headless");

  FirefoxProfile profile = new FirefoxProfile();
  profile.setPreference("browser.download.folderList", 2);
  profile.setPreference("browser.download.dir",
      FileUtils.getTempDirectory().toString() + "/firefox/");
  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, webDriverPath);
  System.setProperty(
      FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");

  FirefoxOptions firefoxOptions = new FirefoxOptions();
  firefoxOptions.setBinary(ffox);
  firefoxOptions.setProfile(profile);
  firefoxOptions.setLogLevel(FirefoxDriverLogLevel.TRACE);

  return new FirefoxDriver(firefoxOptions);
}
 
Example 4
Source File: BotWorker.java    From JYTB with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Sets the webdriver to FireFox. We set our optimal parameters here
     * to ensure our proxy is set correctly.
     */
    private void setFirefoxDriver() {
        FirefoxOptions options = new FirefoxOptions();
        FirefoxProfile profile = new FirefoxProfile();
        FirefoxBinary binary = new FirefoxBinary(this.driverLocation);
        LoggingPreferences logPrefs = new LoggingPreferences();
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
        // hide firefox logs from console
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/tmp/rust_");

        profile.setPreference("media.volume_scale", "0.0");
        profile.setPreference("general.useragent.override", userAgent.randomUA());
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.http_port", this.proxies.getCurrentProxyModel().getPort());
        profile.setPreference("network.proxy.ssl", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.ssl_port", this.proxies.getCurrentProxyModel().getPort());

        logPrefs.enable(LogType.BROWSER, Level.ALL);
        logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
        options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

        options.setProfile(profile);
        options.setHeadless(true);
        options.setBinary(binary);
//        options.setProxy(this.proxies.getCurrentProxy());
        options.setCapability("proxy", this.proxies.getCurrentProxy());
        this.webDriver = new FirefoxDriver(options);

        Log.WINFO(this.workerName, this.workerColor, "Firefox Driver Set");
    }
 
Example 5
Source File: FirefoxSettingPreferences.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 5 votes vote down vote up
public static void main(String... args) {

        System.setProperty("webdriver.gecko.driver",
                "./src/test/resources/drivers/geckodriver 2");

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("general.useragent.override",
                "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) " +
                        "AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 " +
                        " Mobile/15A356 Safari/604.1");
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);
        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("http://facebook.com");
    }
 
Example 6
Source File: VaadinLocaleTest.java    From viritin with Apache License 2.0 5 votes vote down vote up
public VaadinLocaleTest(String language, String expectedLanuage) {
    this.expectedLanguage = expectedLanuage;
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("intl.accept_languages", language);
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setProfile(profile);
    WebDriver webDriver = new FirefoxDriver(firefoxOptions);
    startBrowser(webDriver);
}
 
Example 7
Source File: MBeanFieldGroupRequiredErrorMessageTest.java    From viritin with Apache License 2.0 5 votes vote down vote up
public MBeanFieldGroupRequiredErrorMessageTest(String language, String expectedMessage) {
    this.expectedMessage = expectedMessage;
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("intl.accept_languages", language);
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setProfile(profile);
    WebDriver webDriver = new FirefoxDriver(firefoxOptions);
    startBrowser(webDriver);
}
 
Example 8
Source File: WebDriverCapabilities.java    From QVisual with Apache License 2.0 4 votes vote down vote up
private void setupFirefox() {
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("dom.webnotifications.enabled", false);
    firefoxProfile.setAcceptUntrustedCertificates(true);
    firefoxProfile.setPreference("app.update.enabled", false);
    firefoxProfile.setPreference("devtools.devedition.promo.url", "");
    firefoxProfile.setPreference("xpinstall.signatures.required", false);
    firefoxProfile.setPreference("browser.startup.homepage;about:home", "about:blank");
    firefoxProfile.setPreference("browser.startup.homepage_override.mstone", "ignore");
    firefoxProfile.setPreference("browser.usedOnWindows10", false);
    firefoxProfile.setPreference("browser.usedOnWindows10.introURL", "about:blank");
    firefoxProfile.setPreference("startup.homepage_welcome_url", "about:blank");
    firefoxProfile.setPreference("startup.homepage_welcome_url.additional", "about:blank");
    firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
    firefoxProfile.setPreference("browser.download.folderList", 2);
    firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    firefoxProfile.setPreference("browser.download.manager.useWindow", false);
    firefoxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    firefoxProfile.setPreference("browser.download.dir", DOWNLOAD_DIRECTORY);
    firefoxProfile.setPreference("browser.download.manager.focusWhenStarting", false);
    firefoxProfile.setPreference("browser.download.useDownloadDir", true);
    firefoxProfile.setPreference("browser.download.manager.closeWhenDone", true);
    firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete", false);
    firefoxProfile.setPreference("browser.download.panel.shown", false);
    firefoxProfile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
    firefoxProfile.setPreference("pdfjs.disabled", true);
    firefoxProfile.setPreference("plugin.scan.Acrobat", "99.0");
    firefoxProfile.setPreference("plugin.scan.plid.all", false);
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-msdownload," +
            "application/AppleLink," +
            "application/x-newton-compatible-pkg," +
            "image/png," +
            "application/ris," +
            "text/csv," +
            "text/xml," +
            "text/html," +
            "text/plain," +
            "application/xml," +
            "application/zip," +
            "application/x-zip," +
            "application/x-zip-compressed," +
            "application/download," +
            "application/octet-stream," +
            "application/excel," +
            "application/vnd.ms-excel," +
            "application/x-excel," +
            "application/x-msexcel," +
            "application/vnd.openxmlformats-officedocument.spreadsheetml.template," +
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet," +
            "application/msword," +
            "application/csv," +
            "application/pdf," +
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document," +
            "application/vnd.openxmlformats-officedocument.wordprocessingml.template");

    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setProfile(firefoxProfile);
    firefoxOptions.setHeadless(BROWSER_HEADLESS);

    capabilities.merge(firefoxOptions);
}
 
Example 9
Source File: FirefoxDriverHandler.java    From selenium-jupiter with Apache License 2.0 4 votes vote down vote up
@Override
public MutableCapabilities getOptions(Parameter parameter,
        Optional<Object> testInstance)
        throws IOException, IllegalAccessException {
    FirefoxOptions firefoxOptions = new FirefoxOptions();

    if (parameter != null) {
        // @Arguments
        Arguments arguments = parameter.getAnnotation(Arguments.class);
        if (arguments != null) {
            stream(arguments.value()).forEach(firefoxOptions::addArguments);
        }

        // @Extensions
        Extensions extensions = parameter.getAnnotation(Extensions.class);
        if (extensions != null) {
            for (String extension : extensions.value()) {
                FirefoxProfile firefoxProfile = new FirefoxProfile();
                firefoxProfile.addExtension(getExtension(extension));
                firefoxOptions.setProfile(firefoxProfile);
            }
        }

        // @Binary
        Binary binary = parameter.getAnnotation(Binary.class);
        if (binary != null) {
            firefoxOptions.setBinary(binary.value());
        }

        // @Preferences
        managePreferences(parameter, firefoxOptions);

        // @Options
        FirefoxOptions optionsFromAnnotatedField = annotationsReader
                .getFromAnnotatedField(testInstance, Options.class,
                        FirefoxOptions.class);
        if (optionsFromAnnotatedField != null) {
            firefoxOptions = optionsFromAnnotatedField
                    .merge(firefoxOptions);
        }
    }

    return firefoxOptions;
}