var driver = new FirefoxDriver(new FirefoxOptions());
@BeforeEach public void setup(@TempDirectory.TempDir Path folder) throws IOException { Assumptions.assumeTrue(Boolean.getBoolean("smoke.test"), "Smoke tests disabled (set System property 'smoke.test')"); this.downloadDir = folder.toFile(); FirefoxProfile fxProfile = new FirefoxProfile(); fxProfile.setPreference("browser.download.folderList", 2); fxProfile.setPreference("browser.download.manager.showWhenStarting", false); fxProfile.setPreference("browser.download.dir", this.downloadDir.getAbsolutePath()); fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip,application/x-compress,application/octet-stream"); FirefoxOptions options = new FirefoxOptions().setProfile(fxProfile); this.driver = new FirefoxDriver(options); ((JavascriptExecutor) this.driver).executeScript("window.focus();"); Actions actions = new Actions(this.driver); this.enterAction = actions.sendKeys(Keys.ENTER).build(); }
private Capabilities getHeadlessCapabilities(Config config, Browser browser) { log.info("Starting in headless mode"); if (browser.isChrome()) { ChromeOptions options = new ChromeOptions(); options.setHeadless(config.headless()); return options; } else if (browser.isFirefox()) { FirefoxOptions options = new FirefoxOptions(); options.setHeadless(config.headless()); return options; } else { log.warning("Headless mode on remote server is only supported for Chrome/Firefox, setting will be ignored."); } return new DesiredCapabilities(); }
FirefoxOptions createFirefoxOptions(Config config, Proxy proxy) { FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setHeadless(config.headless()); if (!config.browserBinary().isEmpty()) { log.info("Using browser binary: " + config.browserBinary()); firefoxOptions.setBinary(config.browserBinary()); } firefoxOptions.addPreference("network.automatic-ntlm-auth.trusted-uris", "http://,https://"); firefoxOptions.addPreference("network.automatic-ntlm-auth.allow-non-fqdn", true); firefoxOptions.addPreference("network.negotiate-auth.delegation-uris", "http://,https://"); firefoxOptions.addPreference("network.negotiate-auth.trusted-uris", "http://,https://"); firefoxOptions.addPreference("network.http.phishy-userpass-length", 255); firefoxOptions.addPreference("security.csp.enable", false); firefoxOptions.addPreference("network.proxy.no_proxies_on", ""); firefoxOptions.merge(createCommonCapabilities(config, proxy)); firefoxOptions = transferFirefoxProfileFromSystemProperties(firefoxOptions); return firefoxOptions; }
private FirefoxOptions transferFirefoxProfileFromSystemProperties(FirefoxOptions currentFirefoxOptions) { String prefix = "firefoxprofile."; FirefoxProfile profile = Optional.ofNullable(currentFirefoxOptions.getProfile()) .orElseGet(FirefoxProfile::new); for (String key : System.getProperties().stringPropertyNames()) { if (key.startsWith(prefix)) { String capability = key.substring(prefix.length()); String value = System.getProperties().getProperty(key); log.config("Use " + key + "=" + value); if (value.equals("true") || value.equals("false")) { profile.setPreference(capability, Boolean.valueOf(value)); } else if (value.matches("^-?\\d+$")) { //if integer profile.setPreference(capability, Integer.parseInt(value)); } else { profile.setPreference(capability, value); } } } return currentFirefoxOptions.setProfile(profile); } }
@Override public WebDriver getDriver() { FirefoxProfile profile = getFirefoxProfile(Locale.GERMANY); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(profile); LogManager.getLogger().info("is headless: {}", isHeadless()); firefoxOptions.setHeadless(isHeadless()); FirefoxDriver firefoxDriver = new FirefoxDriver(firefoxOptions); firefoxDriver.manage().window().setSize(new Dimension(dimX, dimY)); firefoxDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); return firefoxDriver; }
FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setHeadless(isHeadless()); if (isProfilePathSet()) { firefoxOptions.setProfile(new FirefoxProfile(new File(profilePath))); firefoxOptions.addPreference("network.proxy.type", 1); firefoxOptions.addPreference("network.proxy.http", proxyAddress); firefoxOptions.addPreference("network.proxy.http_port", proxyPort); firefoxOptions.addPreference("network.proxy.ssl", proxyAddress); firefoxOptions.addPreference("network.proxy.ssl_port", proxyPort); firefoxOptions.addPreference("network.proxy.share_proxy_settings", true); firefoxOptions.addPreference("network.proxy.no_proxies_on", ""); firefoxOptions.merge(cap);
@Override public WebDriver getWebDriver(Capabilities capabilities) { final FirefoxOptions firefoxOptions; if (capabilities instanceof FirefoxOptions) { firefoxOptions = (FirefoxOptions) capabilities; } else { firefoxOptions = new FirefoxOptions().merge(capabilities); } return new FirefoxDriver(firefoxOptions); } }
@Override public FirefoxOptions getCapabilities() { FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setHeadless(Property.HEADLESS.getBoolean()); firefoxOptions.setLogLevel(FirefoxDriverLogLevel.INFO); return firefoxOptions; }
Capabilities getBrowserBinaryCapabilities(Config config, Browser browser) { log.info("Using browser binary: " + config.browserBinary()); if (browser.isChrome()) { ChromeOptions options = new ChromeOptions(); options.setBinary(config.browserBinary()); return options; } else if (browser.isFirefox()) { FirefoxOptions options = new FirefoxOptions(); options.setBinary(config.browserBinary()); return options; } else { log.warning("Changing browser binary on remote server is only supported for Chrome/Firefox, setting will be ignored."); } return new DesiredCapabilities(); }
if (jobConfig.browser.isFirefox()) { WebDriverManager.firefoxdriver().setup(); FirefoxOptions options = new FirefoxOptions(); options.setProfile(getFirefoxProfileWithDisabledAnimatedGifs()); options.addArguments(runStepConfig.getFirefoxParameters()); if (jobConfig.browser.isHeadless()) { options.setHeadless(true); options.addArguments("-width", width + "", "-height", jobConfig.windowHeight + ""); LOG.debug("Creating firefox with options: {}", options.toString()); driver = new FirefoxDriver(options); } else if (jobConfig.browser.isChrome()) {
@Override public void setDriverOptions() { Proxy proxy = new Proxy(); options = new FirefoxOptions(); options.setHeadless(drHeadless); options.setCapability(PROXY, proxy); options.setCapability(ACCEPT_SSL_CERTS, drAcceptSsl); options.setCapability(SUPPORTS_APPLICATION_CACHE, drSupportCache); options.setCapability(SUPPORTS_ALERTS, drAlertsHandled); options.setUnhandledPromptBehaviour(ACCEPT); break; case DISMISS: options.setUnhandledPromptBehaviour(DISMISS); break; case IGNORE: options.setUnhandledPromptBehaviour(IGNORE); break; default: options.setUnhandledPromptBehaviour(DISMISS); break; options.addArguments(format("user-data-dir=%s", drCustomProfileDir)); options.setAcceptInsecureCerts(drAllowInsecureContent); options.addPreference("download.prompt_for_download", drPromptForDl); options.addPreference("download.default_directory", driverDlPath);
WebDriverManager.firefoxdriver().setup(); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.addPreference("media.navigator.permission.disabled", true); firefoxOptions.addPreference("media.navigator.streams.fake", true); firefoxOptions.setAcceptInsecureCerts(true); capabilities.setBrowserName(firefoxOptions.getBrowserName()); File xpi = File.createTempFile(extension.keySet().iterator().next(), ".xpi"); FileUtils.copyInputStreamToFile(is, xpi); firefoxOptions.getProfile().addExtension(xpi); } catch (Throwable t) { log.error("Error loading Firefox extension {} ({} : {})", extension, t.getClass(),
Optional<Object> testInstance) throws IOException, IllegalAccessException { FirefoxOptions firefoxOptions = new FirefoxOptions(); FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.addExtension(getExtension(extension)); firefoxOptions.setProfile(firefoxProfile); firefoxOptions.setBinary(binary.value()); if (optionsFromAnnotatedField != null) { firefoxOptions = optionsFromAnnotatedField .merge(firefoxOptions);
/** * Задает 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; }
@Override public FirefoxOptions getDefaultOptions() { FirefoxOptions opt = new FirefoxOptions(); opt.addPreference("browser.startup.homepage", "about:blank"); opt.addPreference("startup.homepage_welcome_url", "about:blank"); opt.addPreference("startup.homepage_welcome_url.additional", "about:blank"); return opt; }
String profilePath = System.getProperty("firefox.profile.path"); FirefoxOptions options = new FirefoxOptions(); if (firefoxPath != null) { options.setBinary(new FirefoxBinary(new File(firefoxPath))); File profileDir = new File(profilePath); FirefoxProfile profile = new FirefoxProfile(profileDir); options.setProfile(profile);
FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setProfile(firefoxProfile); if (browser.isHeadless()) { firefoxOptions.addArguments("-headless"); firefoxOptions.addArguments(flag);
private WebDriver createWebDriver(DriverManagerType driverManagerType) throws IllegalArgumentException, WebDriverManagerException { switch (driverManagerType) { case CHROME: ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setHeadless(true); chromeOptions.addArguments(jooUnitWebDriverBrowserArguments); getLog().info("Starting Chrome with " + jooUnitWebDriverBrowserArguments.size() + " arguments: " + String.join(" ", jooUnitWebDriverBrowserArguments)); return new ChromeDriver(chromeOptions); case FIREFOX: FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setHeadless(true); firefoxOptions.addArguments(jooUnitWebDriverBrowserArguments); getLog().info("Starting Firefox with " + jooUnitWebDriverBrowserArguments.size() + " arguments: " + String.join(" ", jooUnitWebDriverBrowserArguments)); return new FirefoxDriver(firefoxOptions); case EDGE: return new EdgeDriver(); // no headless mode and no arguments yet :-( case IEXPLORER: return new InternetExplorerDriver(); // no headless mode and no arguments yet :-( case OPERA: return new OperaDriver(); // no headless mode and no arguments yet :-( } throw new IllegalArgumentException(); }
@Override protected FirefoxOptions getBrowserSpecificOptions() { getLogger().debug("creating capabilities for Firefox"); FirefoxOptions options = new FirefoxOptions(); FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setAcceptUntrustedCertificates(true); firefoxProfile.setAssumeUntrustedCertificateIssuer(false); options.setCapability(FirefoxDriver.PROFILE, firefoxProfile); return options; }