List of usage examples for org.openqa.selenium.firefox FirefoxProfile setAcceptUntrustedCertificates
public void setAcceptUntrustedCertificates(boolean acceptUntrustedSsl)
From source file:org.jboss.pressgang.ccms.page.WebDriverFactory.java
License:Open Source License
private FirefoxProfile makeFirefoxProfile() { if (!Strings.isNullOrEmpty(System.getProperty("webdriver.firefox.profile"))) { throw new RuntimeException("webdriver.firefox.profile is ignored"); // TODO - look at FirefoxDriver.getProfile(). }/* ww w .j a v a 2 s . c om*/ final FirefoxProfile firefoxProfile = new FirefoxProfile(); /* * TODO: Evaluate need for this * Disable unnecessary connection to sb-ssl.google.com * firefoxProfile.setPreference("browser.safebrowsing.malware.enabled", false); */ firefoxProfile.setAlwaysLoadNoFocusLib(true); firefoxProfile.setEnableNativeEvents(true); firefoxProfile.setAcceptUntrustedCertificates(true); return firefoxProfile; }
From source file:org.jitsi.meet.test.ConferenceFixture.java
License:Apache License
/** * Starts a <tt>WebDriver</tt> instance using default settings. * @param browser the browser type.//w w w. j a v a2 s. c o m * @param participant the participant we are creating a driver for. * @return the <tt>WebDriver</tt> instance. */ private static WebDriver startDriverInstance(BrowserType browser, Participant participant) { // by default we load chrome, but we can load safari or firefox if (browser == BrowserType.firefox) { String browserBinary = System.getProperty(BROWSER_FF_BINARY_NAME_PROP); if (browserBinary != null && browserBinary.trim().length() > 0) { File binaryFile = new File(browserBinary); if (binaryFile.exists()) System.setProperty("webdriver.firefox.bin", browserBinary); } FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("media.navigator.permission.disabled", true); // Enables tcp in firefox, disabled by default in 44 profile.setPreference("media.peerconnection.ice.tcp", true); profile.setAcceptUntrustedCertificates(true); profile.setPreference("webdriver.log.file", FailureListener.createLogsFolder() + "/firefox-js-console-" + getParticipantName(participant) + ".log"); System.setProperty("webdriver.firefox.logfile", FailureListener.createLogsFolder() + "/firefox-console-" + getParticipantName(participant) + ".log"); return new FirefoxDriver(profile); } else if (browser == BrowserType.safari) { return new SafariDriver(); } else if (browser == BrowserType.ie) { DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability("ignoreZoomSetting", true); System.setProperty("webdriver.ie.driver.silent", "true"); return new InternetExplorerDriver(caps); } else { System.setProperty("webdriver.chrome.verboseLogging", "true"); System.setProperty("webdriver.chrome.logfile", FailureListener.createLogsFolder() + "/chrome-console-" + getParticipantName(participant) + ".log"); DesiredCapabilities caps = DesiredCapabilities.chrome(); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); final ChromeOptions ops = new ChromeOptions(); ops.addArguments("use-fake-ui-for-media-stream"); ops.addArguments("use-fake-device-for-media-stream"); ops.addArguments("disable-extensions"); ops.addArguments("disable-plugins"); ops.addArguments("mute-audio"); String disProp = System.getProperty(DISABLE_NOSANBOX_PARAM); if (disProp == null && !Boolean.parseBoolean(disProp)) { ops.addArguments("no-sandbox"); ops.addArguments("disable-setuid-sandbox"); } // starting version 46 we see crashes of chrome GPU process when // running in headless mode // which leaves the browser opened and selenium hang forever. // There are reports that in older version crashes like that will // fallback to software graphics, we try to disable gpu for now ops.addArguments("disable-gpu"); String browserProp; if (participant == Participant.secondParticipantDriver) browserProp = BROWSER_CHROME_BINARY_SECOND_NAME_PROP; else browserProp = BROWSER_CHROME_BINARY_OWNER_NAME_PROP; String browserBinary = System.getProperty(browserProp); if (browserBinary != null && browserBinary.trim().length() > 0) { File binaryFile = new File(browserBinary); if (binaryFile.exists()) ops.setBinary(binaryFile); } if (fakeStreamAudioFName != null) { ops.addArguments("use-file-for-fake-audio-capture=" + fakeStreamAudioFName); } if (fakeStreamVideoFName != null) { ops.addArguments("use-file-for-fake-video-capture=" + fakeStreamVideoFName); } //ops.addArguments("vmodule=\"*media/*=3,*turn*=3\""); ops.addArguments("enable-logging"); ops.addArguments("vmodule=*=3"); caps.setCapability(ChromeOptions.CAPABILITY, ops); try { final ExecutorService pool = Executors.newFixedThreadPool(1); // we will retry four times for 1 minute to obtain // the chrome driver, on headless environments chrome hangs // and we wait forever for (int i = 0; i < 2; i++) { Future<ChromeDriver> future = null; try { future = pool.submit(new Callable<ChromeDriver>() { @Override public ChromeDriver call() throws Exception { long start = System.currentTimeMillis(); ChromeDriver resDr = new ChromeDriver(ops); System.err.println("ChromeDriver created for:" + (System.currentTimeMillis() - start) + " ms."); return resDr; } }); ChromeDriver res = future.get(2, TimeUnit.MINUTES); if (res != null) return res; } catch (TimeoutException te) { // cancel current task if (future != null) future.cancel(true); System.err.println("Timeout waiting for " + "chrome instance! We will retry now, this was our" + "attempt " + i); } } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } // keep the old code System.err.println("Just create ChromeDriver, may hang!"); return new ChromeDriver(ops); } }
From source file:org.jitsi.meet.test.web.WebParticipantFactory.java
License:Apache License
/** * Starts a <tt>WebDriver</tt> instance using default settings. * @param options the options to use when creating the driver. * @return the <tt>WebDriver</tt> instance. *///www .j a v a 2s . c o m private WebDriver startWebDriver(WebParticipantOptions options) { ParticipantType participantType = options.getParticipantType(); String version = options.getVersion(); File browserBinaryAPath = getFile(options, options.getBinary()); boolean isRemote = options.isRemote(); // by default we load chrome, but we can load safari or firefox if (participantType.isFirefox()) { FirefoxDriverManager.getInstance().setup(); if (browserBinaryAPath != null && (browserBinaryAPath.exists() || isRemote)) { System.setProperty("webdriver.firefox.bin", browserBinaryAPath.getAbsolutePath()); } FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("media.navigator.permission.disabled", true); // Enables tcp in firefox, disabled by default in 44 profile.setPreference("media.peerconnection.ice.tcp", true); profile.setPreference("media.navigator.streams.fake", true); profile.setAcceptUntrustedCertificates(true); profile.setPreference("webdriver.log.file", FailureListener.createLogsFolder() + "/firefox-js-console-" + options.getName() + ".log"); System.setProperty("webdriver.firefox.logfile", FailureListener.createLogsFolder() + "/firefox-console-" + options.getName() + ".log"); if (isRemote) { FirefoxOptions ffOptions = new FirefoxOptions(); ffOptions.setProfile(profile); if (version != null && version.length() > 0) { ffOptions.setCapability(CapabilityType.VERSION, version); } return new RemoteWebDriver(options.getRemoteDriverAddress(), ffOptions); } return new FirefoxDriver(new FirefoxOptions().setProfile(profile)); } else if (participantType == ParticipantType.safari) { // You must enable the 'Allow Remote Automation' option in // Safari's Develop menu to control Safari via WebDriver. // In Safari->Preferences->Websites, select Camera, // and select Allow for "When visiting other websites" if (isRemote) { return new RemoteWebDriver(options.getRemoteDriverAddress(), new SafariOptions()); } return new SafariDriver(); } else if (participantType == ParticipantType.edge) { InternetExplorerDriverManager.getInstance().setup(); InternetExplorerOptions ieOptions = new InternetExplorerOptions(); ieOptions.ignoreZoomSettings(); System.setProperty("webdriver.ie.driver.silent", "true"); return new InternetExplorerDriver(ieOptions); } else { ChromeDriverManager.getInstance().setup(); System.setProperty("webdriver.chrome.verboseLogging", "true"); System.setProperty("webdriver.chrome.logfile", FailureListener.createLogsFolder() + "/chrome-console-" + options.getName() + ".log"); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); final ChromeOptions ops = new ChromeOptions(); ops.addArguments("use-fake-ui-for-media-stream"); ops.addArguments("use-fake-device-for-media-stream"); ops.addArguments("disable-plugins"); ops.addArguments("mute-audio"); ops.addArguments("disable-infobars"); // Since chrome v66 there are new autoplay policies, which broke // shared video tests, disable no-user-gesture to make it work ops.addArguments("autoplay-policy=no-user-gesture-required"); if (options.getChromeExtensionId() != null) { try { ops.addExtensions(downloadExtension(options.getChromeExtensionId())); } catch (IOException e) { throw new RuntimeException(e); } } ops.addArguments("auto-select-desktop-capture-source=Entire screen"); ops.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); if (options.isChromeSandboxDisabled()) { ops.addArguments("no-sandbox"); ops.addArguments("disable-setuid-sandbox"); } if (options.isHeadless()) { ops.addArguments("headless"); ops.addArguments("window-size=1200x600"); } // starting version 46 we see crashes of chrome GPU process when // running in headless mode // which leaves the browser opened and selenium hang forever. // There are reports that in older version crashes like that will // fallback to software graphics, we try to disable gpu for now ops.addArguments("disable-gpu"); if (browserBinaryAPath != null && (browserBinaryAPath.exists() || isRemote)) { ops.setBinary(browserBinaryAPath.getAbsolutePath()); } File uplinkFile = getFile(options, options.getUplink()); if (uplinkFile != null) { ops.addArguments("uplink=" + uplinkFile.getAbsolutePath()); } File downlinkFile = getFile(options, options.getDownlink()); if (downlinkFile != null) { ops.addArguments("downlink=" + downlinkFile.getAbsolutePath()); } String profileDirectory = options.getProfileDirectory(); if (profileDirectory != null && profileDirectory != "") { ops.addArguments("user-data-dir=" + profileDirectory); } File fakeStreamAudioFile = getFile(options, options.getFakeStreamAudioFile()); if (fakeStreamAudioFile != null) { ops.addArguments("use-file-for-fake-audio-capture=" + fakeStreamAudioFile.getAbsolutePath()); } File fakeStreamVideoFile = getFile(options, options.getFakeStreamVideoFile()); if (fakeStreamVideoFile != null) { ops.addArguments("use-file-for-fake-video-capture=" + fakeStreamVideoFile.getAbsolutePath()); } //ops.addArguments("vmodule=\"*media/*=3,*turn*=3\""); ops.addArguments("enable-logging"); ops.addArguments("vmodule=*=3"); if (isRemote) { if (version != null && version.length() > 0) { ops.setCapability(CapabilityType.VERSION, version); } return new RemoteWebDriver(options.getRemoteDriverAddress(), ops); } try { final ExecutorService pool = Executors.newFixedThreadPool(1); // we will retry four times for 1 minute to obtain // the chrome driver, on headless environments chrome hangs // and we wait forever for (int i = 0; i < 2; i++) { Future<ChromeDriver> future = null; try { future = pool.submit(() -> { long start = System.currentTimeMillis(); ChromeDriver resDr = new ChromeDriver(ops); TestUtils.print( "ChromeDriver created for:" + (System.currentTimeMillis() - start) + " ms."); return resDr; }); ChromeDriver res = future.get(2, TimeUnit.MINUTES); if (res != null) return res; } catch (TimeoutException te) { // cancel current task future.cancel(true); TestUtils.print("Timeout waiting for " + "chrome instance! We will retry now, this was our" + "attempt " + i); } } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } // keep the old code TestUtils.print("Just create ChromeDriver, may hang!"); return new ChromeDriver(ops); } }
From source file:org.jwatter.browser.FirefoxWebAutomationFramework.java
License:Apache License
/** * Creates a new Firefox browser instance with a blank window. * /*from w ww . j a v a 2 s . c o m*/ * @throws Exception * if an error occurs */ @Override public void createBrowser() throws Exception { FirefoxProfile profile = new FirefoxProfile(); profile.setAcceptUntrustedCertificates(false); browser = new FirefoxDriver(profile); initBrowser(); }
From source file:org.jwatter.browser.FirefoxWebAutomationFramework.java
License:Apache License
/** * Creates a new Firefox browser instance with a blank window, using the specified * profile./* w ww.j a v a 2 s .co m*/ * * @param profileName * the name of the profile to use * @throws Exception * if an error occurs */ @Override public void createBrowser(String profileName) throws Exception { FirefoxProfile profile = new ProfilesIni().getProfile(profileName); if (profile == null) { throw new NoSuchProfileException(profileName); } profile.setAcceptUntrustedCertificates(false); browser = new FirefoxDriver(profile); initBrowser(); }
From source file:org.openlmis.UiUtils.DriverFactory.java
License:Open Source License
private WebDriver createFirefoxDriver(boolean enableJavascript) { boolean headless = Boolean.parseBoolean(getProperty("headless", "false")); FirefoxProfile profile = new FirefoxProfile(); profile.setAcceptUntrustedCertificates(true); profile.setPreference("signed.applets.codebase_principal_support", true); profile.setPreference("javascript.enabled", enableJavascript); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv"); profile.setPreference("browser.download.dir", new File(System.getProperty("user.dir")).getParent()); profile.setPreference("browser.download.folderList", 2); profile.setPreference("dom.storage.enabled", true); profile.setPreference("device.storage.enabled", true); if ((getProperty("os.name").toLowerCase().contains("mac")) && headless) { String LOCAL_FIREFOX_X11_PATH = "/opt/local/bin/firefox-x11"; File binaryFile = new File(LOCAL_FIREFOX_X11_PATH); FirefoxBinary binary = new FirefoxBinary(binaryFile); String LOCAL_X11_DISPLAY = ":5"; binary.setEnvironmentProperty("DISPLAY", LOCAL_X11_DISPLAY); return new FirefoxDriver(binary, profile); }//from ww w . jav a2s . c o m return new FirefoxDriver(profile); }
From source file:org.securitytests.cisecurity.drivers.DriverFactory.java
License:Open Source License
public WebDriver createFirefoxDriver(DesiredCapabilities capabilities) { if (capabilities != null) { return new FirefoxDriver(capabilities); }/* ww w .j a v a2 s .co m*/ ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile myProfile = allProfiles.getProfile("WebDriver"); if (myProfile == null) { File ffDir = new File(System.getProperty("user.dir") + File.separator + "ffProfile"); if (!ffDir.exists()) { ffDir.mkdir(); } myProfile = new FirefoxProfile(ffDir); } myProfile.setAcceptUntrustedCertificates(true); myProfile.setAssumeUntrustedCertificateIssuer(true); myProfile.setPreference("webdriver.load.strategy", "unstable"); if (capabilities == null) { capabilities = new DesiredCapabilities(); } capabilities.setCapability(FirefoxDriver.PROFILE, myProfile); return new FirefoxDriver(capabilities); }
From source file:org.zanata.page.WebDriverFactory.java
License:Open Source License
private FirefoxProfile makeFirefoxProfile() { if (!Strings.isNullOrEmpty(System.getProperty("webdriver.firefox.profile"))) { throw new RuntimeException("webdriver.firefox.profile is ignored"); // TODO - look at FirefoxDriver.getProfile(). }//from w ww . j a va2 s . com final FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setAlwaysLoadNoFocusLib(true); firefoxProfile.setEnableNativeEvents(true); firefoxProfile.setAcceptUntrustedCertificates(true); // TODO port zanata-testing-extension to firefox // File file = new File("extension.xpi"); // firefoxProfile.addExtension(file); return firefoxProfile; }
From source file:test.firefox.FirefoxTest.java
License:Open Source License
public static void firefox(String baseurl, boolean useKeycloak) { WebDriver driver = null;/*w w w . java 2s.c om*/ try { ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile myProfile = allProfiles.getProfile("default"); myProfile.setAcceptUntrustedCertificates(true); myProfile.setAssumeUntrustedCertificateIssuer(false); FirefoxDriverManager.getInstance().setup(); driver = new FirefoxDriver(myProfile); driver.manage().window().setSize(new Dimension(Utils.WINDOW_WIDTH, Utils.WINDOW_HEIGHT)); driver.manage().timeouts().implicitlyWait(Utils.DEFAULT_WAITING_TIME, TimeUnit.SECONDS); TestScenario.useKeycloak = useKeycloak; TestScenario.test(driver, baseurl); } finally { if (driver != null) { driver.quit(); } } }