Skip to content

Commit 0a1a2aa

Browse files
committed
java: Gathering all Firefox-specific magic system property names to a single interface
1 parent 128a127 commit 0a1a2aa

File tree

4 files changed

+57
-30
lines changed

4 files changed

+57
-30
lines changed

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

+39-16
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.google.common.collect.Maps;
3030
import com.google.common.collect.Sets;
3131

32+
import com.sun.javafx.runtime.SystemProperties;
33+
3234
import org.openqa.selenium.Capabilities;
3335
import org.openqa.selenium.OutputType;
3436
import org.openqa.selenium.Platform;
@@ -71,6 +73,26 @@
7173
* profile directly. This allows multiple instances of firefox to be started.
7274
*/
7375
public class FirefoxDriver extends RemoteWebDriver implements Killable {
76+
77+
public interface SystemProperty {
78+
String BROWSER_BINARY = "webdriver.firefox.bin";
79+
String BROWSER_LOGFILE = "webdriver.firefox.logfile";
80+
String BROWSER_LIBRARY_PATH = "webdriver.firefox.library.path";
81+
String BROWSER_PROFILE = "webdriver.firefox.profile";
82+
83+
/**
84+
* System property that defines the location of the webdriver.xpi browser extension to install
85+
* in the browser. If not set, the prebuilt extension bundled with this class will be used
86+
* instead.
87+
*/
88+
String DRIVER_XPI_PROPERTY = "webdriver.firefox.driver";
89+
90+
/**
91+
* Boolean system property that instructs FirefoxDriver to use Marionette backend.
92+
*/
93+
String DRIVER_USE_MARIONETTE = "webdriver.firefox.marionette";
94+
}
95+
7496
public static final String BINARY = "firefox_binary";
7597
public static final String PROFILE = "firefox_profile";
7698

@@ -79,7 +101,7 @@ public class FirefoxDriver extends RemoteWebDriver implements Killable {
79101

80102
// For now, only enable native events on Windows
81103
public static final boolean USE_MARIONETTE = Boolean.parseBoolean(
82-
System.getProperty("webdriver.firefox.marionette"));
104+
System.getProperty(SystemProperty.DRIVER_USE_MARIONETTE));
83105

84106
// Accept untrusted SSL certificates.
85107
@Deprecated
@@ -100,18 +122,18 @@ public FirefoxDriver(FirefoxProfile profile) {
100122
}
101123

102124
public FirefoxDriver(Capabilities desiredCapabilities) {
103-
this(getBinary(desiredCapabilities), extractProfile(desiredCapabilities, null),
125+
this(getBinary(desiredCapabilities), extractProfile(desiredCapabilities, null),
104126
desiredCapabilities);
105127
}
106-
128+
107129
public FirefoxDriver(Capabilities desiredCapabilities, Capabilities requiredCapabilities) {
108-
this(getBinary(desiredCapabilities), extractProfile(desiredCapabilities, requiredCapabilities),
130+
this(getBinary(desiredCapabilities), extractProfile(desiredCapabilities, requiredCapabilities),
109131
desiredCapabilities, requiredCapabilities);
110132
}
111133

112-
private static FirefoxProfile extractProfile(Capabilities desiredCapabilities,
134+
private static FirefoxProfile extractProfile(Capabilities desiredCapabilities,
113135
Capabilities requiredCapabilities) {
114-
136+
115137
FirefoxProfile profile = null;
116138
Object raw = null;
117139
if (desiredCapabilities != null && desiredCapabilities.getCapability(PROFILE) != null) {
@@ -132,10 +154,10 @@ private static FirefoxProfile extractProfile(Capabilities desiredCapabilities,
132154
}
133155
}
134156
profile = getProfile(profile);
135-
157+
136158
populateProfile(profile, desiredCapabilities);
137159
populateProfile(profile, requiredCapabilities);
138-
160+
139161
return profile;
140162
}
141163

@@ -152,10 +174,10 @@ static void populateProfile(FirefoxProfile profile, Capabilities capabilities) {
152174
profile.setAcceptUntrustedCertificates(acceptCerts);
153175
}
154176
if (capabilities.getCapability(LOGGING_PREFS) != null) {
155-
LoggingPreferences logsPrefs =
177+
LoggingPreferences logsPrefs =
156178
(LoggingPreferences) capabilities.getCapability(LOGGING_PREFS);
157179
for (String logtype : logsPrefs.getEnabledLogTypes()) {
158-
profile.setPreference("webdriver.log." + logtype,
180+
profile.setPreference("webdriver.log." + logtype,
159181
logsPrefs.getLevel(logtype).intValue());
160182
}
161183
}
@@ -185,8 +207,8 @@ public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile) {
185207
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile, Capabilities capabilities) {
186208
this(binary, profile, capabilities, null);
187209
}
188-
189-
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile,
210+
211+
public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile,
190212
Capabilities desiredCapabilities, Capabilities requiredCapabilities) {
191213
super(new LazyCommandExecutor(binary, profile),
192214
dropCapabilities(desiredCapabilities, BINARY, PROFILE),
@@ -251,12 +273,13 @@ protected void startClient() {
251273

252274
private static FirefoxProfile getProfile(FirefoxProfile profile) {
253275
FirefoxProfile profileToUse = profile;
254-
String suggestedProfile = System.getProperty("webdriver.firefox.profile");
276+
String suggestedProfile = System.getProperty(SystemProperty.BROWSER_PROFILE);
255277
if (profileToUse == null && suggestedProfile != null) {
256278
profileToUse = new ProfilesIni().getProfile(suggestedProfile);
257279
if (profileToUse == null) {
258-
throw new WebDriverException("Firefox profile '" + suggestedProfile
259-
+ "' named in system property 'webdriver.firefox.profile' not found");
280+
throw new WebDriverException(String.format(
281+
"Firefox profile '%s' named in system property '%s' not found",
282+
suggestedProfile, SystemProperty.BROWSER_PROFILE));
260283
}
261284
} else if (profileToUse == null) {
262285
profileToUse = new FirefoxProfile();
@@ -292,7 +315,7 @@ protected void stopClient() {
292315

293316
/**
294317
* Drops capabilities that we shouldn't send over the wire.
295-
*
318+
*
296319
* Used for capabilities which aren't BeanToJson-convertable, and are only used by the local
297320
* launcher.
298321
*/

java/client/src/org/openqa/selenium/firefox/internal/Executable.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.openqa.selenium.Platform;
2424
import org.openqa.selenium.WebDriverException;
25+
import org.openqa.selenium.firefox.FirefoxDriver;
2526
import org.openqa.selenium.os.CommandLine;
2627
import org.openqa.selenium.os.WindowsUtils;
2728
import org.openqa.selenium.remote.internal.CircularOutputStream;
@@ -101,7 +102,7 @@ public void setLibraryPath(CommandLine command, final Map<String, String> extraE
101102
// Last, add the contents of the specified system property, defaulting to the binary's path.
102103

103104
// On Snow Leopard, beware of problems the sqlite library
104-
String firefoxLibraryPath = System.getProperty("webdriver.firefox.library.path",
105+
String firefoxLibraryPath = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LIBRARY_PATH,
105106
binary.getAbsoluteFile().getParentFile().getAbsolutePath());
106107
if (Platform.getCurrent().is(Platform.MAC) && Platform.getCurrent().getMinorVersion() > 5) {
107108
libraryPath.append(libraryPath).append(File.pathSeparator);
@@ -118,7 +119,7 @@ public void setLibraryPath(CommandLine command, final Map<String, String> extraE
118119
* be found.
119120
*/
120121
private static File locateFirefoxBinaryFromSystemProperty() {
121-
String binaryName = System.getProperty("webdriver.firefox.bin");
122+
String binaryName = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_BINARY);
122123
if (binaryName == null)
123124
return null;
124125

@@ -142,11 +143,8 @@ private static File locateFirefoxBinaryFromSystemProperty() {
142143
return binary;
143144

144145
throw new WebDriverException(
145-
String
146-
.format(
147-
"\"webdriver.firefox.bin\" property set, but unable to locate the requested binary: %s",
148-
binaryName
149-
));
146+
String.format("'%s' property set, but unable to locate the requested binary: %s",
147+
FirefoxDriver.SystemProperty.BROWSER_BINARY, binaryName));
150148
}
151149

152150
/**
@@ -209,7 +207,7 @@ private static String getEnvVar(String name, String defaultValue) {
209207
}
210208

211209
public OutputStream getDefaultOutputStream() {
212-
String firefoxLogFile = System.getProperty("webdriver.firefox.logfile");
210+
String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
213211
if ("/dev/stdout".equals(firefoxLogFile)) {
214212
return System.out;
215213
}

java/client/src/org/openqa/selenium/firefox/internal/MarionetteConnection.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.openqa.selenium.WebElement;
2727
import org.openqa.selenium.firefox.ExtensionConnection;
2828
import org.openqa.selenium.firefox.FirefoxBinary;
29+
import org.openqa.selenium.firefox.FirefoxDriver;
2930
import org.openqa.selenium.firefox.FirefoxProfile;
3031
import org.openqa.selenium.internal.Lock;
3132
import org.openqa.selenium.logging.LocalLogs;
@@ -108,7 +109,7 @@ public void start() throws IOException {
108109

109110
process.clean(profile, profileDir);
110111

111-
String firefoxLogFile = System.getProperty("webdriver.firefox.logfile");
112+
String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
112113

113114
if (firefoxLogFile != null) {
114115
if ("/dev/stdout".equals(firefoxLogFile)) {

java/client/src/org/openqa/selenium/firefox/internal/NewProfileExtensionConnection.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openqa.selenium.WebDriverException;
2323
import org.openqa.selenium.firefox.ExtensionConnection;
2424
import org.openqa.selenium.firefox.FirefoxBinary;
25+
import org.openqa.selenium.firefox.FirefoxDriver;
2526
import org.openqa.selenium.firefox.FirefoxProfile;
2627
import org.openqa.selenium.firefox.NotConnectedException;
2728
import org.openqa.selenium.internal.Lock;
@@ -49,8 +50,11 @@ public class NewProfileExtensionConnection implements ExtensionConnection, Needs
4950
* System property that defines the location of the webdriver.xpi browser extension to install
5051
* in the browser. If not set, the prebuilt extension bundled with this class will be used
5152
* instead.
53+
*
54+
* @deprecated Use FirefoxDriver.SystemProperty.DRIVER_XPI_PROPERTY instead
5255
*/
53-
public static final String FIREFOX_DRIVER_XPI_PROPERTY = "webdriver.firefox.driver";
56+
@Deprecated
57+
public static final String FIREFOX_DRIVER_XPI_PROPERTY = FirefoxDriver.SystemProperty.DRIVER_XPI_PROPERTY;
5458

5559
private final static int BUFFER_SIZE = 4096;
5660

@@ -92,7 +96,7 @@ public void start() throws IOException {
9296

9397
delegate = new HttpCommandExecutor(buildUrl(host, port));
9498
delegate.setLocalLogs(logs);
95-
String firefoxLogFile = System.getProperty("webdriver.firefox.logfile");
99+
String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
96100

97101
if (firefoxLogFile != null) {
98102
if ("/dev/stdout".equals(firefoxLogFile)) {
@@ -149,8 +153,9 @@ protected void addWebDriverExtensionIfNeeded() {
149153
}
150154

151155
private static Optional<Extension> loadCustomExtension() {
152-
if (System.getProperty(FIREFOX_DRIVER_XPI_PROPERTY) != null) {
153-
File xpi = new File(System.getProperty(FIREFOX_DRIVER_XPI_PROPERTY));
156+
String xpiProperty = System.getProperty(FirefoxDriver.SystemProperty.DRIVER_XPI_PROPERTY);
157+
if (xpiProperty != null) {
158+
File xpi = new File(xpiProperty);
154159
return Optional.of((Extension) new FileExtension(xpi));
155160
}
156161
return Optional.absent();
@@ -205,7 +210,7 @@ public void quit() {
205210
/**
206211
* Builds the URL for the Firefox extension running on the given host and port. If the host is
207212
* {@code localhost}, an attempt will be made to find the correct loopback address.
208-
*
213+
*
209214
* @param host The hostname the extension is running on.
210215
* @param port The port the extension is listening on.
211216
* @return The URL of the Firefox extension.

0 commit comments

Comments
 (0)