Skip to content
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

Use new chromdriver endpoint #1325

Merged
merged 2 commits into from
Nov 17, 2023
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
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
Loading