@@ -30,7 +30,8 @@ namespace OpenQA.Selenium.Chrome
30
30
/// </summary>
31
31
public sealed class ChromeDriverService : DriverService
32
32
{
33
- private const string ChromeDriverServiceFileName = "chromedriver.exe" ;
33
+ private const string DefaultChromeDriverServiceExecutableName = "chromedriver" ;
34
+
34
35
private static readonly Uri ChromeDriverDownloadUrl = new Uri ( "http://chromedriver.storage.googleapis.com/index.html" ) ;
35
36
private string logPath = string . Empty ;
36
37
private string urlPathPrefix = string . Empty ;
@@ -160,7 +161,7 @@ protected override string CommandLineArguments
160
161
/// <returns>A ChromeDriverService that implements default settings.</returns>
161
162
public static ChromeDriverService CreateDefaultService ( )
162
163
{
163
- string serviceDirectory = DriverService . FindDriverServiceExecutable ( ChromeDriverServiceFileName , ChromeDriverDownloadUrl ) ;
164
+ string serviceDirectory = DriverService . FindDriverServiceExecutable ( ChromeDriverServiceFileName ( ) , ChromeDriverDownloadUrl ) ;
164
165
return CreateDefaultService ( serviceDirectory ) ;
165
166
}
166
167
@@ -171,7 +172,7 @@ public static ChromeDriverService CreateDefaultService()
171
172
/// <returns>A ChromeDriverService using a random port.</returns>
172
173
public static ChromeDriverService CreateDefaultService ( string driverPath )
173
174
{
174
- return CreateDefaultService ( driverPath , ChromeDriverServiceFileName ) ;
175
+ return CreateDefaultService ( driverPath , ChromeDriverServiceFileName ( ) ) ;
175
176
}
176
177
177
178
/// <summary>
@@ -184,5 +185,47 @@ public static ChromeDriverService CreateDefaultService(string driverPath, string
184
185
{
185
186
return new ChromeDriverService ( driverPath , driverExecutableFileName , PortUtilities . FindFreePort ( ) ) ;
186
187
}
188
+
189
+ /// <summary>
190
+ /// Returns the Chrome driver filename for the currently running platform
191
+ /// </summary>
192
+ /// <returns>The file name of the Chrome driver service executable.</returns>
193
+ private static string ChromeDriverServiceFileName ( )
194
+ {
195
+ string fileName = DefaultChromeDriverServiceExecutableName ;
196
+
197
+ // Unfortunately, detecting the currently running platform isn't as
198
+ // straightforward as you might hope.
199
+ // See: http://mono.wikia.com/wiki/Detecting_the_execution_platform
200
+ // and https://msdn.microsoft.com/en-us/library/3a8hyw88(v=vs.110).aspx
201
+ const int PlatformMonoUnixValue = 128 ;
202
+
203
+ switch ( Environment . OSVersion . Platform )
204
+ {
205
+ case PlatformID . Win32NT :
206
+ case PlatformID . Win32S :
207
+ case PlatformID . Win32Windows :
208
+ case PlatformID . WinCE :
209
+ fileName += ".exe" ;
210
+ break ;
211
+
212
+ case PlatformID . MacOSX :
213
+ case PlatformID . Unix :
214
+ break ;
215
+
216
+ // Don't handle the Xbox case. Let default handle it.
217
+ // case PlatformID.Xbox:
218
+ // break;
219
+ default :
220
+ if ( ( int ) Environment . OSVersion . Platform == PlatformMonoUnixValue )
221
+ {
222
+ break ;
223
+ }
224
+
225
+ throw new WebDriverException ( "Unsupported platform: " + Environment . OSVersion . Platform ) ;
226
+ }
227
+
228
+ return fileName ;
229
+ }
187
230
}
188
231
}
0 commit comments