org.openqa.selenium.firefox.FirefoxOptions#setProfile ( )源码实例Demo

下面列出了org.openqa.selenium.firefox.FirefoxOptions#setProfile ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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();
        }

    }
 
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");
    }
 
源代码3 项目: submarine   文件: FirefoxWebDriverProvider.java
@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);
}
 
源代码4 项目: JYTB   文件: BotWorker.java
/**
     * 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");
    }
 
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");
    }
 
源代码6 项目: viritin   文件: VaadinLocaleTest.java
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);
}
 
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);
}
 
源代码8 项目: QVisual   文件: WebDriverCapabilities.java
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);
}
 
源代码9 项目: selenium-jupiter   文件: FirefoxDriverHandler.java
@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;
}