Skip to content

Commit

Permalink
[rust] Selenium Manager honors full browser version (#13419)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia committed Oct 18, 2024
1 parent 7c9f000 commit 075b7c8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 46 deletions.
22 changes: 11 additions & 11 deletions rust/src/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,18 +521,18 @@ impl SeleniumManager for ChromeManager {
let good_versions_url = self.create_cft_url_for_browsers(GOOD_VERSIONS_ENDPOINT);
let all_versions =
self.request_versions_from_online::<VersionsWithDownloads>(&good_versions_url)?;
let filtered_versions: Vec<Version> = all_versions
.versions
.into_iter()
.filter(|r| r.version.starts_with(major_browser_version.as_str()))
.collect();
let inter_versions = all_versions.versions.into_iter();
let filtered_versions: Vec<Version> = if self.is_browser_version_specific() {
inter_versions
.filter(|r| r.version.eq(browser_version.as_str()))
.collect()
} else {
inter_versions
.filter(|r| r.version.starts_with(major_browser_version.as_str()))
.collect()
};
if filtered_versions.is_empty() {
return Err(anyhow!(format_three_args(
UNAVAILABLE_DOWNLOAD_WITH_MIN_VERSION_ERR_MSG,
browser_name,
&major_browser_version,
&MIN_CHROME_VERSION_CFT.to_string(),
)));
return self.unavailable_download();
}
let last_browser = filtered_versions.last().unwrap();
let platform_url: Vec<&PlatformUrl> = last_browser
Expand Down
82 changes: 47 additions & 35 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,43 +237,47 @@ pub trait SeleniumManager {
)));
}

// Browser version is checked in the local metadata
match get_browser_version_from_metadata(
&metadata.browsers,
self.get_browser_name(),
&major_browser_version,
) {
Some(version) => {
self.get_logger().trace(format!(
"Browser with valid TTL. Getting {} version from metadata",
self.get_browser_name()
));
browser_version = version;
self.set_browser_version(browser_version.clone());
}
_ => {
// If not in metadata, discover version using online metadata
if self.is_browser_version_stable() || self.is_browser_version_empty() {
browser_version =
self.request_latest_browser_version_from_online(original_browser_version)?;
} else {
browser_version =
self.request_fixed_browser_version_from_online(original_browser_version)?;
if self.is_version_specific(original_browser_version) {
browser_version = original_browser_version.to_string();
} else {
// Browser version is checked in the local metadata
match get_browser_version_from_metadata(
&metadata.browsers,
self.get_browser_name(),
&major_browser_version,
) {
Some(version) => {
self.get_logger().trace(format!(
"Browser with valid TTL. Getting {} version from metadata",
self.get_browser_name()
));
browser_version = version;
self.set_browser_version(browser_version.clone());
}
self.set_browser_version(browser_version.clone());
_ => {
// If not in metadata, discover version using online metadata
if self.is_browser_version_stable() || self.is_browser_version_empty() {
browser_version = self
.request_latest_browser_version_from_online(original_browser_version)?;
} else {
browser_version = self
.request_fixed_browser_version_from_online(original_browser_version)?;
}
self.set_browser_version(browser_version.clone());

let browser_ttl = self.get_ttl();
if browser_ttl > 0
&& !self.is_browser_version_empty()
&& !self.is_browser_version_stable()
{
metadata.browsers.push(create_browser_metadata(
self.get_browser_name(),
&major_browser_version,
&browser_version,
browser_ttl,
));
write_metadata(&metadata, self.get_logger(), cache_path);
let browser_ttl = self.get_ttl();
if browser_ttl > 0
&& !self.is_browser_version_empty()
&& !self.is_browser_version_stable()
{
metadata.browsers.push(create_browser_metadata(
self.get_browser_name(),
&major_browser_version,
&browser_version,
browser_ttl,
));
write_metadata(&metadata, self.get_logger(), cache_path);
}
}
}
}
Expand Down Expand Up @@ -715,6 +719,14 @@ pub trait SeleniumManager {
self.is_stable(self.get_browser_version())
}

fn is_version_specific(&self, version: &str) -> bool {
version.contains(".")
}

fn is_browser_version_specific(&self) -> bool {
self.is_version_specific(self.get_browser_version())
}

fn setup(&mut self) -> Result<PathBuf, Error> {
let mut driver_in_path = None;
let mut driver_in_path_version = None;
Expand Down
3 changes: 3 additions & 0 deletions rust/tests/browser_download_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ fn browser_latest_download_test(#[case] browser: String) {

#[rstest]
#[case("chrome", "113")]
#[case("chrome", "131.0.6725.0")]
#[case("chrome", "beta")]
#[case("firefox", "116")]
#[case("firefox", "121.0.1")]
#[case("firefox", "beta")]
#[case("firefox", "esr")]
#[case("edge", "129.0.2792.79")]
#[case("edge", "beta")]
fn browser_version_download_test(#[case] browser: String, #[case] browser_version: String) {
if OS.eq("windows") && browser.eq("edge") {
Expand Down

0 comments on commit 075b7c8

Please sign in to comment.