Skip to content

Commit ec80d11

Browse files
committed
Refactoring constructor that accepts FirefoxBinary and FirefoxProfile
1 parent 914207e commit ec80d11

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import java.io.IOException;
5959
import java.net.URI;
6060
import java.util.Map;
61-
import java.util.Optional;
6261
import java.util.Set;
6362
import java.util.concurrent.TimeUnit;
6463

@@ -151,6 +150,10 @@ public FirefoxDriver(FirefoxProfile profile) {
151150
this(new FirefoxOptions().setProfile(profile));
152151
}
153152

153+
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) {
154+
this(new FirefoxOptions().setBinary(binary).setProfile(profile));
155+
}
156+
154157
public FirefoxDriver(Capabilities desiredCapabilities) {
155158
this(getBinary(desiredCapabilities), null, desiredCapabilities);
156159
}
@@ -284,10 +287,6 @@ private static FirefoxBinary getBinary(Capabilities capabilities) {
284287
return new FirefoxBinary();
285288
}
286289

287-
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) {
288-
this(binary, profile, DesiredCapabilities.firefox());
289-
}
290-
291290
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) {
292291
this(binary, profile, capabilities, null);
293292
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import com.google.gson.JsonPrimitive;
2929

3030
import org.openqa.selenium.WebDriverException;
31-
import org.openqa.selenium.remote.CommandExecutor;
3231
import org.openqa.selenium.remote.DesiredCapabilities;
33-
import org.openqa.selenium.remote.service.DriverCommandExecutor;
3432

3533
import java.io.IOException;
3634
import java.nio.file.Path;
@@ -166,7 +164,7 @@ public FirefoxBinary getBinaryOrNull() {
166164
}
167165

168166
public FirefoxOptions setProfile(FirefoxProfile profile) {
169-
this.profile = checkNotNull(profile);
167+
this.profile = profile;
170168
return this;
171169
}
172170

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ public void canStartDriverWithSpecifiedProfile() throws IOException {
106106
verifyItIsLegacy(localDriver);
107107
}
108108

109+
@Test
110+
public void canStartDriverWithSpecifiedBinaryAndProfile() throws IOException {
111+
FirefoxBinary binary = spy(new FirefoxBinary());
112+
FirefoxProfile profile = new FirefoxProfile();
113+
profile.setPreference("browser.startup.page", 1);
114+
profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage);
115+
localDriver = new FirefoxDriver(binary, profile);
116+
wait.until($ -> "XHTML Test Page".equals(localDriver.getTitle()));
117+
verifyItIsLegacy(localDriver);
118+
verify(binary).startFirefoxProcess(any());
119+
}
120+
109121
private static class ConnectionCapturingDriver extends FirefoxDriver {
110122
public ExtensionConnection keptConnection;
111123

java/client/test/org/openqa/selenium/firefox/MarionetteTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ public void canStartDriverWithSpecifiedProfile() throws IOException {
7777
verifyItIsMarionette(localDriver);
7878
}
7979

80+
@Test
81+
public void canStartDriverWithSpecifiedBinaryAndProfile() throws IOException {
82+
FirefoxBinary binary = spy(new FirefoxBinary());
83+
FirefoxProfile profile = new FirefoxProfile();
84+
profile.setPreference("browser.startup.page", 1);
85+
profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage);
86+
localDriver = new FirefoxDriver(binary, profile);
87+
wait.until($ -> "XHTML Test Page".equals(localDriver.getTitle()));
88+
verifyItIsMarionette(localDriver);
89+
verify(binary, atLeastOnce()).getPath();
90+
verify(binary, never()).startFirefoxProcess(any());
91+
}
92+
8093
@Test
8194
public void shouldUseFirefoxOptions() throws InterruptedException {
8295
DesiredCapabilities caps = new FirefoxOptions()

0 commit comments

Comments
 (0)