@@ -88,6 +88,8 @@ pub const UNAME_COMMAND: &str = "uname -{}";
88
88
pub const CRLF : & str = "\r \n " ;
89
89
pub const LF : & str = "\n " ;
90
90
pub 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" ;
91
93
92
94
pub trait SeleniumManager {
93
95
// ----------------------------------------------------------
@@ -382,6 +384,7 @@ pub trait SeleniumManager {
382
384
}
383
385
} else {
384
386
// If driver is not in the cache, download it
387
+ self . assert_online_or_err ( OFFLINE_DOWNLOAD_ERR_MSG ) ?;
385
388
self . download_driver ( ) ?;
386
389
}
387
390
Ok ( driver_path)
@@ -424,6 +427,13 @@ pub trait SeleniumManager {
424
427
Ok ( format ! ( "selenium-{release_version}" ) )
425
428
}
426
429
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
+
427
437
// ----------------------------------------------------------
428
438
// Getters and setters for configuration parameters
429
439
// ----------------------------------------------------------
@@ -493,7 +503,7 @@ pub trait SeleniumManager {
493
503
. unwrap ( )
494
504
. to_string ( )
495
505
. replace ( "\\ \\ ?\\ " , "" )
496
- . replace ( " \\ " , "\\ \\ " ) ;
506
+ . replace ( '\\' , "\\ \\ " ) ;
497
507
}
498
508
browser_path
499
509
}
@@ -510,7 +520,7 @@ pub trait SeleniumManager {
510
520
}
511
521
512
522
fn set_proxy ( & mut self , proxy : String ) -> Result < ( ) , Box < dyn Error > > {
513
- if !proxy. is_empty ( ) {
523
+ if !proxy. is_empty ( ) && ! self . is_offline ( ) {
514
524
self . get_logger ( ) . debug ( format ! ( "Using proxy: {}" , & proxy) ) ;
515
525
let mut config = self . get_config_mut ( ) ;
516
526
config. proxy = proxy;
@@ -557,6 +567,16 @@ pub trait SeleniumManager {
557
567
fn set_browser_ttl ( & mut self , browser_ttl : u64 ) {
558
568
self . get_config_mut ( ) . browser_ttl = browser_ttl;
559
569
}
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
+ }
560
580
}
561
581
562
582
// ----------------------------------------------------------
0 commit comments