11using  System ; 
22using  System . Diagnostics ; 
3+ using  System . IO ; 
34using  System . Threading . Tasks ; 
45
56namespace  WebDriverManager . Helpers 
@@ -22,6 +23,24 @@ public static string GetInstalledBrowserVersionLinux(string executableFileName,
2223            } 
2324        } 
2425
26+         public  static   string  GetInstalledBrowserVersionLinux ( params  string [ ]  executableAndArgumentsPairs ) 
27+         { 
28+             var  length  =  executableAndArgumentsPairs . Length ; 
29+             if  ( length  %  2  ==  1 )  throw  new  Exception ( "Please provide arguments for every executable!" ) ; 
30+ 
31+             for  ( var  i  =  0 ;  i  <  length ;  i  +=  2 ) 
32+             { 
33+                 var  executableFileName  =  executableAndArgumentsPairs [ i ] ; 
34+                 var  arguments  =  executableAndArgumentsPairs [ i  +  1 ] ; 
35+                 
36+                 var  fullPath  =  GetFullPath ( executableFileName ) ; 
37+                 if  ( fullPath  !=  null )  return  GetInstalledBrowserVersionLinux ( fullPath ,  arguments ) ; 
38+             } 
39+ 
40+             throw  new  Exception ( 
41+                 $ "Unable to locate installed browser for runtime platform { Environment . OSVersion . Platform } ") ; 
42+         } 
43+ 
2544        public  static   string  GetInstalledBrowserVersionOsx ( string  executableFileName ,  string  arguments ) 
2645        { 
2746            try 
@@ -62,5 +81,25 @@ public static string GetInstalledBrowserVersionWin(string executableFileName)
6281
6382            return  null ; 
6483        } 
84+ 
85+         /// <summary> 
86+         /// Checks if a provided file name can be found in either the current working directory or the <c>PATH</c> 
87+         /// environment variable. 
88+         /// </summary> 
89+         /// <param name="fileName">The file name of the executable, including extension on Windows.</param> 
90+         /// <returns>The full path of the executable or <see langword="null"/> if it doesn't exist.</returns> 
91+         private  static   string  GetFullPath ( string  fileName ) 
92+         { 
93+             if  ( File . Exists ( fileName ) )  return  Path . GetFullPath ( fileName ) ; 
94+ 
95+             var  paths  =  Environment . GetEnvironmentVariable ( "PATH" ) ? . Split ( Path . PathSeparator )  ??  Array . Empty < string > ( ) ; 
96+             foreach  ( var  path  in  paths ) 
97+             { 
98+                 var  fullPath  =  Path . Combine ( path ,  fileName ) ; 
99+                 if  ( File . Exists ( fullPath ) )  return  fullPath ; 
100+             } 
101+ 
102+             return  null ; 
103+         } 
65104    } 
66105} 
0 commit comments