Skip to content

Commit f048ab8

Browse files
Edward Ned Harveyjimevans
authored andcommitted
Made ChromeDriverServiceFileName a method instead of a const, so it will work on unix/linux
Signed-off-by: Jim Evans <[email protected]>
1 parent 6131fa4 commit f048ab8

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

dotnet/src/webdriver/Chrome/ChromeDriverService.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ namespace OpenQA.Selenium.Chrome
3030
/// </summary>
3131
public sealed class ChromeDriverService : DriverService
3232
{
33-
private const string ChromeDriverServiceFileName = "chromedriver.exe";
33+
private const string DefaultChromeDriverServiceExecutableName = "chromedriver";
34+
3435
private static readonly Uri ChromeDriverDownloadUrl = new Uri("http://chromedriver.storage.googleapis.com/index.html");
3536
private string logPath = string.Empty;
3637
private string urlPathPrefix = string.Empty;
@@ -160,7 +161,7 @@ protected override string CommandLineArguments
160161
/// <returns>A ChromeDriverService that implements default settings.</returns>
161162
public static ChromeDriverService CreateDefaultService()
162163
{
163-
string serviceDirectory = DriverService.FindDriverServiceExecutable(ChromeDriverServiceFileName, ChromeDriverDownloadUrl);
164+
string serviceDirectory = DriverService.FindDriverServiceExecutable(ChromeDriverServiceFileName(), ChromeDriverDownloadUrl);
164165
return CreateDefaultService(serviceDirectory);
165166
}
166167

@@ -171,7 +172,7 @@ public static ChromeDriverService CreateDefaultService()
171172
/// <returns>A ChromeDriverService using a random port.</returns>
172173
public static ChromeDriverService CreateDefaultService(string driverPath)
173174
{
174-
return CreateDefaultService(driverPath, ChromeDriverServiceFileName);
175+
return CreateDefaultService(driverPath, ChromeDriverServiceFileName());
175176
}
176177

177178
/// <summary>
@@ -184,5 +185,47 @@ public static ChromeDriverService CreateDefaultService(string driverPath, string
184185
{
185186
return new ChromeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
186187
}
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+
}
187230
}
188231
}

0 commit comments

Comments
 (0)