Skip to content

Commit 7627ee8

Browse files
authored
[java] remove deprecated Firefox capabilities and consolidate tests (#11403)
1 parent 29fc508 commit 7627ee8

7 files changed

Lines changed: 28 additions & 377 deletions

File tree

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,6 @@ public static final class SystemProperty {
326326
public static final String BROWSER_PROFILE = "webdriver.firefox.profile";
327327
}
328328

329-
public static final class Capability {
330-
331-
public static final String BINARY = "firefox_binary";
332-
public static final String PROFILE = "firefox_profile";
333-
public static final String MARIONETTE = "marionette";
334-
}
335-
336329
private static class FirefoxDriverCommandExecutor extends DriverCommandExecutor {
337330

338331
public FirefoxDriverCommandExecutor(DriverService service) {

java/src/org/openqa/selenium/firefox/FirefoxOptions.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package org.openqa.selenium.firefox;
1919

2020
import static java.util.stream.Collectors.toMap;
21-
import static org.openqa.selenium.firefox.FirefoxDriver.Capability.BINARY;
22-
import static org.openqa.selenium.firefox.FirefoxDriver.Capability.PROFILE;
2321
import static org.openqa.selenium.remote.Browser.FIREFOX;
2422

2523
import org.openqa.selenium.Capabilities;
@@ -295,45 +293,6 @@ public FirefoxOptions setAndroidIntentArguments(List<String> args) {
295293
return setFirefoxOption("androidIntentArguments", args);
296294
}
297295

298-
@Override
299-
public void setCapability(String key, Object value) {
300-
Require.nonNull("Capability name", key);
301-
Require.nonNull("Value", value);
302-
303-
switch (key) {
304-
case BINARY:
305-
if (value instanceof FirefoxBinary) {
306-
setBinary((FirefoxBinary) value);
307-
} else if (value instanceof Path) {
308-
setBinary((Path) value);
309-
} else if (value instanceof String) {
310-
setBinary((String) value);
311-
} else {
312-
throw new IllegalArgumentException("Unable to set binary from " + value);
313-
}
314-
break;
315-
316-
case PROFILE:
317-
if (value instanceof FirefoxProfile) {
318-
setProfile((FirefoxProfile) value);
319-
} else if (value instanceof String) {
320-
try {
321-
FirefoxProfile profile = FirefoxProfile.fromJson((String) value);
322-
setProfile(profile);
323-
} catch (IOException e) {
324-
throw new WebDriverException(e);
325-
}
326-
} else {
327-
throw new WebDriverException("Unexpected value for profile: " + value);
328-
}
329-
break;
330-
331-
default:
332-
// Do nothing
333-
}
334-
super.setCapability(key, value);
335-
}
336-
337296
private FirefoxOptions setFirefoxOption(Keys key, Object value) {
338297
return setFirefoxOption(key.key(), value);
339298
}

java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.selenium.firefox;
1919

20-
import static org.openqa.selenium.firefox.FirefoxDriver.Capability.MARIONETTE;
2120
import static org.openqa.selenium.remote.Browser.FIREFOX;
2221
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;
2322

@@ -47,10 +46,6 @@ public Capabilities getCanonicalCapabilities() {
4746

4847
@Override
4948
public boolean isSupporting(Capabilities capabilities) {
50-
if (capabilities.is(MARIONETTE)) {
51-
return false;
52-
}
53-
5449
if (FIREFOX.is(capabilities)) {
5550
return true;
5651
}
@@ -93,10 +88,6 @@ public Optional<WebDriver> createDriver(Capabilities capabilities)
9388
return Optional.empty();
9489
}
9590

96-
if (capabilities.is(MARIONETTE)) {
97-
return Optional.empty();
98-
}
99-
10091
return Optional.of(new FirefoxDriver(new FirefoxOptions().merge(capabilities)));
10192
}
10293
}

java/src/org/openqa/selenium/firefox/GeckoDriverService.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,7 @@ public static GeckoDriverService createDefaultService() {
9595
}
9696

9797
static GeckoDriverService createDefaultService(Capabilities caps) {
98-
Builder builder = new Builder();
99-
100-
Object binary = caps.getCapability(FirefoxDriver.Capability.BINARY);
101-
if (binary != null) {
102-
FirefoxBinary actualBinary;
103-
if (binary instanceof FirefoxBinary) {
104-
actualBinary = (FirefoxBinary) binary;
105-
} else if (binary instanceof String) {
106-
actualBinary = new FirefoxBinary(new File(String.valueOf(binary)));
107-
} else {
108-
throw new IllegalArgumentException(
109-
"Expected binary to be a string or a binary: " + binary);
110-
}
111-
112-
builder.usingFirefoxBinary(actualBinary);
113-
}
114-
115-
return builder.build();
98+
return createDefaultService();
11699
}
117100

118101
@Override
@@ -139,11 +122,6 @@ public Builder() {
139122

140123
@Override
141124
public int score(Capabilities capabilities) {
142-
if (capabilities.getCapability(FirefoxDriver.Capability.MARIONETTE) != null
143-
&& ! capabilities.is(FirefoxDriver.Capability.MARIONETTE)) {
144-
return 0;
145-
}
146-
147125
int score = 0;
148126

149127
if (FIREFOX.is(capabilities)) {

java/test/org/openqa/selenium/firefox/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite", "java_test_su
44

55
LARGE_TESTS = [
66
"FirefoxDriverTest.java",
7-
"MarionetteTest.java",
87
"TakesFullPageScreenshotTest.java",
98
]
109

java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import org.openqa.selenium.ImmutableCapabilities;
3030
import org.openqa.selenium.JavascriptExecutor;
3131
import org.openqa.selenium.OutputType;
32+
import org.openqa.selenium.PageLoadStrategy;
3233
import org.openqa.selenium.ParallelTestRunner;
3334
import org.openqa.selenium.ParallelTestRunner.Worker;
3435
import org.openqa.selenium.WebDriver;
3536
import org.openqa.selenium.WebElement;
3637
import org.openqa.selenium.build.InProject;
38+
import org.openqa.selenium.remote.CapabilityType;
3739
import org.openqa.selenium.remote.Command;
3840
import org.openqa.selenium.remote.CommandExecutor;
3941
import org.openqa.selenium.remote.DriverCommand;
@@ -72,6 +74,7 @@
7274
import static org.mockito.Mockito.verify;
7375
import static org.openqa.selenium.WaitingConditions.elementValueToEqual;
7476
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
77+
import static org.openqa.selenium.remote.CapabilityType.PAGE_LOAD_STRATEGY;
7578
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
7679
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
7780

@@ -135,7 +138,6 @@ public void canStartDriverWithNoParameters() {
135138
}
136139

137140
@Test
138-
@Ignore(value = FIREFOX, reason = "Assumed to be covered by tests for GeckoDriverService")
139141
@NoDriverBeforeTest
140142
public void canStartDriverWithSpecifiedBinary() {
141143
FirefoxBinary binary = spy(new FirefoxBinary());
@@ -182,27 +184,6 @@ public void canSetProfileInFirefoxOptions() {
182184
wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle()));
183185
}
184186

185-
@Test
186-
@Ignore(value = FIREFOX, reason = "Assumed to be covered by tests for GeckoDriverService")
187-
@NoDriverBeforeTest
188-
public void canSetBinaryInCapabilities() {
189-
FirefoxBinary binary = spy(new FirefoxBinary());
190-
Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.BINARY, binary);
191-
192-
localDriver = new WebDriverBuilder().get(caps);
193-
194-
verify(binary, atLeastOnce()).getPath();
195-
}
196-
197-
@Test
198-
@NoDriverBeforeTest
199-
public void canSetBinaryPathInCapabilities() {
200-
String binPath = new FirefoxBinary().getPath();
201-
Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.BINARY, binPath);
202-
203-
localDriver = new WebDriverBuilder().get(caps);
204-
}
205-
206187
@Test
207188
@NoDriverBeforeTest
208189
public void canSetPreferencesAndProfileInFirefoxOptions() {
@@ -327,16 +308,13 @@ public void shouldBeAbleToStartANamedProfile() {
327308
}
328309

329310
@Test
330-
@Timeout(60)
331-
@Ignore(FIREFOX)
311+
@Timeout(10)
312+
@NoDriverBeforeTest
332313
public void shouldBeAbleToStartANewInstanceEvenWithVerboseLogging() {
333-
FirefoxBinary binary = new FirefoxBinary();
334314
GeckoDriverService service = new GeckoDriverService.Builder()
335-
.usingFirefoxBinary(binary)
336315
.withEnvironment(ImmutableMap.of("NSPR_LOG_MODULES", "all:5"))
337316
.build();
338317

339-
// We will have an infinite hang if this driver does not start properly.
340318
new FirefoxDriver(service).quit();
341319
}
342320

@@ -354,6 +332,16 @@ public void shouldBeAbleToPassCommandLineOptions() {
354332
assertThat(size.height).isLessThan(650);
355333
}
356334

335+
@Test
336+
@NoDriverBeforeTest
337+
public void canPassCapabilities() {
338+
Capabilities caps = new ImmutableCapabilities(CapabilityType.PAGE_LOAD_STRATEGY, "none");
339+
340+
localDriver = new FirefoxDriver(new FirefoxOptions().merge(caps));
341+
342+
assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none");
343+
}
344+
357345
@Test
358346
@NoDriverBeforeTest
359347
public void canBlockInsecureCerts() {
@@ -364,24 +352,23 @@ public void canBlockInsecureCerts() {
364352

365353
@Test
366354
@NoDriverBeforeTest
367-
public void shouldAllowUserToSuccessfullyOverrideTheHomePage() {
368-
FirefoxProfile profile = new FirefoxProfile();
369-
profile.setPreference("browser.startup.page", "1");
370-
profile.setPreference("browser.startup.homepage", pages.javascriptPage);
355+
public void canSetPageLoadStrategyViaOptions() {
356+
localDriver = new FirefoxDriver(
357+
new FirefoxOptions().setPageLoadStrategy(PageLoadStrategy.NONE));
371358

372-
localDriver = new WebDriverBuilder().get(new FirefoxOptions().setProfile(profile));
373-
new WebDriverWait(localDriver, Duration.ofSeconds(30)).until(urlToBe(pages.javascriptPage));
359+
assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none");
374360
}
375361

376-
private ExpectedCondition<Boolean> urlToBe(final String expectedUrl) {
377-
return driver1 -> expectedUrl.equals(driver1.getCurrentUrl());
362+
@Test
363+
@NoDriverBeforeTest
364+
public void canStartHeadless() {
365+
localDriver = new FirefoxDriver(new FirefoxOptions().setHeadless(true));
366+
367+
assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability("moz:headless")).isEqualTo(true);
378368
}
379369

380-
@Test
381-
@Ignore(value = FIREFOX, issue = "https://github.com/mozilla/geckodriver/issues/273")
382-
public void canAccessUrlProtectedByBasicAuth() {
383-
driver.get(appServer.whereIsWithCredentials("basicAuth", "test", "test"));
384-
assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized");
370+
private ExpectedCondition<Boolean> urlToBe(final String expectedUrl) {
371+
return driver1 -> expectedUrl.equals(driver1.getCurrentUrl());
385372
}
386373

387374
@Test

0 commit comments

Comments
 (0)