34
34
import java .util .ArrayList ;
35
35
import java .util .Arrays ;
36
36
import java .util .List ;
37
+ import java .util .Map ;
37
38
import java .util .logging .Logger ;
38
39
39
40
import static java .nio .file .StandardCopyOption .REPLACE_EXISTING ;
@@ -157,6 +158,29 @@ private synchronized File getBinary() {
157
158
return binary ;
158
159
}
159
160
161
+ /**
162
+ * Returns the browser binary path when present in the vendor options
163
+ *
164
+ * @param options browser options used to start the session
165
+ * @return the browser binary path when present, only Chrome/Firefox/Edge
166
+ */
167
+ private String getBrowserBinary (Capabilities options ) {
168
+ List <String > vendorOptionsCapabilities = Arrays .asList ("moz:firefoxOptions" , "goog:chromeOptions" , "ms:edgeOptions" );
169
+ for (String vendorOptionsCapability : vendorOptionsCapabilities ) {
170
+ if (options .asMap ().containsKey (vendorOptionsCapability )) {
171
+ try {
172
+ @ SuppressWarnings ("unchecked" )
173
+ Map <String , Object > vendorOptions = (Map <String , Object >) options .getCapability (vendorOptionsCapability );
174
+ return (String ) vendorOptions .get ("binary" );
175
+ } catch (Exception e ) {
176
+ LOG .warning (String .format ("Exception while retrieving the browser binary path. %s: %s" ,
177
+ options , e .getMessage ()));
178
+ }
179
+ }
180
+ }
181
+ return null ;
182
+ }
183
+
160
184
/**
161
185
* Determines the location of the correct driver.
162
186
* @param options Browser Options instance.
@@ -175,6 +199,12 @@ public String getDriverPath(Capabilities options) {
175
199
if (!options .getBrowserVersion ().isEmpty ()) {
176
200
commandList .addAll (Arrays .asList ("--browser-version" , options .getBrowserVersion ()));
177
201
}
202
+
203
+ String browserBinary = getBrowserBinary (options );
204
+ if (browserBinary != null && !browserBinary .isEmpty ()) {
205
+ commandList .addAll (Arrays .asList ("--browser-path" , browserBinary ));
206
+ }
207
+
178
208
return runCommand (commandList .toArray (new String [0 ]));
179
209
}
180
210
}
0 commit comments