Skip to content

Commit b3e61c4

Browse files
committed
Allow user to specify name of driver service executable in .NET
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.
1 parent bd0e4ef commit b3e61c4

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

Diff for: dotnet/src/webdriver/Chrome/ChromeDriverService.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public sealed class ChromeDriverService : DriverService
4141
/// <summary>
4242
/// Initializes a new instance of the ChromeDriverService class.
4343
/// </summary>
44-
/// <param name="executable">The full path to the ChromeDriver executable.</param>
44+
/// <param name="executablePath">The full path to the ChromeDriver executable.</param>
45+
/// <param name="executableFileName">The file name of the ChromeDriver executable.</param>
4546
/// <param name="port">The port on which the ChromeDriver executable should listen.</param>
46-
private ChromeDriverService(string executable, int port)
47-
: base(executable, port, ChromeDriverServiceFileName, ChromeDriverDownloadUrl)
47+
private ChromeDriverService(string executablePath, string executableFileName, int port)
48+
: base(executablePath, port, executableFileName, ChromeDriverDownloadUrl)
4849
{
4950
}
5051

@@ -153,7 +154,18 @@ public static ChromeDriverService CreateDefaultService()
153154
/// <returns>A ChromeDriverService using a random port.</returns>
154155
public static ChromeDriverService CreateDefaultService(string driverPath)
155156
{
156-
return new ChromeDriverService(driverPath, PortUtilities.FindFreePort());
157+
return CreateDefaultService(driverPath, ChromeDriverServiceFileName);
158+
}
159+
160+
/// <summary>
161+
/// Creates a default instance of the ChromeDriverService using a specified path to the ChromeDriver executable with the given name.
162+
/// </summary>
163+
/// <param name="driverPath">The directory containing the ChromeDriver executable.</param>
164+
/// <param name="driverExecutableFileName">The name of the ChromeDriver executable file.</param>
165+
/// <returns>A ChromeDriverService using a random port.</returns>
166+
public static ChromeDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
167+
{
168+
return new ChromeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
157169
}
158170
}
159171
}

Diff for: dotnet/src/webdriver/IE/InternetExplorerDriverService.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public sealed class InternetExplorerDriverService : DriverService
4141
/// <summary>
4242
/// Initializes a new instance of the InternetExplorerDriverService class.
4343
/// </summary>
44-
/// <param name="executable">The full path to the IEDriverServer executable.</param>
44+
/// <param name="executablePath">The full path to the IEDriverServer executable.</param>
45+
/// <param name="executableFileName">The file name of the IEDriverServer executable.</param>
4546
/// <param name="port">The port on which the IEDriverServer executable should listen.</param>
46-
private InternetExplorerDriverService(string executable, int port)
47-
: base(executable, port, InternetExplorerDriverServiceFileName, InternetExplorerDriverDownloadUrl)
47+
private InternetExplorerDriverService(string executablePath, string executableFileName, int port)
48+
: base(executablePath, port, executableFileName, InternetExplorerDriverDownloadUrl)
4849
{
4950
}
5051

@@ -144,7 +145,18 @@ public static InternetExplorerDriverService CreateDefaultService()
144145
/// <returns>A InternetExplorerDriverService using a random port.</returns>
145146
public static InternetExplorerDriverService CreateDefaultService(string driverPath)
146147
{
147-
return new InternetExplorerDriverService(driverPath, PortUtilities.FindFreePort());
148+
return CreateDefaultService(driverPath, InternetExplorerDriverServiceFileName);
149+
}
150+
151+
/// <summary>
152+
/// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable with the given name.
153+
/// </summary>
154+
/// <param name="driverPath">The directory containing the IEDriverServer executable.</param>
155+
/// <param name="driverExecutableFileName">The name of the IEDriverServer executable file.</param>
156+
/// <returns>A InternetExplorerDriverService using a random port.</returns>
157+
public static InternetExplorerDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
158+
{
159+
return new InternetExplorerDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
148160
}
149161
}
150162
}

Diff for: dotnet/src/webdriver/PhantomJS/PhantomJSDriverService.cs

+17-5
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,18 @@ public sealed class PhantomJSDriverService : DriverService
5151
/// </remarks>
5252
[JsonConstructor]
5353
private PhantomJSDriverService()
54-
: this(FileUtilities.FindFile(PhantomJSDriverServiceFileName), PortUtilities.FindFreePort())
54+
: this(FileUtilities.FindFile(PhantomJSDriverServiceFileName), PhantomJSDriverServiceFileName, PortUtilities.FindFreePort())
5555
{
5656
}
5757

5858
/// <summary>
5959
/// Initializes a new instance of the PhantomJSDriverService class.
6060
/// </summary>
61-
/// <param name="executable">The full path to the PhantomJS executable.</param>
61+
/// <param name="executablePath">The full path to the PhantomJS executable.</param>
62+
/// <param name="executableFileName">The file name of the PhantomJS executable.</param>
6263
/// <param name="port">The port on which the IEDriverServer executable should listen.</param>
63-
private PhantomJSDriverService(string executable, int port)
64-
: base(executable, port, PhantomJSDriverServiceFileName, PhantomJSDownloadUrl)
64+
private PhantomJSDriverService(string executablePath, string executableFileName, int port)
65+
: base(executablePath, port, executableFileName, PhantomJSDownloadUrl)
6566
{
6667
this.InitializeProperties();
6768
}
@@ -334,7 +335,18 @@ public static PhantomJSDriverService CreateDefaultService()
334335
/// <returns>A PhantomJSDriverService using a random port.</returns>
335336
public static PhantomJSDriverService CreateDefaultService(string driverPath)
336337
{
337-
return new PhantomJSDriverService(driverPath, PortUtilities.FindFreePort());
338+
return CreateDefaultService(driverPath, PhantomJSDriverServiceFileName);
339+
}
340+
341+
/// <summary>
342+
/// Creates a default instance of the PhantomJSDriverService using a specified path to the PhantomJS executable with the given name.
343+
/// </summary>
344+
/// <param name="driverPath">The directory containing the PhantomJS executable.</param>
345+
/// <param name="driverExecutableFileName">The name of the PhantomJS executable file.</param>
346+
/// <returns>A PhantomJSDriverService using a random port.</returns>
347+
public static PhantomJSDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
348+
{
349+
return new PhantomJSDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
338350
}
339351

340352
/// <summary>

0 commit comments

Comments
 (0)