diff --git a/dotnet/src/webdriver/Chrome/ChromeDriverService.cs b/dotnet/src/webdriver/Chrome/ChromeDriverService.cs index c6c85f286581f..ee1a2559a77e9 100644 --- a/dotnet/src/webdriver/Chrome/ChromeDriverService.cs +++ b/dotnet/src/webdriver/Chrome/ChromeDriverService.cs @@ -21,6 +21,8 @@ using OpenQA.Selenium.Internal; using System.IO; +#nullable enable + namespace OpenQA.Selenium.Chrome { /// @@ -36,7 +38,7 @@ public sealed class ChromeDriverService : ChromiumDriverService /// The full path to the ChromeDriver executable. /// The file name of the ChromeDriver executable. /// The port on which the ChromeDriver executable should listen. - private ChromeDriverService(string executablePath, string executableFileName, int port) + private ChromeDriverService(string? executablePath, string? executableFileName, int port) : base(executablePath, executableFileName, port) { } @@ -67,7 +69,7 @@ public static ChromeDriverService CreateDefaultService(string driverPath) if (File.Exists(driverPath)) { fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath); + driverPath = Path.GetDirectoryName(driverPath)!; } else { diff --git a/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs b/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs index bf9779d750319..73bb49dc4eb95 100644 --- a/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs +++ b/dotnet/src/webdriver/Chromium/ChromiumDriverService.cs @@ -38,7 +38,7 @@ 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. - protected ChromiumDriverService(string executablePath, string executableFileName, int port) + protected ChromiumDriverService(string? executablePath, string? executableFileName, int port) : base(executablePath, port, executableFileName) { } diff --git a/dotnet/src/webdriver/Edge/EdgeDriverService.cs b/dotnet/src/webdriver/Edge/EdgeDriverService.cs index 0ee5b128a4a9b..4a911439c8dbd 100644 --- a/dotnet/src/webdriver/Edge/EdgeDriverService.cs +++ b/dotnet/src/webdriver/Edge/EdgeDriverService.cs @@ -22,6 +22,8 @@ using System; using System.IO; +#nullable enable + namespace OpenQA.Selenium.Edge { /// @@ -37,7 +39,7 @@ public sealed class EdgeDriverService : ChromiumDriverService /// The full path to the EdgeDriver executable. /// The file name of the EdgeDriver executable. /// The port on which the EdgeDriver executable should listen. - private EdgeDriverService(string executablePath, string executableFileName, int port) + private EdgeDriverService(string? executablePath, string? executableFileName, int port) : base(executablePath, executableFileName, port) { } @@ -54,8 +56,8 @@ protected override DriverOptions GetDefaultDriverOptions() [Obsolete("Use EnableVerboseLogging")] public bool UseVerboseLogging { - get { return this.EnableVerboseLogging; } - set { this.EnableVerboseLogging = value; } + get => this.EnableVerboseLogging; + set => this.EnableVerboseLogging = value; } /// @@ -78,7 +80,7 @@ public static EdgeDriverService CreateDefaultService(string driverPath) if (File.Exists(driverPath)) { fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath); + driverPath = Path.GetDirectoryName(driverPath)!; } else { diff --git a/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs b/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs index 3214bbbe36203..9b7af524877a7 100644 --- a/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs +++ b/dotnet/src/webdriver/IE/InternetExplorerDriverService.cs @@ -22,28 +22,24 @@ using System.IO; using System.Text; +#nullable enable + namespace OpenQA.Selenium.IE { /// - /// Exposes the service provided by the native IEDriverServer executable. + /// Exposes the service provided by the native IEDriverServer executable. /// public sealed class InternetExplorerDriverService : DriverService { private const string InternetExplorerDriverServiceFileName = "IEDriverServer.exe"; - private InternetExplorerDriverLogLevel loggingLevel = InternetExplorerDriverLogLevel.Fatal; - private string host = string.Empty; - private string logFile = string.Empty; - private string libraryExtractionPath = string.Empty; - private string whitelistedIpAddresses = string.Empty; - /// /// Initializes a new instance of the class. /// - /// The full path to the IEDriverServer executable. - /// The file name of the IEDriverServer executable. - /// The port on which the IEDriverServer executable should listen. - private InternetExplorerDriverService(string executablePath, string executableFileName, int port) + /// The full path to the IEDriverServer executable. + /// 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) { } @@ -55,57 +51,36 @@ protected override DriverOptions GetDefaultDriverOptions() } /// - /// Gets or sets the value of the host adapter on which the IEDriverServer should listen for connections. + /// Gets or sets the value of the host adapter on which the IEDriverServer should listen for connections. /// - public string Host - { - get { return this.host; } - set { this.host = value; } - } + public string? Host { get; set; } /// - /// Gets or sets the location of the log file written to by the IEDriverServer. + /// Gets or sets the location of the log file written to by the IEDriverServer. /// - public string LogFile - { - get { return this.logFile; } - set { this.logFile = value; } - } + public string? LogFile { get; set; } /// - /// Gets or sets the logging level used by the IEDriverServer. + /// Gets or sets the logging level used by the IEDriverServer. Defaults to . /// - public InternetExplorerDriverLogLevel LoggingLevel - { - get { return this.loggingLevel; } - set { this.loggingLevel = value; } - } + public InternetExplorerDriverLogLevel LoggingLevel { get; set; } = InternetExplorerDriverLogLevel.Fatal; /// - /// Gets or sets the path to which the supporting library of the IEDriverServer.exe is extracted. - /// Defaults to the temp directory if this property is not set. + /// Gets or sets the path to which the supporting library of the IEDriverServer.exe is extracted. + /// Defaults to the temp directory if this property is or . /// /// - /// The IEDriverServer.exe requires extraction of a supporting library to perform some of its functions. Setting + /// The IEDriverServer.exe requires extraction of a supporting library to perform some of its functions. Setting /// This library is extracted to the temp directory if this property is not set. If the property is set, it must /// be set to a valid directory. /// - public string LibraryExtractionPath - { - get { return this.libraryExtractionPath; } - set { this.libraryExtractionPath = value; } - } + public string? LibraryExtractionPath { get; set; } /// - /// Gets or sets the comma-delimited list of IP addresses that are approved to - /// connect to this instance of the IEDriverServer. Defaults to an empty string, - /// which means only the local loopback address can connect. + /// Gets or sets the comma-delimited list of IP addresses that are approved to connect to this instance of the IEDriverServer. + /// If or , only the local loopback address can connect. /// - public string WhitelistedIPAddresses - { - get { return this.whitelistedIpAddresses; } - set { this.whitelistedIpAddresses = value; } - } + public string? WhitelistedIPAddresses { get; set; } /// /// Gets the command-line arguments for the driver service. @@ -115,29 +90,29 @@ protected override string CommandLineArguments get { StringBuilder argsBuilder = new StringBuilder(base.CommandLineArguments); - if (!string.IsNullOrEmpty(this.host)) + if (!string.IsNullOrEmpty(this.Host)) { - argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -host={0}", this.host)); + argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -host={0}", this.Host)); } - if (!string.IsNullOrEmpty(this.logFile)) + if (!string.IsNullOrEmpty(this.LogFile)) { - argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-file=\"{0}\"", this.logFile)); + argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-file=\"{0}\"", this.LogFile)); } - if (!string.IsNullOrEmpty(this.libraryExtractionPath)) + if (!string.IsNullOrEmpty(this.LibraryExtractionPath)) { - argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -extract-path=\"{0}\"", this.libraryExtractionPath)); + argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -extract-path=\"{0}\"", this.LibraryExtractionPath)); } - if (this.loggingLevel != InternetExplorerDriverLogLevel.Fatal) + if (this.LoggingLevel != InternetExplorerDriverLogLevel.Fatal) { - argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-level={0}", this.loggingLevel.ToString().ToUpperInvariant())); + argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-level={0}", this.LoggingLevel.ToString().ToUpperInvariant())); } - if (!string.IsNullOrEmpty(this.whitelistedIpAddresses)) + if (!string.IsNullOrEmpty(this.WhitelistedIPAddresses)) { - argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -whitelisted-ips={0}", this.whitelistedIpAddresses)); + argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -whitelisted-ips={0}", this.WhitelistedIPAddresses)); } if (this.SuppressInitialDiagnosticInformation) @@ -159,9 +134,9 @@ public static InternetExplorerDriverService CreateDefaultService() } /// - /// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable. + /// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable. /// - /// The path to the executable or the directory containing the IEDriverServer executable. + /// The path to the executable or the directory containing the IEDriverServer executable. /// A InternetExplorerDriverService using a random port. public static InternetExplorerDriverService CreateDefaultService(string driverPath) { @@ -169,7 +144,7 @@ public static InternetExplorerDriverService CreateDefaultService(string driverPa if (File.Exists(driverPath)) { fileName = Path.GetFileName(driverPath); - driverPath = Path.GetDirectoryName(driverPath); + driverPath = Path.GetDirectoryName(driverPath)!; } else { @@ -180,10 +155,10 @@ public static InternetExplorerDriverService CreateDefaultService(string driverPa } /// - /// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable with the given name. + /// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable with the given name. /// - /// The directory containing the IEDriverServer executable. - /// The name of the IEDriverServer executable file. + /// 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) {