From 4642964c69e488becec392141c3b9c4175c26f1a Mon Sep 17 00:00:00 2001 From: jgraham Date: Wed, 29 Jun 2016 11:23:57 +0100 Subject: [PATCH] Use firefox default path if no other path information is supplied. (#121) If a path is not provided in the new session command, or when starting geckodriver, try to determine the firefox path by introspecting the system. --- Cargo.lock | 44 ++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- src/marionette.rs | 24 +++++++++++++++--------- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f758487..4d4b541 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ dependencies = [ "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mozprofile 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "mozrunner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "mozrunner 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.71 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -16,6 +16,15 @@ dependencies = [ "zip 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "advapi32-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "aho-corasick" version = "0.5.2" @@ -122,6 +131,15 @@ dependencies = [ "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "kernel32-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -131,6 +149,15 @@ dependencies = [ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ktmw32-sys" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "language-tags" version = "0.2.2" @@ -193,11 +220,12 @@ dependencies = [ [[package]] name = "mozrunner" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "mozprofile 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winreg 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -387,6 +415,18 @@ name = "winapi-build" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winreg" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "advapi32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ktmw32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "zip" version = "0.1.17" diff --git a/Cargo.toml b/Cargo.toml index a1b56a1..da452a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ hyper = {version = "0.9", default-features = false} lazy_static = "0.1" log = "0.3" mozprofile = "0.2" -mozrunner = "0.3" +mozrunner = "^0.3.1" regex = "0.1.47" rustc-serialize = "0.3.16" uuid = "0.1.18" diff --git a/src/marionette.rs b/src/marionette.rs index ee1fe3e..d875842 100644 --- a/src/marionette.rs +++ b/src/marionette.rs @@ -2,6 +2,7 @@ use hyper::method::Method; use mozprofile::preferences::Pref; use mozprofile::profile::Profile; use mozrunner::runner::{Runner, FirefoxRunner, RunnerError}; +use mozrunner::runner::platform::firefox_default_path; use regex::Captures; use rustc_serialize::base64::FromBase64; use rustc_serialize::json::{Json, ToJson}; @@ -325,15 +326,7 @@ impl MarionetteHandler { let launcher = if self.connect_existing { BrowserLauncher::None } else { - let binary = if let Some(binary_capability) = capabilities.get("firefox_binary") { - Some(PathBuf::from(try!(binary_capability - .as_string() - .ok_or(WebDriverError::new( - ErrorStatus::InvalidArgument, - "'firefox_binary' capability was not a string"))))) - } else { - self.binary.as_ref().map(|x| x.clone()) - }; + let binary = try!(self.binary_path(capabilities)); if let Some(path) = binary { BrowserLauncher::BinaryLauncher(path) } else { @@ -401,6 +394,19 @@ impl MarionetteHandler { Ok(()) } + fn binary_path(&self, capabilities: &NewSessionParameters) -> WebDriverResult> { + if let Some(binary_capability) = capabilities.get("firefox_binary") { + Ok(Some(PathBuf::from(try!(binary_capability + .as_string() + .ok_or(WebDriverError::new( + ErrorStatus::InvalidArgument, + "'firefox_binary' capability was not a string")))))) + } else if self.binary.is_some() { + Ok(self.binary.as_ref().map(|x| x.clone())) + } else { + Ok(firefox_default_path()) + } + } pub fn load_profile(&self, capabilities: &NewSessionParameters) -> WebDriverResult> { let profile_opt = capabilities.get("firefox_profile"); if profile_opt.is_none() {