|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.remote; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | + |
| 22 | +import org.junit.After; |
| 23 | +import org.junit.Assume; |
| 24 | +import org.junit.Before; |
| 25 | +import org.junit.BeforeClass; |
| 26 | +import org.junit.Test; |
| 27 | +import org.openqa.selenium.WebDriver; |
| 28 | +import org.openqa.selenium.firefox.FirefoxDriver; |
| 29 | +import org.openqa.selenium.firefox.FirefoxOptions; |
| 30 | +import org.openqa.selenium.firefox.FirefoxProfile; |
| 31 | +import org.openqa.selenium.testing.JUnit4TestBase; |
| 32 | + |
| 33 | +import java.net.URL; |
| 34 | + |
| 35 | +public class StartingFirefoxRemotelyTest extends JUnit4TestBase { |
| 36 | + |
| 37 | + private URL remoteUrl; |
| 38 | + private WebDriver localDriver; |
| 39 | + |
| 40 | + @BeforeClass |
| 41 | + public static void ensureTestingFirefox() { |
| 42 | + Assume.assumeTrue("ff".equals(System.getProperty("selenium.browser"))); |
| 43 | + } |
| 44 | + |
| 45 | + @Before |
| 46 | + public void getRemoteServerUrl() { |
| 47 | + CommandExecutor executor = ((RemoteWebDriver) driver).getCommandExecutor(); |
| 48 | + Assume.assumeTrue(executor instanceof HttpCommandExecutor); |
| 49 | + |
| 50 | + remoteUrl = ((HttpCommandExecutor) executor).getAddressOfRemoteServer(); |
| 51 | + } |
| 52 | + |
| 53 | + @After |
| 54 | + public void quiteDriver() { |
| 55 | + if (localDriver != null) { |
| 56 | + localDriver.quit(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void canSetProfileThroughDesiredCapabilities() { |
| 62 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 63 | + caps.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); |
| 64 | + caps.setCapability(FirefoxDriver.PROFILE, new FirefoxProfile()); |
| 65 | + caps.setCapability(FirefoxDriver.MARIONETTE, true); |
| 66 | + |
| 67 | + localDriver = new RemoteWebDriver(remoteUrl, caps); |
| 68 | + localDriver.get(pages.xhtmlTestPage); |
| 69 | + assertEquals("XHTML Test Page", localDriver.getTitle()); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void canSetProfileThroughFirefoxOptions() { |
| 74 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 75 | + caps.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); |
| 76 | + |
| 77 | + FirefoxOptions options = new FirefoxOptions(); |
| 78 | + options.setProfile(new FirefoxProfile()); |
| 79 | + caps.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options); |
| 80 | + |
| 81 | + localDriver = new RemoteWebDriver(remoteUrl, caps); |
| 82 | + localDriver.get(pages.xhtmlTestPage); |
| 83 | + assertEquals("XHTML Test Page", localDriver.getTitle()); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void shouldBeAbleToMergeDesiredOptionsIntoFirefoxOptions() { |
| 88 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 89 | + caps.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); |
| 90 | + |
| 91 | + FirefoxOptions options = new FirefoxOptions(); |
| 92 | + options.setProfile(new FirefoxProfile()); |
| 93 | + options.addDesiredCapabilities(caps); |
| 94 | + |
| 95 | + localDriver = new RemoteWebDriver(remoteUrl, options.toDesiredCapabilities()); |
| 96 | + localDriver.get(pages.xhtmlTestPage); |
| 97 | + assertEquals("XHTML Test Page", localDriver.getTitle()); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void canStartFirefoxWithoutAnyConfigurationOptions() { |
| 102 | + DesiredCapabilities caps = new DesiredCapabilities(); |
| 103 | + caps.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); |
| 104 | + |
| 105 | + FirefoxOptions options = new FirefoxOptions(); |
| 106 | + options.addDesiredCapabilities(caps); |
| 107 | + |
| 108 | + localDriver = new RemoteWebDriver(remoteUrl, options.toDesiredCapabilities()); |
| 109 | + localDriver.get(pages.xhtmlTestPage); |
| 110 | + assertEquals("XHTML Test Page", localDriver.getTitle()); |
| 111 | + } |
| 112 | +} |
0 commit comments