org.openqa.selenium.firefox.FirefoxOptions Java Examples
The following examples show how to use
org.openqa.selenium.firefox.FirefoxOptions.
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: FirefoxCustomProfile.java From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License | 7 votes |
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(); } }
Example #2
Source File: FirefoxDriverHandler.java From selenium-jupiter with Apache License 2.0 | 6 votes |
@Override public void resolve() { try { Optional<Object> testInstance = context.getTestInstance(); Optional<Capabilities> capabilities = annotationsReader .getCapabilities(parameter, testInstance); FirefoxOptions firefoxOptions = (FirefoxOptions) getOptions( parameter, testInstance); if (capabilities.isPresent()) { firefoxOptions.merge(capabilities.get()); } object = new FirefoxDriver(firefoxOptions); } catch (Exception e) { handleException(e); } }
Example #3
Source File: BrowserWebDriverContainerTest.java From testcontainers-java with MIT License | 6 votes |
@Test public void createContainerWithoutShmVolume() { try ( BrowserWebDriverContainer webDriverContainer = new BrowserWebDriverContainer<>() .withSharedMemorySize(512 * FileUtils.ONE_MB) .withCapabilities(new FirefoxOptions()) ) { webDriverContainer.start(); assertEquals("Shared memory size is configured", 512 * FileUtils.ONE_MB, webDriverContainer.getShmSize()); assertEquals("No shm mounts present", emptyList(), shmVolumes(webDriverContainer)); } }
Example #4
Source File: ProxyBasedIT.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Test public void usingAProxyToTrackNetworkTrafficStep2() { BrowserMobProxy browserMobProxy = new BrowserMobProxyServer(); browserMobProxy.start(); Proxy seleniumProxyConfiguration = ClientUtil.createSeleniumProxy(browserMobProxy); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setCapability(CapabilityType.PROXY, seleniumProxyConfiguration); driver = new FirefoxDriver(firefoxOptions); browserMobProxy.newHar(); driver.get("https://www.google.co.uk"); Har httpArchive = browserMobProxy.getHar(); assertThat(getHTTPStatusCode("https://www.google.co.uk/", httpArchive)) .isEqualTo(200); }
Example #5
Source File: WebDriverCreator.java From webtau with Apache License 2.0 | 6 votes |
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 #6
Source File: AbstractWebDriverPoolTest.java From webdriver-factory with Apache License 2.0 | 6 votes |
@Test public void testCanInstantiateARemoteDriver() throws MalformedURLException { factory.setRemoteDriverProvider(new RemoteDriverProvider() { @Override public WebDriver createDriver(URL hub, Capabilities capabilities) { return new FakeWebDriver(capabilities); } }); WebDriver driver = factory.getDriver(new URL("http://localhost/"), new FirefoxOptions()); assertTrue(driver instanceof FakeWebDriver); assertFalse(factory.isEmpty()); factory.dismissDriver(driver); assertTrue(factory.isEmpty()); }
Example #7
Source File: DriverFactory.java From restful-booker-platform with GNU General Public License v3.0 | 6 votes |
private WebDriver prepareRemoteDriver(){ if(System.getenv("SAUCE_USERNAME") == null){ throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs account name to the environmental variable 'sauce_username'"); } if(System.getenv("SAUCE_ACCESS_KEY") == null){ throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs access key to the environmental variable 'sauce_access_key'"); } String URL = "http://" + System.getenv("SAUCE_USERNAME") + ":" + System.getenv("SAUCE_ACCESS_KEY") + "@ondemand.saucelabs.com:80/wd/hub"; FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setCapability("screenResolution", "1440x900"); try { return new RemoteWebDriver(new URL(URL), firefoxOptions); } catch (MalformedURLException e) { throw new RuntimeException("WARN: An error occurred attempting to create a remote driver connection. See the following error: " + e); } }
Example #8
Source File: FirefoxDevice.java From agent with MIT License | 6 votes |
@Override protected Capabilities newCaps(Capabilities capsToMerge) { FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setAcceptInsecureCerts(true); // **** 以上capabilities可被传入的caps覆盖 **** firefoxOptions.merge(capsToMerge); // **** 以下capabilities具有更高优先级,将覆盖传入的caps **** if (!StringUtils.isEmpty(browser.getPath())) { firefoxOptions.setBinary(browser.getPath()); } return firefoxOptions; }
Example #9
Source File: FirefoxFrozenPreferences.java From Selenium-WebDriver-3-Practical-Guide-Second-Edition with MIT License | 6 votes |
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"); }
Example #10
Source File: W3CRemoteDriverTest.java From selenium with Apache License 2.0 | 6 votes |
@Test @Ignore public void shouldPreferMarionette() { // Make sure we have at least one of the services available Capabilities caps = new FirefoxOptions(); RemoteWebDriverBuilder.Plan plan = RemoteWebDriver.builder() .addAlternative(caps) .getPlan(); assertThat(new XpiDriverService.Builder().score(caps)).isEqualTo(0); assertThat(new GeckoDriverService.Builder().score(caps)).isEqualTo(1); assertThat(plan.isUsingDriverService()).isTrue(); assertThat(plan.getDriverService().getClass()).isEqualTo(GeckoDriverService.class); }
Example #11
Source File: FirefoxAnnotationReaderTest.java From selenium-jupiter with Apache License 2.0 | 6 votes |
@ParameterizedTest @MethodSource("testClassProvider") @SuppressWarnings("unchecked") void testFirefoxOptions(Class<?> testClass) throws Exception { Parameter parameter = testClass .getMethod("webrtcTest", FirefoxDriver.class) .getParameters()[0]; Optional<Object> testInstance = Optional.of(testClass.newInstance()); FirefoxOptions firefoxOptions = (FirefoxOptions) annotationsReader .getOptions(parameter, testInstance); Map<String, Map<String, Boolean>> options = (Map<String, Map<String, Boolean>>) firefoxOptions .asMap().get(FIREFOX_OPTIONS); assertTrue(options.get("prefs") .get("media.navigator.permission.disabled")); assertTrue(options.get("prefs").get("media.navigator.streams.fake")); }
Example #12
Source File: WebDriverTypeTests.java From vividus with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private static DesiredCapabilities testGetFirefoxWebDriver(WebDriverConfiguration configuration) throws Exception { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); FirefoxOptions firefoxOptions = new FirefoxOptions(); whenNew(FirefoxOptions.class).withArguments(desiredCapabilities).thenReturn(firefoxOptions); whenNew(FirefoxOptions.class).withNoArguments().thenReturn(firefoxOptions); FirefoxDriver expected = mock(FirefoxDriver.class); whenNew(FirefoxDriver.class).withParameterTypes(FirefoxOptions.class).withArguments(firefoxOptions) .thenReturn(expected); WebDriver actual = WebDriverType.FIREFOX.getWebDriver(desiredCapabilities, configuration); assertEquals(expected, actual); Map<String, Object> options = (Map<String, Object>) desiredCapabilities .getCapability(FirefoxOptions.FIREFOX_OPTIONS); Map<String, Object> prefs = (Map<String, Object>) options.get("prefs"); assertEquals("about:blank", prefs.get("startup.homepage_welcome_url.additional")); return desiredCapabilities; }
Example #13
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void testGetRemoteWebDriverFirefoxDriver() throws MalformedURLException { mockCapabilities(remoteWebDriver); setRemoteDriverUrl(); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(new FirefoxOptions()); when(remoteWebDriverFactory.getRemoteWebDriver(eq(URL.toURL()), argThat(caps -> { Map<String, Object> options = (Map<String, Object>) caps.getCapability(FirefoxOptions.FIREFOX_OPTIONS); Map<String, Object> prefs = (Map<String, Object>) options.get("prefs"); return "about:blank".equals(prefs.get("startup.homepage_welcome_url.additional")) && "firefox".equals(caps.getBrowserName()); }))).thenReturn(remoteWebDriver); Timeouts timeouts = mockTimeouts(remoteWebDriver); assertEquals(remoteWebDriver, ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #14
Source File: InternalSelenseTestBase.java From selenium with Apache License 2.0 | 5 votes |
private Capabilities createCapabilities() { String property = System.getProperty("selenium.browser", "ff"); Browser browser = Browser.detect(); switch (browser) { case CHROME: return new ChromeOptions(); case EDGE: return new EdgeHtmlOptions(); case CHROMIUMEDGE: return new EdgeOptions(); case IE: return new InternetExplorerOptions(); case FIREFOX: case MARIONETTE: return new FirefoxOptions(); case OPERA: case OPERABLINK: return new OperaOptions(); case SAFARI: return new SafariOptions(); default: fail("Attempt to use an unsupported browser: " + property); // we never get here, but keep null checks happy anyway return new DesiredCapabilities(); } }
Example #15
Source File: W3CRemoteDriverTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void oneOfWillClearOutTheCurrentlySetCapabilities() { RemoteWebDriverBuilder builder = RemoteWebDriver.builder() .addAlternative(new ChromeOptions()) .oneOf(new FirefoxOptions()); List<Capabilities> allCaps = listCapabilities(builder); assertThat(allCaps).hasSize(1); assertThat(allCaps.get(0).getBrowserName()).isEqualTo("firefox"); }
Example #16
Source File: W3CRemoteDriverTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void shouldSetCapabilityToOptionsAddedAfterTheCallToSetCapabilities() { RemoteWebDriverBuilder builder = RemoteWebDriver.builder() .addAlternative(new FirefoxOptions()) .setCapability("se:cheese", "brie") .addAlternative(new ChromeOptions()); // We expect the global to be in the "alwaysMatch" section for obvious reasons, but that's not // a requirement. Get the capabilities and check each of them. List<Capabilities> allCaps = listCapabilities(builder); assertThat(allCaps).hasSize(2); assertThat(allCaps.get(0).getCapability("se:cheese")).isEqualTo("brie"); assertThat(allCaps.get(1).getCapability("se:cheese")).isEqualTo("brie"); }
Example #17
Source File: W3CRemoteDriverTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void shouldAllowCapabilitiesToBeSetGlobally() { RemoteWebDriverBuilder builder = RemoteWebDriver.builder() .addAlternative(new FirefoxOptions()) .addAlternative(new ChromeOptions()) .setCapability("se:cheese", "brie"); // We expect the global to be in the "alwaysMatch" section for obvious reasons, but that's not // a requirement. Get the capabilities and check each of them. List<Capabilities> allCaps = listCapabilities(builder); assertThat(allCaps).hasSize(2); assertThat(allCaps.get(0).getCapability("se:cheese")).isEqualTo("brie"); assertThat(allCaps.get(1).getCapability("se:cheese")).isEqualTo("brie"); }
Example #18
Source File: AbstractCapabilities.java From carina with Apache License 2.0 | 5 votes |
private DesiredCapabilities addFirefoxOptions(DesiredCapabilities caps) { FirefoxProfile profile = getDefaultFirefoxProfile(); FirefoxOptions options = new FirefoxOptions().setProfile(profile); caps.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options); // add all custom firefox args for (String arg : Configuration.get(Parameter.FIREFOX_ARGS).split(",")) { if (arg.isEmpty()) { continue; } options.addArguments(arg.trim()); } // add all custom firefox preferences for (String preference : Configuration.get(Parameter.CHROME_EXPERIMENTAL_OPTS).split(",")) { if (preference.isEmpty()) { continue; } // TODO: think about equal sign inside name or value later preference = preference.trim(); String name = preference.split("=")[0].trim(); String value = preference.split("=")[1].trim(); // TODO: test approach with numbers if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { options.addPreference(name, Boolean.valueOf(value)); } else { options.addPreference(name, value); } } return caps; }
Example #19
Source File: HTMLLauncher.java From selenium with Apache License 2.0 | 5 votes |
private WebDriver createDriver(String browser) { String[] parts = browser.split(" ", 2); browser = parts[0]; switch (browser) { case "*chrome": case "*firefox": case "*firefoxproxy": case "*firefoxchrome": case "*pifirefox": FirefoxOptions options = new FirefoxOptions().setLegacy(false); if (parts.length > 1) { options.setBinary(parts[1]); } return new FirefoxDriver(options); case "*iehta": case "*iexplore": case "*iexploreproxy": case "*piiexplore": return new InternetExplorerDriver(); case "*googlechrome": return new ChromeDriver(); case "*MicrosoftEdge": return new EdgeDriver(); case "*opera": case "*operablink": return new OperaDriver(); case "*safari": case "*safariproxy": return new SafariDriver(); default: throw new RuntimeException("Unrecognized browser: " + browser); } }
Example #20
Source File: MBeanFieldGroupRequiredErrorMessageTest.java From viritin with Apache License 2.0 | 5 votes |
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); }
Example #21
Source File: FirefoxCapabilities.java From carina with Apache License 2.0 | 5 votes |
/** * Generate DesiredCapabilities for Firefox with custom FirefoxProfile. * * @param testName * - String. * @param profile * - FirefoxProfile. * @return Firefox desired capabilities. */ public DesiredCapabilities getCapability(String testName, FirefoxProfile profile) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities = initBaseCapabilities(capabilities, BrowserType.FIREFOX, testName); capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false); FirefoxOptions options = new FirefoxOptions().setProfile(profile); capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options); LOGGER.debug("Firefox caps: " + capabilities); return capabilities; }
Example #22
Source File: DriverFactory.java From restful-booker-platform with GNU General Public License v3.0 | 5 votes |
private WebDriver prepareRemoteDriver(){ if(System.getenv("SAUCE_USERNAME") == null){ throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs account name to the environmental variable 'sauce_username'"); } if(System.getenv("SAUCE_ACCESS_KEY") == null){ throw new RuntimeException("To use remote driver a Sauce lab account is required. Please assign your Sauce labs access key to the environmental variable 'sauce_access_key'"); } String URL = "http://" + System.getenv("SAUCE_USERNAME") + ":" + System.getenv("SAUCE_ACCESS_KEY") + "@ondemand.saucelabs.com:80/wd/hub"; FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setCapability("platformName", "Windows 10"); firefoxOptions.setCapability("browserVersion", "65.0"); MutableCapabilities sauceCaps = new MutableCapabilities(); sauceCaps.setCapability("username", System.getenv("SAUCE_USERNAME")); sauceCaps.setCapability("accessKey", System.getenv("SAUCE_ACCESS_KEY")); sauceCaps.setCapability("seleniumVersion", "3.141.59"); sauceCaps.setCapability("name", "Restful-booker-platform"); firefoxOptions.setCapability("sauce:options", sauceCaps); try { return new RemoteWebDriver(new URL(URL), firefoxOptions); } catch (MalformedURLException e) { throw new RuntimeException("WARN: An error occurred attempting to create a remote driver connection. See the following error: " + e); } }
Example #23
Source File: AbstractWebDriverPoolTest.java From webdriver-factory with Apache License 2.0 | 5 votes |
@Test public void testCanHandleAlertsOnDriverAvailabilityCheck() { factory.setLocalDriverProvider(FakeAlertiveWebDriver::new); WebDriver driver = factory.getDriver(new FirefoxOptions()); assertTrue(driver instanceof FakeAlertiveWebDriver); assertFalse(factory.isEmpty()); WebDriver driver2 = factory.getDriver(new FirefoxOptions()); assertSame(driver2, driver); assertFalse(factory.isEmpty()); factory.dismissDriver(driver); assertTrue(factory.isEmpty()); }
Example #24
Source File: TestUtils.java From enmasse with Apache License 2.0 | 5 votes |
public static RemoteWebDriver getFirefoxDriver() throws Exception { Endpoint endpoint = SystemtestsKubernetesApps.getFirefoxSeleniumAppEndpoint(Kubernetes.getInstance()); FirefoxOptions options = new FirefoxOptions(); // https://github.com/mozilla/geckodriver/issues/330 enable the emission of console.info(), warn() // etc // to stdout of the browser process. Works around the fact that Firefox logs are not available // through // WebDriver.manage().logs(). options.addPreference("devtools.console.stdout.content", true); options.addPreference("browser.tabs.unloadOnLowMemory", false); return getRemoteDriver(endpoint.getHost(), endpoint.getPort(), options); }
Example #25
Source File: WebRtcFirefoxTest.java From webdrivermanager-examples with Apache License 2.0 | 5 votes |
@Before public void setupTest() { FirefoxOptions options = new FirefoxOptions(); // This flag avoids granting the access to the camera options.addPreference("media.navigator.permission.disabled", true); // This flag force to use fake user media (synthetic video of multiple // color) options.addPreference("media.navigator.streams.fake", true); driver = new FirefoxDriver(options); }
Example #26
Source File: WebRtcRemoteFirefoxTest.java From webdrivermanager-examples with Apache License 2.0 | 5 votes |
@Before public void setup() throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); FirefoxOptions options = new FirefoxOptions(); options.addPreference("media.navigator.permission.disabled", true); options.addPreference("media.navigator.streams.fake", true); capabilities.setCapability(FIREFOX_OPTIONS, options); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities); }
Example #27
Source File: FirefoxFactory.java From webtester2-core with Apache License 2.0 | 5 votes |
public FirefoxFactory() { super((capabilities) -> { FirefoxOptions firefoxOptions = new FirefoxOptions() .setLegacy(true) .merge(capabilities); return new FirefoxDriver(firefoxOptions); }); }
Example #28
Source File: DriverFactory.java From Insights with Apache License 2.0 | 5 votes |
@Override protected WebDriver initialValue() { System.setProperty("webdriver.gecko.driver", ApplicationConfigProvider.getInstance().getDriverLocation()); FirefoxBinary firefoxBinary = new FirefoxBinary(); firefoxBinary.addCommandLineOptions("--headless"); FirefoxOptions firefoxOptions = new FirefoxOptions(); firefoxOptions.setBinary(firefoxBinary); return new FirefoxDriver(firefoxOptions); // can be replaced with other browser drivers }
Example #29
Source File: CustomDriverProvider.java From akita with Apache License 2.0 | 5 votes |
/** * Задает 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 #30
Source File: FirefoxAnnotationReaderTest.java From selenium-jupiter with Apache License 2.0 | 5 votes |
@Test void testAnnotatedFirefoxOptionsIsSelectedOverOtherAnnotatedOptions() throws Exception { Optional<Object> testInstance = Optional .of(new ClassWithMultipleOptions()); FirefoxOptions firefoxOptions = (FirefoxOptions) annotationsReader .getOptions(null, testInstance); assertThat(firefoxOptions, notNullValue()); }