Implementing another GeckoDriverService factory method that creates a service based on capabilities. This method is used by grid to honor firefox_binary capability.
import com.google.common.io.ByteStreams;
//import org.apache.commons.io.output.NullOutputStream;
+import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.remote.service.DriverService;
@@ -70,6 +71,27 @@ public static GeckoDriverService createDefaultService() {
return new Builder().usingAnyFreePort().build();
}
+ static GeckoDriverService createDefaultService(Capabilities caps) {
+ Builder builder = new Builder().usingAnyFreePort();
+
+ Object binary = caps.getCapability(FirefoxDriver.BINARY);
+ if (binary != null) {
+ FirefoxBinary actualBinary;
+ if (binary instanceof FirefoxBinary) {
+ actualBinary = (FirefoxBinary) binary;
+ } else if (binary instanceof String) {
+ actualBinary = new FirefoxBinary(new File(String.valueOf(binary)));
+ } else {
+ throw new IllegalArgumentException(
+ "Expected binary to be a string or a binary: " + binary);
+ }
+
+ builder.usingFirefoxBinary(actualBinary);
+ }
+
+ return new Builder().build();
+ }
+
@Override
protected void waitUntilAvailable() throws MalformedURLException {
PortProber.waitForPortUp(getUrl().getPort(), 20, SECONDS);
