Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities#firefox()
The following examples show how to use
org.openqa.selenium.remote.DesiredCapabilities#firefox() .
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: SeleniumDriverHandler.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 6 votes |
public static WebDriver getFirefoxDriver(){ /* Need to have an updated Firefox, but also need to download and put the geckodriver in your own home dir. See: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver https://github.com/mozilla/geckodriver/releases However, drivers for FireFox have been often unstable. Therefore, I do recommend to use Chrome instead */ setupDriverExecutable("geckodriver", "webdriver.gecko.driver"); DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); desiredCapabilities.setCapability("marionette", true); desiredCapabilities.setJavascriptEnabled(true); return new FirefoxDriver(desiredCapabilities); }
Example 2
Source File: SeleniumDriverHandler.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 6 votes |
public static WebDriver getFirefoxDriver(){ /* Need to have an updated Firefox, but also need to download and put the geckodriver in your own home dir. See: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver https://github.com/mozilla/geckodriver/releases However, drivers for FireFox have been often unstable. Therefore, I do recommend to use Chrome instead */ setupDriverExecutable("geckodriver", "webdriver.gecko.driver"); DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); desiredCapabilities.setCapability("marionette", true); desiredCapabilities.setJavascriptEnabled(true); return new FirefoxDriver(desiredCapabilities); }
Example 3
Source File: SeleniumDriverHandler.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 6 votes |
public static WebDriver getFirefoxDriver(){ /* Need to have an updated Firefox, but also need to download and put the geckodriver in your own home dir. See: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver https://github.com/mozilla/geckodriver/releases However, drivers for FireFox have been often unstable. Therefore, I do recommend to use Chrome instead */ setupDriverExecutable("geckodriver", "webdriver.gecko.driver"); DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); desiredCapabilities.setCapability("marionette", true); desiredCapabilities.setJavascriptEnabled(true); return new FirefoxDriver(desiredCapabilities); }
Example 4
Source File: SeleniumTestUtilities.java From Spring-Security-Third-Edition with MIT License | 6 votes |
public static WebDriver getFirefoxDriver() throws Exception { baseDir = new File(".").getPath(); System.out.println("******** " + baseDir); String path = "src/test/resources/geckodriver"; System.out.println("******** " + path); System.setProperty("webdriver.gecko.driver", path); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); capabilities.setCapability("networkConnectionEnabled", true); capabilities.setCapability("browserConnectionEnabled", true); WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444"), capabilities); // WebDriver driver = new MarionetteDriver(capabilities); return driver; }
Example 5
Source File: SeleniumTestUtilities.java From Spring-Security-Third-Edition with MIT License | 6 votes |
public static WebDriver getFirefoxDriver() throws Exception { baseDir = new File(".").getPath(); System.out.println("******** " + baseDir); String path = "src/test/resources/geckodriver"; System.out.println("******** " + path); System.setProperty("webdriver.gecko.driver", path); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); capabilities.setCapability("networkConnectionEnabled", true); capabilities.setCapability("browserConnectionEnabled", true); WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444"), capabilities); // WebDriver driver = new MarionetteDriver(capabilities); return driver; }
Example 6
Source File: SeleniumTestUtilities.java From Spring-Security-Third-Edition with MIT License | 6 votes |
public static WebDriver getFirefoxDriver() throws Exception { baseDir = new File(".").getPath(); System.out.println("******** " + baseDir); String path = "src/test/resources/geckodriver"; System.out.println("******** " + path); System.setProperty("webdriver.gecko.driver", path); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); capabilities.setCapability("networkConnectionEnabled", true); capabilities.setCapability("browserConnectionEnabled", true); WebDriver driver = new RemoteWebDriver( new URL("http://localhost:4444"), capabilities); // WebDriver driver = new MarionetteDriver(capabilities); return driver; }
Example 7
Source File: LogSearchUIStories.java From ambari-logsearch with Apache License 2.0 | 5 votes |
public LogSearchUIStories() { String dockerHost = System.getProperty("docker.host") != null ? System.getProperty("docker.host") : "localhost"; System.setProperty("REMOTE_WEBDRIVER_URL", String.format("http://%s:4444/wd/hub", dockerHost)); DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setPlatform(Platform.LINUX); capability.setVersion("45.8.0"); driverProvider = new RemoteWebDriverProvider(capability); StoryDataRegistry.INSTANCE.setWebDriverProvider(driverProvider); context = new SeleniumContext(); configuredEmbedder().useExecutorService(new SameThreadExecutors().create(configuredEmbedder().embedderControls())); }
Example 8
Source File: RemoteWebRtcFirefoxTest.java From webdrivermanager-examples with Apache License 2.0 | 5 votes |
@Before public void setupTest() throws MalformedURLException { DesiredCapabilities capability = DesiredCapabilities.firefox(); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("media.navigator.permission.disabled", true); profile.setPreference("media.navigator.streams.fake", true); capability.setCapability(FirefoxDriver.PROFILE, profile); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability); }
Example 9
Source File: FirefoxUser.java From openvidu with Apache License 2.0 | 5 votes |
public FirefoxUser(String userName, int timeOfWaitInSeconds) { super(userName, timeOfWaitInSeconds); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setAcceptInsecureCerts(true); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); FirefoxProfile profile = new FirefoxProfile(); // This flag avoids granting the access to the camera profile.setPreference("media.navigator.permission.disabled", true); // This flag force to use fake user media (synthetic video of multiple color) profile.setPreference("media.navigator.streams.fake", true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); String REMOTE_URL = System.getProperty("REMOTE_URL_FIREFOX"); if (REMOTE_URL != null) { log.info("Using URL {} to connect to remote web driver", REMOTE_URL); try { this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } else { log.info("Using local web driver"); this.driver = new FirefoxDriver(capabilities); } this.configureDriver(); }
Example 10
Source File: SeleniumConfig.java From tutorials with MIT License | 5 votes |
public SeleniumConfig() { Capabilities capabilities = DesiredCapabilities.firefox(); driver = new FirefoxDriver(capabilities); driver.manage() .timeouts() .implicitlyWait(5, TimeUnit.SECONDS); }
Example 11
Source File: SeleniumTestUtilities.java From Spring-Security-Third-Edition with MIT License | 5 votes |
public static WebDriver getFirefoxDriver(String pathToFirefoxExecutable) { String path = "src/test/resources/geckodriver"; System.setProperty("webdriver.gecko.driver", path); System.setProperty("webdriver.firefox.bin", pathToFirefoxExecutable); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); capabilities.setCapability("networkConnectionEnabled", true); capabilities.setCapability("browserConnectionEnabled", true); WebDriver driver = new MarionetteDriver(capabilities); return driver; }
Example 12
Source File: SeleniumTestUtilities.java From Spring-Security-Third-Edition with MIT License | 5 votes |
public static WebDriver getFirefoxDriver(String pathToFirefoxExecutable) { String path = "src/test/resources/geckodriver"; System.setProperty("webdriver.gecko.driver", path); System.setProperty("webdriver.firefox.bin", pathToFirefoxExecutable); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("marionette", true); capabilities.setCapability("networkConnectionEnabled", true); capabilities.setCapability("browserConnectionEnabled", true); WebDriver driver = new MarionetteDriver(capabilities); return driver; }
Example 13
Source File: CapabilityConfig.java From phoenix.webui.framework with Apache License 2.0 | 5 votes |
/** * 火狐浏览器配置 */ private void firefox() { DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setCapability("marionette", true); engineCapMap.put(DRIVER_FIREFOX, capability); }
Example 14
Source File: FirefoxRemote.java From at.info-knowledge-base with MIT License | 5 votes |
@BeforeMethod public void setUpProxy() throws Exception { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.PROXY, getProxy()); //or //capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy()); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities); }
Example 15
Source File: SauceLabsWebDriverHelper.java From rice with Educational Community License v2.0 | 4 votes |
/** * <p> * Saucelabs setUp. * </p><p> * Creates a {@link org.openqa.selenium.remote.RemoteWebDriver} instance with the DesiredCapabilities as configured * using the JVM arguments described as SAUCE_ Constants in this class. After setUp the WebDriver can be accessed via * {@see #getDriver}. You'll also need {@see #getSessionId} for when you call {@see #tearDown} * </p> * * @param className class name of the test being setup as a String * @param testName test name of the test being setup as a String * @throws Exception */ public void setUp(String className, String testName) throws Exception { if (System.getProperty(REMOTE_DRIVER_SAUCELABS_PROPERTY) == null) { // dup guard so WebDriverUtils doesn't have to be used. return; } if (System.getProperty(SAUCE_USER_PROPERTY) == null || System.getProperty(SAUCE_KEY_PROPERTY) == null) { Assert.fail("-D" + SAUCE_USER_PROPERTY + " and -D" + SAUCE_KEY_PROPERTY + " must be set to saucelabs user and access key."); } DesiredCapabilities capabilities = null; if ("ff".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.firefox(); } else if ("ie".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, System.getProperty(SAUCE_IE_INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS_PROPERTY, "true")); } else if ("chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.chrome(); } else if ("opera".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.opera(); } else if ("android".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.android(); } else if ("safari".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.safari(); } else if ("ipad".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.ipad(); } else if ("iphone".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.iphone(); } else { capabilities = DesiredCapabilities.firefox(); } String version = System.getProperty(SAUCE_VERSION_PROPERTY); if (version == null || "0".equals(version)) { // Blank or 0 leaves version blank for use with chrome if (!"chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { throw new RuntimeException("Blank or 0 version for a browser not chrome " + System.getProperty(SAUCE_BROWSER_PROPERTY)); } capabilities.setCapability("version", ""); // saucelabs requires blank for chrome (latest version) } else { capabilities.setCapability("version", version); // saucelabs requires blank for chrome (latest version) } capabilities.setCapability("platform", System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()).replaceAll("_", " ")); capabilities.setCapability("idle-timeout", Integer.parseInt(System.getProperty(SAUCE_IDLE_TIMEOUT_SECONDS_PROPERTY, "180"))); capabilities.setCapability("max-duration", Integer.parseInt(System.getProperty(SAUCE_MAX_DURATION_SECONDS_PROPERTY, "600"))); capabilities.setCapability("name", className + "." + testName + "-" + AutomatedFunctionalTestUtils.DTS); capabilities.setCapability("disable-popup-handler", System.getProperty(SAUCE_POPUP_PROPERTY, "false")); capabilities.setCapability("public", System.getProperty(SAUCE_SHARE_PROPERTY, "public restricted")); System.out.println("Requesting Saucelabs RemoteWebDriver with DesiredCapabilities of " + capabilities.toString()); this.driver = new RemoteWebDriver( new URL("http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabilities); this.sessionId = ((RemoteWebDriver)driver).getSessionId().toString(); System.out.println("SauceLabs job can be viewed at https://saucelabs.com/jobs/" + this.sessionId); }
Example 16
Source File: BrowserDriver.java From SWET with MIT License | 4 votes |
@SuppressWarnings("deprecation") private static DesiredCapabilities capabilitiesFirefox() { final String geckoDriverPath = (applicationGeckoDriverPath == null) ? osName.toLowerCase().startsWith("windows") ? "c:/java/selenium/geckodriver.exe" : "/var/run/geckodriver" : applicationGeckoDriverPath; // firefox.browser.path final String firefoxBrowserPath = (applicationFirefoxBrowserPath == null) ? osName.toLowerCase().startsWith("windows") ? "c:/Program Files (x86)/Mozilla Firefox/firefox.exe" : osName.toLowerCase().startsWith("mac") ? "/Applications/Firefox.app/Contents/MacOS/firefox.bin" : "/usr/bin/firefox/firefox" : applicationFirefoxBrowserPath; System.setProperty("webdriver.gecko.driver", new File(geckoDriverPath).getAbsolutePath()); System.setProperty("webdriver.firefox.bin", new File(firefoxBrowserPath).getAbsolutePath()); System.setProperty("webdriver.reap_profile", "false"); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); // TODO: switch to Selenium 3.X+ /* FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setBinary(new File(firefoxBrowserPath).getAbsolutePath()); capabilities.setCapability("moz:firefoxOptions", firefoxOptions); */ capabilities.setCapability("firefox_binary", new File(firefoxBrowserPath).getAbsolutePath()); capabilities.setCapability("marionette", false); FirefoxProfile profile = new FirefoxProfile(); // no longer exists in Selenium // profile.setEnableNativeEvents(true); profile.setAcceptUntrustedCertificates(true); profile.setAssumeUntrustedCertificateIssuer(false); // Disable Firefox Auto-Updating profile.setPreference("app.update.auto", false); profile.setPreference("app.update.enabled", false); capabilities.setCapability(FirefoxDriver.PROFILE, profile); capabilities.setCapability("elementScrollBehavior", 1); capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); return capabilities; }
Example 17
Source File: FirefoxWebDriverProxyTest.java From marathonv5 with Apache License 2.0 | 4 votes |
public FirefoxWebDriverProxyTest() { super(FirefoxWebDriverProxy.class, DesiredCapabilities.firefox()); }
Example 18
Source File: GetNodeDetails.java From selenium-grid2-api with Apache License 2.0 | 4 votes |
@Test public void getNodeDetailsViaTestSession() throws Exception { DesiredCapabilities capability = DesiredCapabilities.firefox(); URL hub = new URL("http://localhost:4444/wd/hub"); WebDriver driver = new RemoteWebDriver(hub, capability); System.out.println("Session Id: " + ((RemoteWebDriver) driver).getSessionId()); GridInfo gridInfo = GridInfoExtractor.getHostNameAndPort(hub.getHost(), hub.getPort(), ((RemoteWebDriver) driver).getSessionId()); System.out.println("I'm running on: " + gridInfo.getHost() + ":" + gridInfo.getPort()); }
Example 19
Source File: CreateDriver.java From Selenium-Framework-Design-in-Data-Driven-Testing with MIT License | 4 votes |
/** * setDriver method to create driver instance * * @param browser * @param environment * @param platform * @param optPreferences * @throws Exception */ @SafeVarargs public final void setDriver(String browser, String platform, String environment, Map<String, Object>... optPreferences) throws Exception { DesiredCapabilities caps = null; String getPlatform = null; props.load(new FileInputStream(Global_VARS.SE_PROPS)); switch (browser) { case "firefox": caps = DesiredCapabilities.firefox(); FirefoxOptions ffOpts = new FirefoxOptions(); FirefoxProfile ffProfile = new FirefoxProfile(); ffProfile.setPreference("browser.autofocus", true); ffProfile.setPreference("browser.tabs.remote.autostart.2", false); caps.setCapability(FirefoxDriver.PROFILE, ffProfile); caps.setCapability("marionette", true); // then pass them to the local WebDriver if ( environment.equalsIgnoreCase("local") ) { System.setProperty("webdriver.gecko.driver", props.getProperty("gecko.driver.windows.path")); webDriver.set(new FirefoxDriver(ffOpts.merge(caps))); } break; case "chrome": caps = DesiredCapabilities.chrome(); ChromeOptions chOptions = new ChromeOptions(); Map<String, Object> chromePrefs = new HashMap<String, Object>(); chromePrefs.put("credentials_enable_service", false); chOptions.setExperimentalOption("prefs", chromePrefs); chOptions.addArguments("--disable-plugins", "--disable-extensions", "--disable-popup-blocking"); caps.setCapability(ChromeOptions.CAPABILITY, chOptions); caps.setCapability("applicationCacheEnabled", false); if ( environment.equalsIgnoreCase("local") ) { System.setProperty("webdriver.chrome.driver", props.getProperty("chrome.driver.windows.path")); webDriver.set(new ChromeDriver(chOptions.merge(caps))); } break; case "internet explorer": caps = DesiredCapabilities.internetExplorer(); InternetExplorerOptions ieOpts = new InternetExplorerOptions(); ieOpts.requireWindowFocus(); ieOpts.merge(caps); caps.setCapability("requireWindowFocus", true); if ( environment.equalsIgnoreCase("local") ) { System.setProperty("webdriver.ie.driver", props.getProperty("ie.driver.windows.path")); webDriver.set(new InternetExplorerDriver(ieOpts.merge(caps))); } break; } getEnv = environment; getPlatform = platform; sessionId.set(((RemoteWebDriver) webDriver.get()).getSessionId().toString()); sessionBrowser.set(caps.getBrowserName()); sessionVersion.set(caps.getVersion()); sessionPlatform.set(getPlatform); System.out.println("\n*** TEST ENVIRONMENT = " + getSessionBrowser().toUpperCase() + "/" + getSessionPlatform().toUpperCase() + "/" + getEnv.toUpperCase() + "/Selenium Version=" + props.getProperty("selenium.revision") + "/Session ID=" + getSessionId() + "\n"); getDriver().manage().timeouts().implicitlyWait(IMPLICIT_TIMEOUT, TimeUnit.SECONDS); getDriver().manage().window().maximize(); }
Example 20
Source File: SeleniumWebDriver.java From che with Eclipse Public License 2.0 | 4 votes |
private RemoteWebDriver doCreateDriver(URL webDriverUrl) { DesiredCapabilities capability; switch (browser) { case GOOGLE_CHROME: LoggingPreferences loggingPreferences = new LoggingPreferences(); loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL); loggingPreferences.enable(LogType.BROWSER, Level.ALL); ChromeOptions options = new ChromeOptions(); options.addArguments("--no-sandbox"); options.addArguments("--dns-prefetch-disable"); options.addArguments("--ignore-certificate-errors"); // set parameters required for automatic download capability Map<String, Object> chromePrefs = new HashMap<>(); chromePrefs.put("download.default_directory", downloadDir); chromePrefs.put("download.prompt_for_download", false); chromePrefs.put("download.directory_upgrade", true); chromePrefs.put("safebrowsing.enabled", true); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("plugins.plugins_disabled", "['Chrome PDF Viewer']"); options.setExperimentalOption("prefs", chromePrefs); capability = DesiredCapabilities.chrome(); capability.setCapability(ChromeOptions.CAPABILITY, options); capability.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences); capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); break; default: capability = DesiredCapabilities.firefox(); capability.setCapability("dom.max_script_run_time", 240); capability.setCapability("dom.max_chrome_script_run_time", 240); } RemoteWebDriver driver = new RemoteWebDriver(webDriverUrl, capability); if (driver.getErrorHandler().isIncludeServerErrors() && driver.getCapabilities().getCapability("message") != null) { String errorMessage = format( "Web driver creation error occurred: %s", driver.getCapabilities().getCapability("message")); LOG.error(errorMessage); throw new RuntimeException(errorMessage); } driver.manage().window().setSize(new Dimension(1920, 1080)); return driver; }