Skip to content

Commit

Permalink
Merge pull request #1325 from Myriad-Dreamin/new-chromdriver-endpoint
Browse files Browse the repository at this point in the history
Use new chromdriver endpoint
  • Loading branch information
drager committed Nov 17, 2023
2 parents 77b8ced + 49c1e93 commit 8cba32f
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/test/webdriver/chromedriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::target;
use anyhow::{bail, Context, Result};
use binary_install::Cache;
use chrono::DateTime;
use std::collections::HashMap;
use std::path::PathBuf;

// Keep it up to date with each `wasm-pack` release.
Expand All @@ -28,7 +29,9 @@ pub fn install_chromedriver(cache: &Cache, installation_allowed: bool) -> Result
let target = if target::LINUX && target::x86_64 {
"linux64"
} else if target::MACOS && target::x86_64 {
"mac64"
"mac-x64"
} else if target::MACOS && target::aarch64 {
"mac-arm64"
} else if target::WINDOWS {
"win32"
} else {
Expand Down Expand Up @@ -116,19 +119,44 @@ fn should_load_chromedriver_version_from_stamp(json: &serde_json::Value) -> bool
}
}

/// Channel information from the chromedriver version endpoint.
#[derive(Deserialize)]
struct ChannelInfo {
version: String,
}

/// The response from the chromedriver version endpoint.
#[derive(Deserialize)]
struct GoodLatestVersions {
channels: HashMap<String, ChannelInfo>,
}

/// Retrieve the latest version of chromedriver from the json endpoints.
/// See: <https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints>
fn fetch_chromedriver_version() -> Result<String> {
let version = ureq::get("https://chromedriver.storage.googleapis.com/LATEST_RELEASE")
.call()
.context("fetching of chromedriver's LATEST_RELEASE failed")?
.into_string()
.context("converting chromedriver version response to string failed")?;
let info: GoodLatestVersions = ureq::get(
"https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json",
)
.call()
.context("fetching of chromedriver's LATEST_RELEASE failed")?
.into_json()
.context("converting chromedriver version response to GoodLatestVersions failed")?;

let version = info
.channels
.get("Stable")
.ok_or_else(|| anyhow::anyhow!("no Stable channel found in chromedriver version response"))?
.version
.clone();

println!("chromedriver version: {}", version);

Ok(version)
}

fn assemble_chromedriver_url(chromedriver_version: &str, target: &str) -> String {
format!(
"https://chromedriver.storage.googleapis.com/{version}/chromedriver_{target}.zip",
"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/{version}/{target}/chromedriver-{target}.zip",
version = chromedriver_version,
target = target,
)
Expand Down

0 comments on commit 8cba32f

Please sign in to comment.