Skip to content

Commit 07f6b7a

Browse files
committed
Add tests for starting firefox remotely
I can't believe how much chaos this is causing us. Fixing these tests revealed a flaw in how we were setting the legacy flag.
1 parent 65553a1 commit 07f6b7a

File tree

5 files changed

+149
-2
lines changed

5 files changed

+149
-2
lines changed

java/client/src/org/openqa/selenium/firefox/FirefoxDriver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ private static FirefoxOptions getFirefoxOptions(Capabilities capabilities) {
273273
options = (FirefoxOptions) rawOptions;
274274
}
275275

276-
options.setLegacy(!capabilities.is(MARIONETTE));
276+
Object marionette = capabilities.getCapability(MARIONETTE);
277+
if (marionette instanceof Boolean) {
278+
options.setLegacy(!(Boolean) marionette);
279+
}
277280
return options;
278281
}
279282

java/client/test/org/openqa/selenium/remote/BUCK

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ java_test(name = 'remote-driver-tests',
5858

5959
java_library(name = 'remote-driver-test-lib',
6060
srcs = [
61+
'RemoteSpecificTests.java',
6162
'RemoteWebDriverScreenshotTest.java',
63+
'StartingFirefoxRemotelyTest.java',
6264
],
6365
deps = [
6466
'//java/client/src/org/openqa/selenium:selenium',
67+
'//java/client/src/org/openqa/selenium/firefox:firefox',
6568
'//java/client/src/org/openqa/selenium/remote:remote',
6669
'//java/client/test/org/openqa/selenium/testing:test-base',
6770
'//java/client/test/org/openqa/selenium/testing/drivers:drivers',
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 org.junit.runner.RunWith;
21+
import org.junit.runners.Suite;
22+
23+
@RunWith(Suite.class)
24+
@Suite.SuiteClasses({
25+
RemoteWebDriverScreenshotTest.class,
26+
StartingFirefoxRemotelyTest.class
27+
})
28+
public class RemoteSpecificTests {
29+
}

java/client/test/org/openqa/selenium/remote/RemoteWebDriverTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@RunWith(Suite.class)
2525
@Suite.SuiteClasses({
2626
StandardSeleniumTests.class,
27-
RemoteWebDriverScreenshotTest.class
27+
RemoteSpecificTests.class
2828
})
2929
public class RemoteWebDriverTests {
3030
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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

Comments
 (0)