Skip to content

Commit

Permalink
Made ChromeDriverServiceFileName a method instead of a const, so it w…
Browse files Browse the repository at this point in the history
…ill work on unix/linux

Signed-off-by: Jim Evans <[email protected]>
  • Loading branch information
Edward Ned Harvey authored and jimevans committed Jan 27, 2016
1 parent 6131fa4 commit f048ab8
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions dotnet/src/webdriver/Chrome/ChromeDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace OpenQA.Selenium.Chrome
/// </summary>
public sealed class ChromeDriverService : DriverService
{
private const string ChromeDriverServiceFileName = "chromedriver.exe";
private const string DefaultChromeDriverServiceExecutableName = "chromedriver";

private static readonly Uri ChromeDriverDownloadUrl = new Uri("http://chromedriver.storage.googleapis.com/index.html");
private string logPath = string.Empty;
private string urlPathPrefix = string.Empty;
Expand Down Expand Up @@ -160,7 +161,7 @@ protected override string CommandLineArguments
/// <returns>A ChromeDriverService that implements default settings.</returns>
public static ChromeDriverService CreateDefaultService()
{
string serviceDirectory = DriverService.FindDriverServiceExecutable(ChromeDriverServiceFileName, ChromeDriverDownloadUrl);
string serviceDirectory = DriverService.FindDriverServiceExecutable(ChromeDriverServiceFileName(), ChromeDriverDownloadUrl);
return CreateDefaultService(serviceDirectory);
}

Expand All @@ -171,7 +172,7 @@ public static ChromeDriverService CreateDefaultService()
/// <returns>A ChromeDriverService using a random port.</returns>
public static ChromeDriverService CreateDefaultService(string driverPath)
{
return CreateDefaultService(driverPath, ChromeDriverServiceFileName);
return CreateDefaultService(driverPath, ChromeDriverServiceFileName());
}

/// <summary>
Expand All @@ -184,5 +185,47 @@ public static ChromeDriverService CreateDefaultService(string driverPath, string
{
return new ChromeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
}

/// <summary>
/// Returns the Chrome driver filename for the currently running platform
/// </summary>
/// <returns>The file name of the Chrome driver service executable.</returns>
private static string ChromeDriverServiceFileName()
{
string fileName = DefaultChromeDriverServiceExecutableName;

// Unfortunately, detecting the currently running platform isn't as
// straightforward as you might hope.
// See: http://mono.wikia.com/wiki/Detecting_the_execution_platform
// and https://msdn.microsoft.com/en-us/library/3a8hyw88(v=vs.110).aspx
const int PlatformMonoUnixValue = 128;

switch (Environment.OSVersion.Platform)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
fileName += ".exe";
break;

case PlatformID.MacOSX:
case PlatformID.Unix:
break;

// Don't handle the Xbox case. Let default handle it.
// case PlatformID.Xbox:
// break;
default:
if ((int)Environment.OSVersion.Platform == PlatformMonoUnixValue)
{
break;
}

throw new WebDriverException("Unsupported platform: " + Environment.OSVersion.Platform);
}

return fileName;
}
}
}

0 comments on commit f048ab8

Please sign in to comment.