Skip to content

Commit

Permalink
Allow user to specify name of driver service executable in .NET
Browse files Browse the repository at this point in the history
We now give an overload to CreateDefaultService for ChromeDriverService,
PhantomJSDriverService, and InternetExplorerDriverService to allow the
user to specify the name of the service exectuable. This is particularly
useful for non-Windows platforms where the executable does not end with
'.exe'. It also allows the user to rename the executable to a name of
their choosing and still be able to use it from the .NET bindings.
  • Loading branch information
jimevans committed Dec 22, 2013
1 parent bd0e4ef commit b3e61c4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
20 changes: 16 additions & 4 deletions dotnet/src/webdriver/Chrome/ChromeDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public sealed class ChromeDriverService : DriverService
/// <summary>
/// Initializes a new instance of the ChromeDriverService class.
/// </summary>
/// <param name="executable">The full path to the ChromeDriver executable.</param>
/// <param name="executablePath">The full path to the ChromeDriver executable.</param>
/// <param name="executableFileName">The file name of the ChromeDriver executable.</param>
/// <param name="port">The port on which the ChromeDriver executable should listen.</param>
private ChromeDriverService(string executable, int port)
: base(executable, port, ChromeDriverServiceFileName, ChromeDriverDownloadUrl)
private ChromeDriverService(string executablePath, string executableFileName, int port)
: base(executablePath, port, executableFileName, ChromeDriverDownloadUrl)
{
}

Expand Down Expand Up @@ -153,7 +154,18 @@ public static ChromeDriverService CreateDefaultService()
/// <returns>A ChromeDriverService using a random port.</returns>
public static ChromeDriverService CreateDefaultService(string driverPath)
{
return new ChromeDriverService(driverPath, PortUtilities.FindFreePort());
return CreateDefaultService(driverPath, ChromeDriverServiceFileName);
}

/// <summary>
/// Creates a default instance of the ChromeDriverService using a specified path to the ChromeDriver executable with the given name.
/// </summary>
/// <param name="driverPath">The directory containing the ChromeDriver executable.</param>
/// <param name="driverExecutableFileName">The name of the ChromeDriver executable file.</param>
/// <returns>A ChromeDriverService using a random port.</returns>
public static ChromeDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
{
return new ChromeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
}
}
}
20 changes: 16 additions & 4 deletions dotnet/src/webdriver/IE/InternetExplorerDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public sealed class InternetExplorerDriverService : DriverService
/// <summary>
/// Initializes a new instance of the InternetExplorerDriverService class.
/// </summary>
/// <param name="executable">The full path to the IEDriverServer executable.</param>
/// <param name="executablePath">The full path to the IEDriverServer executable.</param>
/// <param name="executableFileName">The file name of the IEDriverServer executable.</param>
/// <param name="port">The port on which the IEDriverServer executable should listen.</param>
private InternetExplorerDriverService(string executable, int port)
: base(executable, port, InternetExplorerDriverServiceFileName, InternetExplorerDriverDownloadUrl)
private InternetExplorerDriverService(string executablePath, string executableFileName, int port)
: base(executablePath, port, executableFileName, InternetExplorerDriverDownloadUrl)
{
}

Expand Down Expand Up @@ -144,7 +145,18 @@ public static InternetExplorerDriverService CreateDefaultService()
/// <returns>A InternetExplorerDriverService using a random port.</returns>
public static InternetExplorerDriverService CreateDefaultService(string driverPath)
{
return new InternetExplorerDriverService(driverPath, PortUtilities.FindFreePort());
return CreateDefaultService(driverPath, InternetExplorerDriverServiceFileName);
}

/// <summary>
/// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable with the given name.
/// </summary>
/// <param name="driverPath">The directory containing the IEDriverServer executable.</param>
/// <param name="driverExecutableFileName">The name of the IEDriverServer executable file.</param>
/// <returns>A InternetExplorerDriverService using a random port.</returns>
public static InternetExplorerDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
{
return new InternetExplorerDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
}
}
}
22 changes: 17 additions & 5 deletions dotnet/src/webdriver/PhantomJS/PhantomJSDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ public sealed class PhantomJSDriverService : DriverService
/// </remarks>
[JsonConstructor]
private PhantomJSDriverService()
: this(FileUtilities.FindFile(PhantomJSDriverServiceFileName), PortUtilities.FindFreePort())
: this(FileUtilities.FindFile(PhantomJSDriverServiceFileName), PhantomJSDriverServiceFileName, PortUtilities.FindFreePort())
{
}

/// <summary>
/// Initializes a new instance of the PhantomJSDriverService class.
/// </summary>
/// <param name="executable">The full path to the PhantomJS executable.</param>
/// <param name="executablePath">The full path to the PhantomJS executable.</param>
/// <param name="executableFileName">The file name of the PhantomJS executable.</param>
/// <param name="port">The port on which the IEDriverServer executable should listen.</param>
private PhantomJSDriverService(string executable, int port)
: base(executable, port, PhantomJSDriverServiceFileName, PhantomJSDownloadUrl)
private PhantomJSDriverService(string executablePath, string executableFileName, int port)
: base(executablePath, port, executableFileName, PhantomJSDownloadUrl)
{
this.InitializeProperties();
}
Expand Down Expand Up @@ -334,7 +335,18 @@ public static PhantomJSDriverService CreateDefaultService()
/// <returns>A PhantomJSDriverService using a random port.</returns>
public static PhantomJSDriverService CreateDefaultService(string driverPath)
{
return new PhantomJSDriverService(driverPath, PortUtilities.FindFreePort());
return CreateDefaultService(driverPath, PhantomJSDriverServiceFileName);
}

/// <summary>
/// Creates a default instance of the PhantomJSDriverService using a specified path to the PhantomJS executable with the given name.
/// </summary>
/// <param name="driverPath">The directory containing the PhantomJS executable.</param>
/// <param name="driverExecutableFileName">The name of the PhantomJS executable file.</param>
/// <returns>A PhantomJSDriverService using a random port.</returns>
public static PhantomJSDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
{
return new PhantomJSDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
}

/// <summary>
Expand Down

0 comments on commit b3e61c4

Please sign in to comment.