20
20
using System . Collections . Generic ;
21
21
using System . Diagnostics ;
22
22
23
+ #if ! NETFRAMEWORK
24
+ using System . Runtime . InteropServices ;
25
+ #endif
26
+
23
27
namespace OpenQA . Selenium
24
28
{
25
29
/// <summary>
@@ -30,9 +34,9 @@ public static class SeleniumManager
30
34
{
31
35
private static string binary ;
32
36
private static readonly List < string > KnownDrivers = new List < string > ( ) {
33
- "geckodriver.exe " ,
34
- "chromedriver.exe " ,
35
- "msedgedriver.exe "
37
+ "geckodriver" ,
38
+ "chromedriver" ,
39
+ "msedgedriver"
36
40
} ;
37
41
38
42
/// <summary>
@@ -44,14 +48,15 @@ public static class SeleniumManager
44
48
/// </returns>
45
49
public static string DriverPath ( string driverName )
46
50
{
51
+ driverName = driverName . Replace ( ".exe" , "" ) ;
47
52
if ( ! KnownDrivers . Contains ( driverName ) )
48
53
{
49
54
throw new WebDriverException ( "Unable to locate driver with name: " + driverName ) ;
50
55
}
51
56
var binaryFile = Binary ;
52
57
if ( binaryFile == null ) return null ;
53
58
54
- var arguments = "--driver " + driverName . Replace ( ".exe" , "" ) ;
59
+ var arguments = "--driver " + driverName ;
55
60
var output = RunCommand ( binaryFile , arguments ) ;
56
61
return output . Replace ( "INFO\t " , "" ) . TrimEnd ( ) ;
57
62
}
@@ -65,13 +70,26 @@ private static string Binary
65
70
{
66
71
if ( string . IsNullOrEmpty ( binary ) )
67
72
{
68
- // TODO Identify runtime platform
69
- if ( ! Environment . OSVersion . Platform . ToString ( ) . StartsWith ( "Win" ) )
70
- {
71
- throw new WebDriverException ( "Selenium Manager only supports Windows in .NET at this time" ) ;
72
- }
73
-
74
- binary = "selenium-manager/windows/selenium-manager.exe" ;
73
+ #if NETFRAMEWORK
74
+ binary = "selenium-manager/windows/selenium-manager.exe" ;
75
+ #else
76
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
77
+ {
78
+ binary = "selenium-manager/windows/selenium-manager.exe" ;
79
+ }
80
+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
81
+ {
82
+ binary = "selenium-manager/linux/selenium-manager" ;
83
+ }
84
+ else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
85
+ {
86
+ binary = "selenium-manager/macos/selenium-manager" ;
87
+ }
88
+ else
89
+ {
90
+ throw new WebDriverException ( "Selenium Manager did not find supported operating system" ) ;
91
+ }
92
+ #endif
75
93
}
76
94
77
95
return binary ;
0 commit comments