Skip to content

Commit 8f8bbee

Browse files
committed
[java] Fixing FirefoxOptions merge and copy-constructor
1 parent d9687dc commit 8f8bbee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public FirefoxOptions(Capabilities source) {
104104
}
105105
});
106106

107+
// If `source` is an instance of FirefoxOptions, we need to mirror those into this instance.
108+
if (source instanceof FirefoxOptions) {
109+
mirror((FirefoxOptions) source);
110+
return;
111+
}
112+
107113
// If `source` has options, we need to mirror those into this instance. This may be either a
108114
// Map (if we're constructing from a serialized instance) or another FirefoxOptions. *sigh*
109115
Object raw = source.getCapability(FIREFOX_OPTIONS);
@@ -167,6 +173,17 @@ public FirefoxOptions(Capabilities source) {
167173
}
168174
}
169175

176+
private void mirror(FirefoxOptions that) {
177+
addArguments(that.args);
178+
that.preferences.forEach(this::addPreference);
179+
setLegacy(that.legacy);
180+
181+
if (that.logLevel != null) { setLogLevel(that.logLevel); }
182+
if (that.binary != null) { setCapability(BINARY, that.binary.asCapability()); }
183+
184+
if (that.profile != null) { setProfile(that.profile); }
185+
}
186+
170187
public FirefoxOptions setLegacy(boolean legacy) {
171188
setCapability(MARIONETTE, !legacy);
172189
return this;
@@ -309,6 +326,9 @@ public Map<String, Object> asMap() {
309326
@Override
310327
public FirefoxOptions merge(Capabilities capabilities) {
311328
super.merge(capabilities);
329+
if (capabilities instanceof FirefoxOptions) {
330+
mirror((FirefoxOptions) capabilities);
331+
}
312332
return this;
313333
}
314334

0 commit comments

Comments
 (0)