@@ -123,7 +123,7 @@ pub trait SeleniumManager {
123
123
. cloned ( )
124
124
}
125
125
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 > {
127
127
let mut metadata = get_metadata ( self . get_logger ( ) ) ;
128
128
let browser_name = & self . get_browser_name ( ) ;
129
129
@@ -141,8 +141,8 @@ pub trait SeleniumManager {
141
141
browser_name
142
142
) ) ;
143
143
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 ( ) ) {
146
146
Ok ( out) => out,
147
147
Err ( _e) => continue ,
148
148
} ;
@@ -221,10 +221,7 @@ pub trait SeleniumManager {
221
221
}
222
222
223
223
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 (
228
225
self . format_one_arg ( DASH_DASH_VERSION , self . get_driver_name ( ) ) ,
229
226
) {
230
227
Ok ( output) => {
@@ -235,9 +232,7 @@ pub trait SeleniumManager {
235
232
} else {
236
233
WHICH_COMMAND
237
234
} ;
238
- let driver_path = match self . run_shell_command (
239
- shell,
240
- flag,
235
+ let driver_path = match self . run_shell_command_with_log (
241
236
self . format_one_arg ( which_command, self . get_driver_name ( ) ) ,
242
237
) {
243
238
Ok ( path) => Some ( path) ,
@@ -251,14 +246,6 @@ pub trait SeleniumManager {
251
246
}
252
247
}
253
248
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
-
262
249
fn is_browser_version_unstable ( & self ) -> bool {
263
250
let browser_version = self . get_browser_version ( ) ;
264
251
browser_version. eq_ignore_ascii_case ( BETA )
@@ -307,21 +294,12 @@ pub trait SeleniumManager {
307
294
Ok ( driver_path)
308
295
}
309
296
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 > > {
316
298
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)
325
303
}
326
304
327
305
fn get_major_version ( & self , full_version : & str ) -> Result < String , Box < dyn Error > > {
@@ -527,3 +505,18 @@ fn strip_trailing_newline(input: &str) -> &str {
527
505
. or_else ( || input. strip_suffix ( '\n' ) )
528
506
. unwrap_or ( input)
529
507
}
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