@@ -123,7 +123,7 @@ pub trait SeleniumManager {
123123 . cloned ( )
124124 }
125125
126- fn detect_browser_version ( & self , shell : & str , flag : & str , args : Vec < String > ) -> Option < String > {
126+ fn detect_browser_version ( & self , commands : Vec < String > ) -> Option < String > {
127127 let mut metadata = get_metadata ( self . get_logger ( ) ) ;
128128 let browser_name = & self . get_browser_name ( ) ;
129129
@@ -141,8 +141,8 @@ pub trait SeleniumManager {
141141 browser_name
142142 ) ) ;
143143 let mut browser_version = "" . to_string ( ) ;
144- for arg in args . iter ( ) {
145- let output = match self . run_shell_command ( shell , flag , arg . to_string ( ) ) {
144+ for command in commands . iter ( ) {
145+ let output = match self . run_shell_command_with_log ( command . to_string ( ) ) {
146146 Ok ( out) => out,
147147 Err ( _e) => continue ,
148148 } ;
@@ -221,10 +221,7 @@ pub trait SeleniumManager {
221221 }
222222
223223 fn find_driver_in_path ( & self ) -> ( Option < String > , Option < String > ) {
224- let ( shell, flag) = self . get_shell_command ( ) ;
225- match self . run_shell_command (
226- shell,
227- flag,
224+ match self . run_shell_command_with_log (
228225 self . format_one_arg ( DASH_DASH_VERSION , self . get_driver_name ( ) ) ,
229226 ) {
230227 Ok ( output) => {
@@ -235,9 +232,7 @@ pub trait SeleniumManager {
235232 } else {
236233 WHICH_COMMAND
237234 } ;
238- let driver_path = match self . run_shell_command (
239- shell,
240- flag,
235+ let driver_path = match self . run_shell_command_with_log (
241236 self . format_one_arg ( which_command, self . get_driver_name ( ) ) ,
242237 ) {
243238 Ok ( path) => Some ( path) ,
@@ -251,14 +246,6 @@ pub trait SeleniumManager {
251246 }
252247 }
253248
254- fn get_shell_command ( & self ) -> ( & str , & str ) {
255- if WINDOWS . is ( self . get_os ( ) ) {
256- ( "cmd" , "/C" )
257- } else {
258- ( "sh" , "-c" )
259- }
260- }
261-
262249 fn is_browser_version_unstable ( & self ) -> bool {
263250 let browser_version = self . get_browser_version ( ) ;
264251 browser_version. eq_ignore_ascii_case ( BETA )
@@ -307,21 +294,12 @@ pub trait SeleniumManager {
307294 Ok ( driver_path)
308295 }
309296
310- fn run_shell_command (
311- & self ,
312- command : & str ,
313- flag : & str ,
314- args : String ,
315- ) -> Result < String , Box < dyn Error > > {
297+ fn run_shell_command_with_log ( & self , command : String ) -> Result < String , Box < dyn Error > > {
316298 self . get_logger ( )
317- . debug ( format ! ( "Running {} command: {:?}" , command, args) ) ;
318- let output = Command :: new ( command) . args ( [ flag, args. as_str ( ) ] ) . output ( ) ?;
319- self . get_logger ( ) . debug ( format ! ( "{:?}" , output) ) ;
320-
321- Ok (
322- strip_trailing_newline ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) . as_str ( ) )
323- . to_string ( ) ,
324- )
299+ . debug ( format ! ( "Running command: {:?}" , command) ) ;
300+ let output = run_shell_command ( self . get_os ( ) , command) ?;
301+ self . get_logger ( ) . debug ( format ! ( "Output: {:?}" , output) ) ;
302+ Ok ( output)
325303 }
326304
327305 fn get_major_version ( & self , full_version : & str ) -> Result < String , Box < dyn Error > > {
@@ -527,3 +505,18 @@ fn strip_trailing_newline(input: &str) -> &str {
527505 . or_else ( || input. strip_suffix ( '\n' ) )
528506 . unwrap_or ( input)
529507}
508+
509+ pub fn run_shell_command ( os : & str , command : String ) -> Result < String , Box < dyn Error > > {
510+ let ( shell, flag) = if WINDOWS . is ( os) {
511+ ( "cmd" , "/C" )
512+ } else {
513+ ( "sh" , "-c" )
514+ } ;
515+ let output = Command :: new ( shell)
516+ . args ( [ flag, command. as_str ( ) ] )
517+ . output ( ) ?;
518+ Ok (
519+ strip_trailing_newline ( String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) . as_str ( ) )
520+ . to_string ( ) ,
521+ )
522+ }
0 commit comments