@@ -88,6 +88,8 @@ pub const UNAME_COMMAND: &str = "uname -{}";
8888pub const CRLF : & str = "\r \n " ;
8989pub const LF : & str = "\n " ;
9090pub const SNAPSHOT : & str = "SNAPSHOT" ;
91+ pub const OFFLINE_REQUEST_ERR_MSG : & str = "Unable to discover proper {} version in offline mode" ;
92+ pub const OFFLINE_DOWNLOAD_ERR_MSG : & str = "Unable to download {} in offline mode" ;
9193
9294pub trait SeleniumManager {
9395 // ----------------------------------------------------------
@@ -382,6 +384,7 @@ pub trait SeleniumManager {
382384 }
383385 } else {
384386 // If driver is not in the cache, download it
387+ self . assert_online_or_err ( OFFLINE_DOWNLOAD_ERR_MSG ) ?;
385388 self . download_driver ( ) ?;
386389 }
387390 Ok ( driver_path)
@@ -424,6 +427,13 @@ pub trait SeleniumManager {
424427 Ok ( format ! ( "selenium-{release_version}" ) )
425428 }
426429
430+ fn assert_online_or_err ( & self , message : & str ) -> Result < ( ) , Box < dyn Error > > {
431+ if self . is_offline ( ) {
432+ return Err ( format_one_arg ( message, self . get_driver_name ( ) ) . into ( ) ) ;
433+ }
434+ Ok ( ( ) )
435+ }
436+
427437 // ----------------------------------------------------------
428438 // Getters and setters for configuration parameters
429439 // ----------------------------------------------------------
@@ -493,7 +503,7 @@ pub trait SeleniumManager {
493503 . unwrap ( )
494504 . to_string ( )
495505 . replace ( "\\ \\ ?\\ " , "" )
496- . replace ( " \\ " , "\\ \\ " ) ;
506+ . replace ( '\\' , "\\ \\ " ) ;
497507 }
498508 browser_path
499509 }
@@ -510,7 +520,7 @@ pub trait SeleniumManager {
510520 }
511521
512522 fn set_proxy ( & mut self , proxy : String ) -> Result < ( ) , Box < dyn Error > > {
513- if !proxy. is_empty ( ) {
523+ if !proxy. is_empty ( ) && ! self . is_offline ( ) {
514524 self . get_logger ( ) . debug ( format ! ( "Using proxy: {}" , & proxy) ) ;
515525 let mut config = self . get_config_mut ( ) ;
516526 config. proxy = proxy;
@@ -557,6 +567,16 @@ pub trait SeleniumManager {
557567 fn set_browser_ttl ( & mut self , browser_ttl : u64 ) {
558568 self . get_config_mut ( ) . browser_ttl = browser_ttl;
559569 }
570+
571+ fn is_offline ( & self ) -> bool {
572+ self . get_config ( ) . offline
573+ }
574+
575+ fn set_offline ( & mut self , offline : bool ) {
576+ if offline {
577+ self . get_config_mut ( ) . offline = true ;
578+ }
579+ }
560580}
561581
562582// ----------------------------------------------------------
0 commit comments