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

The following examples show how to use org.openqa.selenium.firefox.FirefoxOptions#setHeadless() . 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: WebDriverCreator.java    From webtau with Apache License 2.0 6 votes vote down vote up
private static FirefoxDriver createFirefoxDriver() {
    FirefoxOptions options = new FirefoxOptions();

    if (BrowserConfig.getFirefoxBinPath() != null) {
        options.setBinary(BrowserConfig.getFirefoxBinPath());
    }

    if (BrowserConfig.getFirefoxDriverPath() != null) {
        System.setProperty(FIREFOX_DRIVER_PATH_KEY, BrowserConfig.getChromeDriverPath().toString());
    }

    if (BrowserConfig.isHeadless()) {
        options.setHeadless(true);
    }

    if (System.getProperty(FIREFOX_DRIVER_PATH_KEY) == null) {
        setupDriverManagerConfig();
        downloadDriverMessage("firefox");
        WebDriverManager.firefoxdriver().setup();
    }

    return new FirefoxDriver(options);
}
 
Example 2
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 3
Source File: CustomDriverProvider.java    From akita with Apache License 2.0 5 votes vote down vote up
/**
 * Задает options для запуска Firefox драйвера
 * options можно передавать, как системную переменную, например -Doptions=--load-extension=my-custom-extension
 *
 * @return FirefoxOptions
 */
private FirefoxOptions getFirefoxDriverOptions(DesiredCapabilities capabilities) {
    log.info("---------------Firefox Driver---------------------");
    FirefoxOptions firefoxOptions = !options[0].equals("") ? new FirefoxOptions().addArguments(options) : new FirefoxOptions();
    capabilities.setVersion(loadSystemPropertyOrDefault(CapabilityType.BROWSER_VERSION, VERSION_LATEST));
    firefoxOptions.setHeadless(getHeadless());
    firefoxOptions.merge(capabilities);
    return firefoxOptions;
}
 
Example 4
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 5
Source File: SearchTestWithFirefoxHeadless.java    From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License 3 votes vote down vote up
@BeforeMethod
public void setup() {


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

    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setHeadless(true);

    driver = new FirefoxDriver(firefoxOptions);

    driver.get("http://demo-store.seleniumacademy.com/");

}