Skip to content

Commit 60302ba

Browse files
committed
[rust] Support snap packages (Firefox, Chromium) in Selenium Manager
1 parent 3cb7784 commit 60302ba

File tree

8 files changed

+81
-2
lines changed

8 files changed

+81
-2
lines changed

rust/src/chrome.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use reqwest::Client;
3535
use serde::{Deserialize, Serialize};
3636
use std::collections::HashMap;
3737
use std::option::Option;
38-
use std::path::PathBuf;
38+
use std::path::{Path, PathBuf};
3939
use std::sync::mpsc;
4040
use std::sync::mpsc::{Receiver, Sender};
4141

@@ -50,6 +50,8 @@ const CFT_MACOS_APP_NAME: &str =
5050
"Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing";
5151
const MIN_CHROME_VERSION_CFT: i32 = 113;
5252
const MIN_CHROMEDRIVER_VERSION_CFT: i32 = 115;
53+
const CHROMIUM_SNAP_LINK: &str = "/snap/bin/chromium";
54+
const CHROMIUM_SNAP_BINARY: &str = "/snap/chromium/current/usr/lib/chromium-browser/chrome";
5355

5456
pub struct ChromeManager {
5557
pub browser_name: &'static str,
@@ -587,6 +589,15 @@ impl SeleniumManager for ChromeManager {
587589
fn set_download_browser(&mut self, download_browser: bool) {
588590
self.download_browser = download_browser;
589591
}
592+
593+
fn is_snap(&self, browser_path: &str) -> bool {
594+
LINUX.is(self.get_os())
595+
&& (browser_path.eq(CHROMIUM_SNAP_LINK) || browser_path.eq(CHROMIUM_SNAP_BINARY))
596+
}
597+
598+
fn get_snap_path(&self) -> Option<PathBuf> {
599+
Some(Path::new(CHROMIUM_SNAP_BINARY).to_path_buf())
600+
}
590601
}
591602

592603
#[derive(Serialize, Deserialize)]

rust/src/edge.rs

+8
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ impl SeleniumManager for EdgeManager {
551551
fn set_download_browser(&mut self, download_browser: bool) {
552552
self.download_browser = download_browser;
553553
}
554+
555+
fn is_snap(&self, _browser_path: &str) -> bool {
556+
false
557+
}
558+
559+
fn get_snap_path(&self) -> Option<PathBuf> {
560+
None
561+
}
554562
}
555563

556564
#[derive(Serialize, Deserialize, Debug)]

rust/src/firefox.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use serde::Deserialize;
3434
use serde::Serialize;
3535
use serde_json::Value;
3636
use std::collections::HashMap;
37-
use std::path::PathBuf;
37+
use std::path::{Path, PathBuf};
3838
use std::sync::mpsc;
3939
use std::sync::mpsc::{Receiver, Sender};
4040

@@ -66,6 +66,8 @@ const MIN_DOWNLOADABLE_FIREFOX_VERSION_MAC: i32 = 4;
6666
const MIN_DOWNLOADABLE_FIREFOX_VERSION_LINUX: i32 = 4;
6767
const UNAVAILABLE_DOWNLOAD_ERROR_MESSAGE: &str =
6868
"{} {} not available for downloading (minimum version: {})";
69+
const FIREFOX_SNAP_LINK: &str = "/snap/bin/firefox";
70+
const FIREFOX_SNAP_BINARY: &str = "/snap/firefox/current/usr/lib/firefox/firefox";
6971

7072
pub struct FirefoxManager {
7173
pub browser_name: &'static str,
@@ -629,6 +631,15 @@ impl SeleniumManager for FirefoxManager {
629631
fn set_download_browser(&mut self, download_browser: bool) {
630632
self.download_browser = download_browser;
631633
}
634+
635+
fn is_snap(&self, browser_path: &str) -> bool {
636+
LINUX.is(self.get_os())
637+
&& (browser_path.eq(FIREFOX_SNAP_LINK) || browser_path.eq(FIREFOX_SNAP_BINARY))
638+
}
639+
640+
fn get_snap_path(&self) -> Option<PathBuf> {
641+
Some(Path::new(FIREFOX_SNAP_BINARY).to_path_buf())
642+
}
632643
}
633644

634645
#[derive(Serialize, Deserialize, Debug)]

rust/src/grid.rs

+8
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,12 @@ impl SeleniumManager for GridManager {
296296
fn set_download_browser(&mut self, download_browser: bool) {
297297
self.download_browser = download_browser;
298298
}
299+
300+
fn is_snap(&self, _browser_path: &str) -> bool {
301+
false
302+
}
303+
304+
fn get_snap_path(&self) -> Option<PathBuf> {
305+
None
306+
}
299307
}

rust/src/iexplorer.rs

+8
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,12 @@ impl SeleniumManager for IExplorerManager {
292292
fn set_download_browser(&mut self, download_browser: bool) {
293293
self.download_browser = download_browser;
294294
}
295+
296+
fn is_snap(&self, _browser_path: &str) -> bool {
297+
false
298+
}
299+
300+
fn get_snap_path(&self) -> Option<PathBuf> {
301+
None
302+
}
295303
}

rust/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ pub trait SeleniumManager {
180180

181181
fn set_download_browser(&mut self, download_browser: bool);
182182

183+
fn is_snap(&self, browser_path: &str) -> bool;
184+
185+
fn get_snap_path(&self) -> Option<PathBuf>;
186+
183187
// ----------------------------------------------------------
184188
// Shared functions
185189
// ----------------------------------------------------------
@@ -605,6 +609,18 @@ pub trait SeleniumManager {
605609
if let Some(path) = browser_path {
606610
self.get_logger()
607611
.debug(format!("Found {} in PATH: {}", browser_name, &path));
612+
if self.is_snap(&path) {
613+
if let Some(snap_path) = self.get_snap_path() {
614+
if snap_path.exists() {
615+
self.get_logger().debug(format!(
616+
"Using {} snap: {}",
617+
browser_name,
618+
path_to_string(snap_path.as_path())
619+
));
620+
return Some(snap_path);
621+
}
622+
}
623+
}
608624
return Some(Path::new(&path).to_path_buf());
609625
}
610626
}
@@ -825,6 +841,7 @@ pub trait SeleniumManager {
825841

826842
// Display warning if the discovered driver version is not the same as the driver in PATH
827843
if !self.get_driver_version().is_empty()
844+
&& !self.is_snap(self.get_browser_path())
828845
&& (self.is_firefox() && !version.eq(self.get_driver_version()))
829846
|| (!self.is_firefox() && !major_version.eq(&self.get_major_browser_version()))
830847
{

rust/src/safari.rs

+8
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,12 @@ impl SeleniumManager for SafariManager {
185185
fn set_download_browser(&mut self, download_browser: bool) {
186186
self.download_browser = download_browser;
187187
}
188+
189+
fn is_snap(&self, _browser_path: &str) -> bool {
190+
false
191+
}
192+
193+
fn get_snap_path(&self) -> Option<PathBuf> {
194+
None
195+
}
188196
}

rust/src/safaritp.rs

+8
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,12 @@ impl SeleniumManager for SafariTPManager {
193193
fn set_download_browser(&mut self, download_browser: bool) {
194194
self.download_browser = download_browser;
195195
}
196+
197+
fn is_snap(&self, _browser_path: &str) -> bool {
198+
false
199+
}
200+
201+
fn get_snap_path(&self) -> Option<PathBuf> {
202+
None
203+
}
196204
}

0 commit comments

Comments
 (0)