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.
This commit is contained in:
jgraham 2016-06-29 11:23:57 +01:00 коммит произвёл GitHub
Родитель 97ebf2c998
Коммит 4642964c69
3 изменённых файлов: 58 добавлений и 12 удалений

44
Cargo.lock сгенерированный
Просмотреть файл

@ -8,7 +8,7 @@ dependencies = [
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "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)", "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)", "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]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.5.2" version = "0.5.2"
@ -122,6 +131,15 @@ dependencies = [
"unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "kernel32-sys" name = "kernel32-sys"
version = "0.2.2" version = "0.2.2"
@ -131,6 +149,15 @@ dependencies = [
"winapi-build 0.1.1 (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 = "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]] [[package]]
name = "language-tags" name = "language-tags"
version = "0.2.2" version = "0.2.2"
@ -193,11 +220,12 @@ dependencies = [
[[package]] [[package]]
name = "mozrunner" name = "mozrunner"
version = "0.3.0" version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"log 0.3.6 (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)", "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]] [[package]]
@ -387,6 +415,18 @@ name = "winapi-build"
version = "0.1.1" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" 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]] [[package]]
name = "zip" name = "zip"
version = "0.1.17" version = "0.1.17"

Просмотреть файл

@ -13,7 +13,7 @@ hyper = {version = "0.9", default-features = false}
lazy_static = "0.1" lazy_static = "0.1"
log = "0.3" log = "0.3"
mozprofile = "0.2" mozprofile = "0.2"
mozrunner = "0.3" mozrunner = "^0.3.1"
regex = "0.1.47" regex = "0.1.47"
rustc-serialize = "0.3.16" rustc-serialize = "0.3.16"
uuid = "0.1.18" uuid = "0.1.18"

Просмотреть файл

@ -2,6 +2,7 @@ use hyper::method::Method;
use mozprofile::preferences::Pref; use mozprofile::preferences::Pref;
use mozprofile::profile::Profile; use mozprofile::profile::Profile;
use mozrunner::runner::{Runner, FirefoxRunner, RunnerError}; use mozrunner::runner::{Runner, FirefoxRunner, RunnerError};
use mozrunner::runner::platform::firefox_default_path;
use regex::Captures; use regex::Captures;
use rustc_serialize::base64::FromBase64; use rustc_serialize::base64::FromBase64;
use rustc_serialize::json::{Json, ToJson}; use rustc_serialize::json::{Json, ToJson};
@ -325,15 +326,7 @@ impl MarionetteHandler {
let launcher = if self.connect_existing { let launcher = if self.connect_existing {
BrowserLauncher::None BrowserLauncher::None
} else { } else {
let binary = if let Some(binary_capability) = capabilities.get("firefox_binary") { let binary = try!(self.binary_path(capabilities));
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())
};
if let Some(path) = binary { if let Some(path) = binary {
BrowserLauncher::BinaryLauncher(path) BrowserLauncher::BinaryLauncher(path)
} else { } else {
@ -401,6 +394,19 @@ impl MarionetteHandler {
Ok(()) Ok(())
} }
fn binary_path(&self, capabilities: &NewSessionParameters) -> WebDriverResult<Option<PathBuf>> {
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<Option<Profile>> { pub fn load_profile(&self, capabilities: &NewSessionParameters) -> WebDriverResult<Option<Profile>> {
let profile_opt = capabilities.get("firefox_profile"); let profile_opt = capabilities.get("firefox_profile");
if profile_opt.is_none() { if profile_opt.is_none() {