3434import java .util .ArrayList ;
3535import java .util .Arrays ;
3636import java .util .List ;
37+ import java .util .Map ;
3738import java .util .logging .Logger ;
3839
3940import static java .nio .file .StandardCopyOption .REPLACE_EXISTING ;
@@ -157,6 +158,29 @@ private synchronized File getBinary() {
157158 return binary ;
158159 }
159160
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+
160184 /**
161185 * Determines the location of the correct driver.
162186 * @param options Browser Options instance.
@@ -175,6 +199,12 @@ public String getDriverPath(Capabilities options) {
175199 if (!options .getBrowserVersion ().isEmpty ()) {
176200 commandList .addAll (Arrays .asList ("--browser-version" , options .getBrowserVersion ()));
177201 }
202+
203+ String browserBinary = getBrowserBinary (options );
204+ if (browserBinary != null && !browserBinary .isEmpty ()) {
205+ commandList .addAll (Arrays .asList ("--browser-path" , browserBinary ));
206+ }
207+
178208 return runCommand (commandList .toArray (new String [0 ]));
179209 }
180210}
0 commit comments