Skip to content

Add parse a env args to invocation the browser #1703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::time::{Duration, Instant};
/// etc. It will return `Ok` if all tests finish successfully, and otherwise it
/// will return an error if some tests failed.
pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
let (driver, args) = Driver::find()?;
let (driver, args, mut client_args) = Driver::find()?;
println!(
"Running headless tests in {} with `{}`",
driver.browser(),
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
shell.status("Starting new webdriver session...");
// Allocate a new session with the webdriver protocol, and once we've done
// so schedule the browser to get closed with a call to `close_window`.
let id = client.new_session(&driver)?;
let id = client.new_session(&driver, &mut client_args)?;
client.session = Some(id.clone());

// Visit our local server to open up the page that runs tests, and then get
Expand Down Expand Up @@ -149,17 +149,20 @@ impl Driver {
/// * Env vars like `GECKODRIVER` point to the path to a binary to execute.
/// * Otherwise, `PATH` is searched for an appropriate binary.
///
/// In both cases a list of auxiliary arguments is also returned which is
/// configured through env vars like `GECKODRIVER_ARGS` to support extra
/// arguments to the driver's invocation.
fn find() -> Result<(Driver, Vec<String>), Error> {
let env_args = |name: &str| {
env::var(format!("{}_ARGS", name.to_uppercase()))
/// In both cases a lists of auxiliary arguments is also returned which is
/// configured through env vars like `GECKODRIVER_ARGS` and
/// `GECKODRIVER_CLIENT_ARGS` to support extra arguments to invocation the
/// driver and a browser respectively.
fn find() -> Result<(Driver, Vec<String>, Vec<String>), Error> {
let env_vars = |name: String| {
env::var(name)
.unwrap_or_default()
.split_whitespace()
.map(|s| s.to_string())
.collect::<Vec<_>>()
};
let env_args = |name: &str| env_vars(format!("{}_ARGS", name.to_uppercase()));
let env_client_args = |name: &str| env_vars(format!("{}_CLIENT_ARGS", name.to_uppercase()));

let drivers = [
("geckodriver", Driver::Gecko as fn(PathBuf) -> Driver),
Expand All @@ -175,7 +178,7 @@ impl Driver {
Some(path) => path,
None => continue,
};
return Ok((ctor(path.into()), env_args(driver)));
return Ok((ctor(path.into()), env_args(driver), env_client_args(driver)));
}

// Next, check PATH. If we can find any supported driver, use that by
Expand All @@ -190,7 +193,7 @@ impl Driver {
Some(p) => p,
None => continue,
};
return Ok((ctor(name.into()), env_args(name)));
return Ok((ctor(name.into()), env_args(name), env_client_args(name)));
}

// TODO: download an appropriate driver? How to know which one to
Expand Down Expand Up @@ -255,7 +258,7 @@ enum Method<'a> {
// copied the `webdriver-client` crate when writing the below bindings.

impl Client {
fn new_session(&mut self, driver: &Driver) -> Result<String, Error> {
fn new_session(&mut self, driver: &Driver, args: &mut Vec<String>) -> Result<String, Error> {
match driver {
Driver::Gecko(_) => {
#[derive(Deserialize)]
Expand All @@ -268,11 +271,12 @@ impl Client {
#[serde(rename = "sessionId")]
session_id: String,
}
args.push("-headless".to_string());
let request = json!({
"capabilities": {
"alwaysMatch": {
"moz:firefoxOptions": {
"args": ["-headless"],
"args": args,
}
}
}
Expand Down Expand Up @@ -316,17 +320,16 @@ impl Client {
#[serde(rename = "sessionId")]
session_id: String,
}
args.push("headless".to_string());
// See https://stackoverflow.com/questions/50642308/
// for what this funky `disable-dev-shm-usage`
// option is
args.push("disable-dev-shm-usage".to_string());
args.push("no-sandbox".to_string());
let request = json!({
"desiredCapabilities": {
"goog:chromeOptions": {
"args": [
"headless",
// See https://stackoverflow.com/questions/50642308/
// for what this funky `disable-dev-shm-usage`
// option is
"disable-dev-shm-usage",
"no-sandbox",
],
"args": args,
},
}
});
Expand Down