@@ -191,8 +191,16 @@ public Optional<FirefoxBinary> getBinaryOrNull() {
191
191
return Optional .of (new FirefoxBinary (new File (binaryPath )));
192
192
}
193
193
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 );
196
204
if (raw instanceof FirefoxBinary ) {
197
205
return Optional .of ((FirefoxBinary ) raw );
198
206
} else {
@@ -204,17 +212,17 @@ public Optional<FirefoxBinary> getBinaryOrNull() {
204
212
}
205
213
}
206
214
207
- if (desiredCapabilities .getCapability (CapabilityType .VERSION ) != null ) {
215
+ if (caps .getCapability (CapabilityType .VERSION ) != null ) {
208
216
try {
209
217
FirefoxBinary .Channel channel = FirefoxBinary .Channel .fromString (
210
- (String ) desiredCapabilities .getCapability (CapabilityType .VERSION ));
218
+ (String ) caps .getCapability (CapabilityType .VERSION ));
211
219
return Optional .of (new FirefoxBinary (channel ));
212
220
} catch (WebDriverException ex ) {
213
221
return Optional .of (new FirefoxBinary (
214
- (String ) desiredCapabilities .getCapability (CapabilityType .VERSION )));
222
+ (String ) caps .getCapability (CapabilityType .VERSION )));
215
223
}
216
224
}
217
- // last resort
225
+
218
226
return Optional .empty ();
219
227
}
220
228
@@ -226,10 +234,10 @@ public FirefoxOptions setProfile(FirefoxProfile profile) {
226
234
public FirefoxProfile getProfile () {
227
235
FirefoxProfile profileToUse = profile ;
228
236
if (profileToUse == null ) {
229
- profileToUse = extractProfile (desiredCapabilities );
237
+ profileToUse = extractProfile (requiredCapabilities );
230
238
}
231
239
if (profileToUse == null ) {
232
- profileToUse = extractProfile (requiredCapabilities );
240
+ profileToUse = extractProfile (desiredCapabilities );
233
241
}
234
242
if (profileToUse == null ) {
235
243
String suggestedProfile = System .getProperty (FirefoxDriver .SystemProperty .BROWSER_PROFILE );
0 commit comments