mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 22:22:12 +00:00
Add parse a env args to invocation the browser
This commit is contained in:
parent
732b691bb8
commit
b60ed2ee27
@ -20,7 +20,7 @@ use std::time::{Duration, Instant};
|
|||||||
/// etc. It will return `Ok` if all tests finish successfully, and otherwise it
|
/// etc. It will return `Ok` if all tests finish successfully, and otherwise it
|
||||||
/// will return an error if some tests failed.
|
/// will return an error if some tests failed.
|
||||||
pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
|
pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
|
||||||
let (driver, args) = Driver::find()?;
|
let (driver, args, mut client_args) = Driver::find()?;
|
||||||
println!(
|
println!(
|
||||||
"Running headless tests in {} with `{}`",
|
"Running headless tests in {} with `{}`",
|
||||||
driver.browser(),
|
driver.browser(),
|
||||||
@ -64,7 +64,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
|
|||||||
shell.status("Starting new webdriver session...");
|
shell.status("Starting new webdriver session...");
|
||||||
// Allocate a new session with the webdriver protocol, and once we've done
|
// 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`.
|
// 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());
|
client.session = Some(id.clone());
|
||||||
|
|
||||||
// Visit our local server to open up the page that runs tests, and then get
|
// Visit our local server to open up the page that runs tests, and then get
|
||||||
@ -149,17 +149,20 @@ impl Driver {
|
|||||||
/// * Env vars like `GECKODRIVER` point to the path to a binary to execute.
|
/// * Env vars like `GECKODRIVER` point to the path to a binary to execute.
|
||||||
/// * Otherwise, `PATH` is searched for an appropriate binary.
|
/// * Otherwise, `PATH` is searched for an appropriate binary.
|
||||||
///
|
///
|
||||||
/// In both cases a list of auxiliary arguments is also returned which is
|
/// In both cases a lists of auxiliary arguments is also returned which is
|
||||||
/// configured through env vars like `GECKODRIVER_ARGS` to support extra
|
/// configured through env vars like `GECKODRIVER_ARGS` and
|
||||||
/// arguments to the driver's invocation.
|
/// `GECKODRIVER_CLIENT_ARGS` to support extra arguments to invocation the
|
||||||
fn find() -> Result<(Driver, Vec<String>), Error> {
|
/// driver and a browser respectively.
|
||||||
let env_args = |name: &str| {
|
fn find() -> Result<(Driver, Vec<String>, Vec<String>), Error> {
|
||||||
env::var(format!("{}_ARGS", name.to_uppercase()))
|
let env_vars = |name: String| {
|
||||||
|
env::var(name)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect::<Vec<_>>()
|
.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 = [
|
let drivers = [
|
||||||
("geckodriver", Driver::Gecko as fn(PathBuf) -> Driver),
|
("geckodriver", Driver::Gecko as fn(PathBuf) -> Driver),
|
||||||
@ -175,7 +178,7 @@ impl Driver {
|
|||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => continue,
|
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
|
// Next, check PATH. If we can find any supported driver, use that by
|
||||||
@ -190,7 +193,7 @@ impl Driver {
|
|||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => continue,
|
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
|
// TODO: download an appropriate driver? How to know which one to
|
||||||
@ -255,7 +258,7 @@ enum Method<'a> {
|
|||||||
// copied the `webdriver-client` crate when writing the below bindings.
|
// copied the `webdriver-client` crate when writing the below bindings.
|
||||||
|
|
||||||
impl Client {
|
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 {
|
match driver {
|
||||||
Driver::Gecko(_) => {
|
Driver::Gecko(_) => {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@ -268,11 +271,12 @@ impl Client {
|
|||||||
#[serde(rename = "sessionId")]
|
#[serde(rename = "sessionId")]
|
||||||
session_id: String,
|
session_id: String,
|
||||||
}
|
}
|
||||||
|
args.push("-headless".to_string());
|
||||||
let request = json!({
|
let request = json!({
|
||||||
"capabilities": {
|
"capabilities": {
|
||||||
"alwaysMatch": {
|
"alwaysMatch": {
|
||||||
"moz:firefoxOptions": {
|
"moz:firefoxOptions": {
|
||||||
"args": ["-headless"],
|
"args": args,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,17 +320,16 @@ impl Client {
|
|||||||
#[serde(rename = "sessionId")]
|
#[serde(rename = "sessionId")]
|
||||||
session_id: String,
|
session_id: String,
|
||||||
}
|
}
|
||||||
let request = json!({
|
args.push("headless".to_string());
|
||||||
"desiredCapabilities": {
|
|
||||||
"goog:chromeOptions": {
|
|
||||||
"args": [
|
|
||||||
"headless",
|
|
||||||
// See https://stackoverflow.com/questions/50642308/
|
// See https://stackoverflow.com/questions/50642308/
|
||||||
// for what this funky `disable-dev-shm-usage`
|
// for what this funky `disable-dev-shm-usage`
|
||||||
// option is
|
// option is
|
||||||
"disable-dev-shm-usage",
|
args.push("disable-dev-shm-usage".to_string());
|
||||||
"no-sandbox",
|
args.push("no-sandbox".to_string());
|
||||||
],
|
let request = json!({
|
||||||
|
"desiredCapabilities": {
|
||||||
|
"goog:chromeOptions": {
|
||||||
|
"args": args,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user