diff --git a/dotnet/src/webdriver/Chrome/ChromeDriverService.cs b/dotnet/src/webdriver/Chrome/ChromeDriverService.cs index ee1a2559a77e9..e1b5c3f23ccfa 100644 --- a/dotnet/src/webdriver/Chrome/ChromeDriverService.cs +++ b/dotnet/src/webdriver/Chrome/ChromeDriverService.cs @@ -63,20 +63,22 @@ public static ChromeDriverService CreateDefaultService() /// /// The path to the executable or the directory containing the ChromeDriver executable. /// A ChromeDriverService using a random port. - public static ChromeDriverService CreateDefaultService(string driverPath) + public static ChromeDriverService CreateDefaultService(string? driverPath) { - string fileName; if (File.Exists(driverPath)) { - fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath)!; + string fileName = Path.GetFileName(driverPath); + string driverFolder = Path.GetDirectoryName(driverPath)!; + + return CreateDefaultService(driverFolder, fileName); } else { - fileName = ChromiumDriverServiceFileName(DefaultChromeDriverServiceExecutableName); - } + string fileName = ChromiumDriverServiceFileName(DefaultChromeDriverServiceExecutableName); + string? driverFolder = driverPath; - return CreateDefaultService(driverPath, fileName); + return CreateDefaultService(driverFolder, fileName); + } } /// @@ -85,7 +87,7 @@ public static ChromeDriverService CreateDefaultService(string driverPath) /// The directory containing the ChromeDriver executable. /// The name of the ChromeDriver executable file. /// A ChromeDriverService using a random port. - public static ChromeDriverService CreateDefaultService(string driverPath, string driverExecutableFileName) + public static ChromeDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName) { return new ChromeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort()); } diff --git a/dotnet/src/webdriver/Edge/EdgeDriverService.cs b/dotnet/src/webdriver/Edge/EdgeDriverService.cs index 4a911439c8dbd..feca473b8f10a 100644 --- a/dotnet/src/webdriver/Edge/EdgeDriverService.cs +++ b/dotnet/src/webdriver/Edge/EdgeDriverService.cs @@ -72,22 +72,24 @@ public static EdgeDriverService CreateDefaultService() /// /// Creates a default instance of the EdgeDriverService using a specified path to the EdgeDriver executable. /// - /// The directory containing the EdgeDriver executable. + /// The path to the executable or the directory containing the EdgeDriver executable. /// An EdgeDriverService using a random port. - public static EdgeDriverService CreateDefaultService(string driverPath) + public static EdgeDriverService CreateDefaultService(string? driverPath) { - string fileName; if (File.Exists(driverPath)) { - fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath)!; + string fileName = Path.GetFileName(driverPath); + string driverFolder = Path.GetDirectoryName(driverPath)!; + + return CreateDefaultService(driverFolder, fileName); } else { - fileName = ChromiumDriverServiceFileName(MSEdgeDriverServiceFileName); - } + string fileName = ChromiumDriverServiceFileName(MSEdgeDriverServiceFileName); + string? driverFolder = driverPath; - return CreateDefaultService(driverPath, fileName); + return CreateDefaultService(driverFolder, fileName); + } } /// @@ -96,7 +98,7 @@ public static EdgeDriverService CreateDefaultService(string driverPath) /// The directory containing the EdgeDriver executable. /// The name of the EdgeDriver executable file. /// A EdgeDriverService using a random port. - public static EdgeDriverService CreateDefaultService(string driverPath, string driverExecutableFileName) + public static EdgeDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName) { return new EdgeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort()); } diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs b/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs index a7cf0cec88bcd..f53fd5640d416 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxDriverService.cs @@ -194,20 +194,22 @@ public static FirefoxDriverService CreateDefaultService() /// /// The path to the executable or the directory containing the Firefox driver executable. /// A FirefoxDriverService using a random port. - public static FirefoxDriverService CreateDefaultService(string driverPath) + public static FirefoxDriverService CreateDefaultService(string? driverPath) { - string fileName; if (File.Exists(driverPath)) { - fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath)!; + string fileName = Path.GetFileName(driverPath); + string driverFolder = Path.GetDirectoryName(driverPath)!; + + return CreateDefaultService(driverFolder, fileName); } else { - fileName = FirefoxDriverServiceFileName(); - } + string fileName = FirefoxDriverServiceFileName(); + string? driverFolder = driverPath; - return CreateDefaultService(driverPath, fileName); + return CreateDefaultService(driverFolder, fileName); + } } /// @@ -216,7 +218,7 @@ public static FirefoxDriverService CreateDefaultService(string driverPath) /// The directory containing the Firefox driver executable. /// The name of the Firefox driver executable file. /// A FirefoxDriverService using a random port. - public static FirefoxDriverService CreateDefaultService(string driverPath, string driverExecutableFileName) + public static FirefoxDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName) { return new FirefoxDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort()); } diff --git a/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs b/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs index 9b7af524877a7..19dca45dabb44 100644 --- a/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs +++ b/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs @@ -138,20 +138,22 @@ public static InternetExplorerDriverService CreateDefaultService() /// /// The path to the executable or the directory containing the IEDriverServer executable. /// A InternetExplorerDriverService using a random port. - public static InternetExplorerDriverService CreateDefaultService(string driverPath) + public static InternetExplorerDriverService CreateDefaultService(string? driverPath) { - string fileName; if (File.Exists(driverPath)) { - fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath)!; + string fileName = Path.GetFileName(driverPath); + string driverFolder = Path.GetDirectoryName(driverPath)!; + + return CreateDefaultService(driverFolder, fileName); } else { - fileName = InternetExplorerDriverServiceFileName; - } + string fileName = InternetExplorerDriverServiceFileName; + string? driverFolder = driverPath; - return CreateDefaultService(driverPath, fileName); + return CreateDefaultService(driverFolder, fileName); + } } /// @@ -160,7 +162,7 @@ public static InternetExplorerDriverService CreateDefaultService(string driverPa /// The directory containing the IEDriverServer executable. /// The name of the IEDriverServer executable file. /// A InternetExplorerDriverService using a random port. - public static InternetExplorerDriverService CreateDefaultService(string driverPath, string driverExecutableFileName) + public static InternetExplorerDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName) { return new InternetExplorerDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort()); } diff --git a/dotnet/src/webdriver/Safari/SafariDriverService.cs b/dotnet/src/webdriver/Safari/SafariDriverService.cs index b3ee30a85ddd7..92e2ddb742bff 100644 --- a/dotnet/src/webdriver/Safari/SafariDriverService.cs +++ b/dotnet/src/webdriver/Safari/SafariDriverService.cs @@ -103,20 +103,22 @@ public static SafariDriverService CreateDefaultService() /// /// The path to the executable or the directory containing the SafariDriver executable. /// A SafariDriverService using a random port. - public static SafariDriverService CreateDefaultService(string driverPath) + public static SafariDriverService CreateDefaultService(string? driverPath) { - string fileName; if (File.Exists(driverPath)) { - fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath)!; + string fileName = Path.GetFileName(driverPath); + string driverFolder = Path.GetDirectoryName(driverPath)!; + + return CreateDefaultService(driverFolder, fileName); } else { - fileName = DefaultSafariDriverServiceExecutableName; - } + string fileName = DefaultSafariDriverServiceExecutableName; + string? driverFolder = driverPath; - return CreateDefaultService(driverPath, fileName); + return CreateDefaultService(driverFolder, fileName); + } } /// @@ -125,7 +127,7 @@ public static SafariDriverService CreateDefaultService(string driverPath) /// The directory containing the SafariDriver executable. /// The name of the SafariDriver executable file. /// A SafariDriverService using a random port. - public static SafariDriverService CreateDefaultService(string driverPath, string driverExecutableFileName) + public static SafariDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName) { return new SafariDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort()); }