diff --git a/dotnet/src/webdriver/Chrome/ChromeDriverService.cs b/dotnet/src/webdriver/Chrome/ChromeDriverService.cs
index eb0872ace169c..d0e8b8bb19182 100644
--- a/dotnet/src/webdriver/Chrome/ChromeDriverService.cs
+++ b/dotnet/src/webdriver/Chrome/ChromeDriverService.cs
@@ -16,9 +16,9 @@
// limitations under the License.
//
-using System;
-using OpenQA.Selenium.Internal;
+using System.IO;
using OpenQA.Selenium.Chromium;
+using OpenQA.Selenium.Internal;
namespace OpenQA.Selenium.Chrome
{
@@ -29,8 +29,6 @@ public sealed class ChromeDriverService : ChromiumDriverService
{
private const string DefaultChromeDriverServiceExecutableName = "chromedriver";
- private static readonly Uri ChromeDriverDownloadUrl = new Uri("http://chromedriver.storage.googleapis.com/index.html");
-
///
/// Initializes a new instance of the class.
///
@@ -38,7 +36,7 @@ public sealed class ChromeDriverService : ChromiumDriverService
/// The file name of the ChromeDriver executable.
/// The port on which the ChromeDriver executable should listen.
private ChromeDriverService(string executablePath, string executableFileName, int port)
- : base(executablePath, executableFileName, port, ChromeDriverDownloadUrl)
+ : base(executablePath, executableFileName, port)
{
}
@@ -58,10 +56,8 @@ public static ChromeDriverService CreateDefaultService()
/// A ChromeDriverService that implements default settings.
public static ChromeDriverService CreateDefaultService(ChromeOptions options)
{
- string serviceDirectory = DriverService.FindDriverServiceExecutable(ChromiumDriverServiceFileName(DefaultChromeDriverServiceExecutableName),
- ChromeDriverDownloadUrl);
- ChromeDriverService service = CreateDefaultService(serviceDirectory);
- return DriverFinder.VerifyDriverServicePath(service, options) as ChromeDriverService;;
+ string fullServicePath = DriverFinder.FullPath(options);
+ return CreateDefaultService(Path.GetDirectoryName(fullServicePath), Path.GetFileName(fullServicePath));
}
///
@@ -71,6 +67,11 @@ public static ChromeDriverService CreateDefaultService(ChromeOptions options)
/// A ChromeDriverService using a random port.
public static ChromeDriverService CreateDefaultService(string driverPath)
{
+ if (Path.GetFileName(driverPath).Contains(DefaultChromeDriverServiceExecutableName))
+ {
+ driverPath = Path.GetDirectoryName(driverPath);
+ }
+
return CreateDefaultService(driverPath, ChromiumDriverServiceFileName(DefaultChromeDriverServiceExecutableName));
}
diff --git a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs
index 1a9284205240c..b032e154149a7 100644
--- a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs
+++ b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs
@@ -125,7 +125,7 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
/// The to be used with the ChromiumDriver.
/// The maximum amount of time to wait for each command.
protected ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
- : base(new DriverServiceCommandExecutor(DriverFinder.VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
+ : base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
{
this.optionsCapabilityName = options.CapabilityName;
}
diff --git a/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs b/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs
index aa1635400cb42..072fbb83bfc8c 100644
--- a/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs
+++ b/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs
@@ -45,9 +45,8 @@ public abstract class ChromiumDriverService : DriverService
/// The full path to the ChromeDriver executable.
/// The file name of the ChromeDriver executable.
/// The port on which the ChromeDriver executable should listen.
- /// The url that ChromiumDriver should be downloaded from.
- protected ChromiumDriverService(string executablePath, string executableFileName, int port, Uri downloadUrl)
- : base(executablePath, port, executableFileName, downloadUrl)
+ protected ChromiumDriverService(string executablePath, string executableFileName, int port, Uri downloadUrl = null)
+ : base(executablePath, port, executableFileName)
{
}
diff --git a/dotnet/src/webdriver/DriverFinder.cs b/dotnet/src/webdriver/DriverFinder.cs
index 306031f8e5426..4d46ee91d70dc 100644
--- a/dotnet/src/webdriver/DriverFinder.cs
+++ b/dotnet/src/webdriver/DriverFinder.cs
@@ -28,31 +28,39 @@ namespace OpenQA.Selenium
public static class DriverFinder
{
///
- /// Checks if the driver path exists, else uses Selenium Manager to return it.
+ /// Use Selenium Manager to locate the driver
///
- /// DriverService with the current path.
/// DriverOptions with the current browser options.
///
- /// The service with a verified driver executable path.
+ /// The full path and name of the driver
///
- public static DriverService VerifyDriverServicePath(DriverService service, DriverOptions options)
+ ///
+ public static string FullPath(DriverOptions options)
{
- string executablePath = Path.Combine(service.DriverServicePath, service.DriverServiceExecutableName);
- if (File.Exists(executablePath)) return service;
+ string executablePath;
try
{
executablePath = SeleniumManager.DriverPath(options);
- service.DriverServicePath = Path.GetDirectoryName(executablePath);
- service.DriverServiceExecutableName = Path.GetFileName(executablePath);
}
catch (Exception e)
{
- throw new NoSuchDriverException($"Unable to obtain {service.DriverServiceExecutableName} using Selenium Manager", e);
+ throw new NoSuchDriverException($"Unable to obtain {options.BrowserName} using Selenium Manager", e);
}
- if (File.Exists(executablePath)) return service;
+ string message;
+ if (executablePath == null)
+ {
+ message = $"Unable to locate or obtain {options.BrowserName} driver";
+ } else if (!File.Exists(executablePath))
+ {
+ message = $"{options.BrowserName} driver located at {executablePath}, but invalid";
+ }
+ else
+ {
+ return executablePath;
+ }
- throw new NoSuchDriverException($"Unable to locate or obtain {service.DriverServiceExecutableName}");
+ throw new NoSuchDriverException(message);
}
}
}
diff --git a/dotnet/src/webdriver/DriverService.cs b/dotnet/src/webdriver/DriverService.cs
index fabc971d766cb..ce441c5b2e110 100644
--- a/dotnet/src/webdriver/DriverService.cs
+++ b/dotnet/src/webdriver/DriverService.cs
@@ -49,14 +49,14 @@ public abstract class DriverService : ICommandServer
/// The full path to the directory containing the executable providing the service to drive the browser.
/// The port on which the driver executable should listen.
/// The file name of the driver service executable.
- /// A URL at which the driver service executable may be downloaded.
+ /// This parameter is no longer used; kept for backwards compatibility.
///
/// If the path specified is or an empty string.
///
///
/// If the specified driver service executable does not exist in the specified directory.
///
- protected DriverService(string servicePath, int port, string driverServiceExecutableName, Uri driverServiceDownloadUrl)
+ protected DriverService(string servicePath, int port, string driverServiceExecutableName, Uri driverServiceDownloadUrl = null)
{
this.driverServicePath = servicePath;
this.driverServiceExecutableName = driverServiceExecutableName;
@@ -284,20 +284,6 @@ public void Start()
}
}
- ///
- /// Finds the specified driver service executable.
- ///
- /// The file name of the executable to find.
- /// A URL at which the driver service executable may be downloaded.
- /// The directory containing the driver service executable.
- ///
- /// If the specified driver service executable does not exist in the current directory or in a directory on the system path.
- ///
- protected static string FindDriverServiceExecutable(string executableName, Uri downloadUrl)
- {
- return FileUtilities.FindFile(executableName);
- }
-
///
/// Releases all resources associated with this .
///
diff --git a/dotnet/src/webdriver/Edge/EdgeDriverService.cs b/dotnet/src/webdriver/Edge/EdgeDriverService.cs
index 0e22b26fa3845..737504b3154f3 100644
--- a/dotnet/src/webdriver/Edge/EdgeDriverService.cs
+++ b/dotnet/src/webdriver/Edge/EdgeDriverService.cs
@@ -16,11 +16,9 @@
// limitations under the License.
//
-using System;
-using System.Globalization;
-using System.Text;
-using OpenQA.Selenium.Internal;
+using System.IO;
using OpenQA.Selenium.Chromium;
+using OpenQA.Selenium.Internal;
namespace OpenQA.Selenium.Edge
{
@@ -31,8 +29,6 @@ public sealed class EdgeDriverService : ChromiumDriverService
{
private const string MSEdgeDriverServiceFileName = "msedgedriver";
- private static readonly Uri MicrosoftWebDriverDownloadUrl = new Uri("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/");
-
///
/// Initializes a new instance of the class.
///
@@ -40,7 +36,7 @@ public sealed class EdgeDriverService : ChromiumDriverService
/// The file name of the EdgeDriver executable.
/// The port on which the EdgeDriver executable should listen.
private EdgeDriverService(string executablePath, string executableFileName, int port)
- : base(executablePath, executableFileName, port, MicrosoftWebDriverDownloadUrl)
+ : base(executablePath, executableFileName, port)
{
}
@@ -69,10 +65,8 @@ public static EdgeDriverService CreateDefaultService()
/// A EdgeDriverService that implements default settings.
public static EdgeDriverService CreateDefaultService(EdgeOptions options)
{
- string serviceDirectory = DriverService.FindDriverServiceExecutable(ChromiumDriverServiceFileName(MSEdgeDriverServiceFileName),
- MicrosoftWebDriverDownloadUrl);
- EdgeDriverService service = CreateDefaultService(serviceDirectory);
- return DriverFinder.VerifyDriverServicePath(service, options) as EdgeDriverService;
+ string fullServicePath = DriverFinder.FullPath(options);
+ return CreateDefaultService(Path.GetDirectoryName(fullServicePath), Path.GetFileName(fullServicePath));
}
///
@@ -82,6 +76,11 @@ public static EdgeDriverService CreateDefaultService(EdgeOptions options)
/// An EdgeDriverService using a random port.
public static EdgeDriverService CreateDefaultService(string driverPath)
{
+ if (Path.GetFileName(driverPath).Contains(MSEdgeDriverServiceFileName))
+ {
+ driverPath = Path.GetDirectoryName(driverPath);
+ }
+
return CreateDefaultService(driverPath, ChromiumDriverServiceFileName(MSEdgeDriverServiceFileName));
}
diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs
index 48bca4d8766cf..19284f0e63aa7 100644
--- a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs
+++ b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs
@@ -186,7 +186,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
/// The to be used with the Firefox driver.
/// The maximum amount of time to wait for each command.
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
- : base(new DriverServiceCommandExecutor(DriverFinder.VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
+ : base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
{
// Add the custom commands unique to Firefox
this.AddCustomFirefoxCommands();
diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs b/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
index 4efd130b77a10..b40cc6b8ac390 100644
--- a/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
+++ b/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
@@ -18,7 +18,7 @@
using System;
using System.Globalization;
-using System.Net;
+using System.IO;
using System.Text;
using OpenQA.Selenium.Internal;
@@ -30,7 +30,6 @@ namespace OpenQA.Selenium.Firefox
public sealed class FirefoxDriverService : DriverService
{
private const string DefaultFirefoxDriverServiceFileName = "geckodriver";
- private static readonly Uri FirefoxDriverDownloadUrl = new Uri("https://github.com/mozilla/geckodriver/releases");
private bool connectToRunningBrowser;
private bool openBrowserToolbox;
@@ -47,7 +46,7 @@ public sealed class FirefoxDriverService : DriverService
/// The file name of the Firefox driver executable.
/// The port on which the Firefox driver executable should listen.
private FirefoxDriverService(string executablePath, string executableFileName, int port)
- : base(executablePath, port, executableFileName, FirefoxDriverDownloadUrl)
+ : base(executablePath, port, executableFileName)
{
}
@@ -220,9 +219,8 @@ public static FirefoxDriverService CreateDefaultService()
/// A FirefoxDriverService that implements default settings.
public static FirefoxDriverService CreateDefaultService(FirefoxOptions options)
{
- string serviceDirectory = DriverService.FindDriverServiceExecutable(FirefoxDriverServiceFileName(), FirefoxDriverDownloadUrl);
- FirefoxDriverService service = CreateDefaultService(serviceDirectory);
- return DriverFinder.VerifyDriverServicePath(service, options) as FirefoxDriverService;
+ string fullServicePath = DriverFinder.FullPath(options);
+ return CreateDefaultService(Path.GetDirectoryName(fullServicePath), Path.GetFileName(fullServicePath));
}
///
@@ -232,6 +230,11 @@ public static FirefoxDriverService CreateDefaultService(FirefoxOptions options)
/// A FirefoxDriverService using a random port.
public static FirefoxDriverService CreateDefaultService(string driverPath)
{
+ if (Path.GetFileName(driverPath) == FirefoxDriverServiceFileName())
+ {
+ driverPath = Path.GetDirectoryName(driverPath);
+ }
+
return CreateDefaultService(driverPath, FirefoxDriverServiceFileName());
}
diff --git a/dotnet/src/webdriver/IE/InternetExplorerDriver.cs b/dotnet/src/webdriver/IE/InternetExplorerDriver.cs
index a5331e0ff14ff..9a946a32f2772 100644
--- a/dotnet/src/webdriver/IE/InternetExplorerDriver.cs
+++ b/dotnet/src/webdriver/IE/InternetExplorerDriver.cs
@@ -140,7 +140,7 @@ public InternetExplorerDriver(InternetExplorerDriverService service, InternetExp
/// The used to initialize the driver.
/// The maximum amount of time to wait for each command.
public InternetExplorerDriver(InternetExplorerDriverService service, InternetExplorerOptions options, TimeSpan commandTimeout)
- : base(new DriverServiceCommandExecutor(DriverFinder.VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
+ : base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
{
}
diff --git a/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs b/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs
index 3b03d4076b39b..8bdf9091dd86a 100644
--- a/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs
+++ b/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs
@@ -16,8 +16,8 @@
// limitations under the License.
//
-using System;
using System.Globalization;
+using System.IO;
using System.Text;
using OpenQA.Selenium.Internal;
@@ -29,7 +29,6 @@ namespace OpenQA.Selenium.IE
public sealed class InternetExplorerDriverService : DriverService
{
private const string InternetExplorerDriverServiceFileName = "IEDriverServer.exe";
- private static readonly Uri InternetExplorerDriverDownloadUrl = new Uri("https://www.selenium.dev/downloads/");
private InternetExplorerDriverLogLevel loggingLevel = InternetExplorerDriverLogLevel.Fatal;
private string host = string.Empty;
@@ -44,7 +43,7 @@ public sealed class InternetExplorerDriverService : DriverService
/// The file name of the IEDriverServer executable.
/// The port on which the IEDriverServer executable should listen.
private InternetExplorerDriverService(string executablePath, string executableFileName, int port)
- : base(executablePath, port, executableFileName, InternetExplorerDriverDownloadUrl)
+ : base(executablePath, port, executableFileName)
{
}
@@ -159,9 +158,8 @@ public static InternetExplorerDriverService CreateDefaultService()
/// A InternetExplorerDriverService that implements default settings.
public static InternetExplorerDriverService CreateDefaultService(InternetExplorerOptions options)
{
- string serviceDirectory = DriverService.FindDriverServiceExecutable(InternetExplorerDriverServiceFileName, InternetExplorerDriverDownloadUrl);
- InternetExplorerDriverService service = CreateDefaultService(serviceDirectory);
- return DriverFinder.VerifyDriverServicePath(service, options) as InternetExplorerDriverService;
+ string fullServicePath = DriverFinder.FullPath(options);
+ return CreateDefaultService(Path.GetDirectoryName(fullServicePath), Path.GetFileName(fullServicePath));
}
///
@@ -171,6 +169,11 @@ public static InternetExplorerDriverService CreateDefaultService(InternetExplore
/// A InternetExplorerDriverService using a random port.
public static InternetExplorerDriverService CreateDefaultService(string driverPath)
{
+ if (Path.GetFileName(driverPath) == InternetExplorerDriverServiceFileName)
+ {
+ driverPath = Path.GetDirectoryName(driverPath);
+ }
+
return CreateDefaultService(driverPath, InternetExplorerDriverServiceFileName);
}
diff --git a/dotnet/src/webdriver/Safari/SafariDriverService.cs b/dotnet/src/webdriver/Safari/SafariDriverService.cs
index a96b349847ec0..7771bb9999961 100644
--- a/dotnet/src/webdriver/Safari/SafariDriverService.cs
+++ b/dotnet/src/webdriver/Safari/SafariDriverService.cs
@@ -17,6 +17,7 @@
//
using System;
+using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
@@ -31,10 +32,6 @@ namespace OpenQA.Selenium.Safari
public sealed class SafariDriverService : DriverService
{
private const string DefaultSafariDriverServiceExecutableName = "safaridriver";
- private const string DefaultSafariDriverServiceExecutablePath = "/usr/bin";
- private const string DefaultSafariPreviewDriverServiceExecutablePath = "/Applications/Safari Technology Preview.app/Contents/MacOS/";
-
- private static readonly Uri SafariDriverDownloadUrl = new Uri("http://apple.com");
private bool useLegacyProtocol;
@@ -45,7 +42,7 @@ public sealed class SafariDriverService : DriverService
/// The file name of the SafariDriver executable.
/// The port on which the SafariDriver executable should listen.
private SafariDriverService(string executablePath, string executableFileName, int port)
- : base(executablePath, port, executableFileName, SafariDriverDownloadUrl)
+ : base(executablePath, port, executableFileName)
{
}
@@ -162,21 +159,18 @@ protected override bool IsInitialized
/// A SafariDriverService that implements default settings.
public static SafariDriverService CreateDefaultService()
{
- return CreateDefaultService(DefaultSafariDriverServiceExecutablePath);
+ return CreateDefaultService(new SafariOptions());
}
///
/// Creates a default instance of the SafariDriverService.
///
+ /// Browser options used to find the correct GeckoDriver binary.
/// A SafariDriverService that implements default settings.
public static SafariDriverService CreateDefaultService(SafariOptions options)
{
- if (options.TechnologyPreview)
- {
- return CreateDefaultService(DefaultSafariPreviewDriverServiceExecutablePath);
- }
-
- return CreateDefaultService(DefaultSafariDriverServiceExecutablePath);
+ string fullServicePath = DriverFinder.FullPath(options);
+ return CreateDefaultService(Path.GetDirectoryName(fullServicePath), Path.GetFileName(fullServicePath));
}
///
@@ -186,6 +180,11 @@ public static SafariDriverService CreateDefaultService(SafariOptions options)
/// A SafariDriverService using a random port.
public static SafariDriverService CreateDefaultService(string driverPath)
{
+ if (Path.GetFileName(driverPath) == DefaultSafariDriverServiceExecutableName)
+ {
+ driverPath = Path.GetDirectoryName(driverPath);
+ }
+
return CreateDefaultService(driverPath, DefaultSafariDriverServiceExecutableName);
}