Skip to content

Commit 04b0789

Browse files
committed
Prefer required capabilities to desired in FirefoxOptions
1 parent 086c655 commit 04b0789

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,16 @@ public Optional<FirefoxBinary> getBinaryOrNull() {
191191
return Optional.of(new FirefoxBinary(new File(binaryPath)));
192192
}
193193

194-
if (desiredCapabilities.getCapability(FirefoxDriver.BINARY) != null) {
195-
Object raw = desiredCapabilities.getCapability(FirefoxDriver.BINARY);
194+
return Stream.of(requiredCapabilities, desiredCapabilities)
195+
.map(this::determineBinaryFromCapabilities)
196+
.filter(Optional::isPresent)
197+
.findFirst()
198+
.orElse(Optional.empty());
199+
}
200+
201+
private Optional<FirefoxBinary> determineBinaryFromCapabilities(Capabilities caps) {
202+
if (caps.getCapability(FirefoxDriver.BINARY) != null) {
203+
Object raw = caps.getCapability(FirefoxDriver.BINARY);
196204
if (raw instanceof FirefoxBinary) {
197205
return Optional.of((FirefoxBinary) raw);
198206
} else {
@@ -204,17 +212,17 @@ public Optional<FirefoxBinary> getBinaryOrNull() {
204212
}
205213
}
206214

207-
if (desiredCapabilities.getCapability(CapabilityType.VERSION) != null) {
215+
if (caps.getCapability(CapabilityType.VERSION) != null) {
208216
try {
209217
FirefoxBinary.Channel channel = FirefoxBinary.Channel.fromString(
210-
(String) desiredCapabilities.getCapability(CapabilityType.VERSION));
218+
(String) caps.getCapability(CapabilityType.VERSION));
211219
return Optional.of(new FirefoxBinary(channel));
212220
} catch (WebDriverException ex) {
213221
return Optional.of(new FirefoxBinary(
214-
(String) desiredCapabilities.getCapability(CapabilityType.VERSION)));
222+
(String) caps.getCapability(CapabilityType.VERSION)));
215223
}
216224
}
217-
// last resort
225+
218226
return Optional.empty();
219227
}
220228

@@ -226,10 +234,10 @@ public FirefoxOptions setProfile(FirefoxProfile profile) {
226234
public FirefoxProfile getProfile() {
227235
FirefoxProfile profileToUse = profile;
228236
if (profileToUse == null) {
229-
profileToUse = extractProfile(desiredCapabilities);
237+
profileToUse = extractProfile(requiredCapabilities);
230238
}
231239
if (profileToUse == null) {
232-
profileToUse = extractProfile(requiredCapabilities);
240+
profileToUse = extractProfile(desiredCapabilities);
233241
}
234242
if (profileToUse == null) {
235243
String suggestedProfile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_PROFILE);

0 commit comments

Comments
 (0)