diff --git a/dotnet/src/webdriver/Chrome/ChromeDriver.cs b/dotnet/src/webdriver/Chrome/ChromeDriver.cs index 005572f2f8d07..2841470636536 100644 --- a/dotnet/src/webdriver/Chrome/ChromeDriver.cs +++ b/dotnet/src/webdriver/Chrome/ChromeDriver.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +#nullable enable + namespace OpenQA.Selenium.Chrome { /// @@ -60,7 +62,7 @@ namespace OpenQA.Selenium.Chrome /// public class ChromeDriver : ChromiumDriver { - private static Dictionary chromeCustomCommands = new Dictionary() + private static readonly Dictionary chromeCustomCommands = new Dictionary() { { ExecuteCdp, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/goog/cdp/execute") }, { GetCastSinksCommand, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/goog/cast/get_sinks") }, @@ -83,6 +85,7 @@ public ChromeDriver() /// Initializes a new instance of the class using the specified options. /// /// The to be used with the Chrome driver. + /// If is . public ChromeDriver(ChromeOptions options) : this(ChromeDriverService.CreateDefaultService(), options, RemoteWebDriver.DefaultCommandTimeout) { @@ -92,6 +95,7 @@ public ChromeDriver(ChromeOptions options) /// Initializes a new instance of the class using the specified driver service. /// /// The used to initialize the driver. + /// If is . public ChromeDriver(ChromeDriverService service) : this(service, new ChromeOptions()) { @@ -113,6 +117,7 @@ public ChromeDriver(string chromeDriverDirectory) /// /// The full path to the directory containing ChromeDriver.exe. /// The to be used with the Chrome driver. + /// If is . public ChromeDriver(string chromeDriverDirectory, ChromeOptions options) : this(chromeDriverDirectory, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -125,6 +130,7 @@ public ChromeDriver(string chromeDriverDirectory, ChromeOptions options) /// The full path to the directory containing ChromeDriver.exe. /// The to be used with the Chrome driver. /// The maximum amount of time to wait for each command. + /// If is . public ChromeDriver(string chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout) : this(ChromeDriverService.CreateDefaultService(chromeDriverDirectory), options, commandTimeout) { @@ -136,6 +142,7 @@ public ChromeDriver(string chromeDriverDirectory, ChromeOptions options, TimeSpa /// /// The to use. /// The used to initialize the driver. + /// If or are . public ChromeDriver(ChromeDriverService service, ChromeOptions options) : this(service, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -147,6 +154,7 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) /// The to use. /// The to be used with the Chrome driver. /// The maximum amount of time to wait for each command. + /// If or are . public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout) : base(service, options, commandTimeout) { diff --git a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs index 489109d34f2d4..f683bec9c2eab 100644 --- a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs +++ b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs @@ -22,9 +22,12 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.Chromium { /// @@ -108,9 +111,9 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools public static readonly string SetPermissionCommand = "setPermission"; private readonly string optionsCapabilityName; - private DevToolsSession devToolsSession; + private DevToolsSession? devToolsSession; - private static Dictionary chromiumCustomCommands = new Dictionary() + private static readonly Dictionary chromiumCustomCommands = new Dictionary() { { GetNetworkConditionsCommand, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/chromium/network_conditions") }, { SetNetworkConditionsCommand, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/network_conditions") }, @@ -127,19 +130,18 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools /// The to use. /// The to be used with the ChromiumDriver. /// The maximum amount of time to wait for each command. + /// If or are . + /// If the Chromium options capability name is . protected ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout) : base(GenerateDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options)) { - this.optionsCapabilityName = options.CapabilityName; + this.optionsCapabilityName = options.CapabilityName ?? throw new ArgumentException("No chromium options capability name specified", nameof(options)); } /// /// Gets the dictionary of custom Chromium commands registered with the driver. /// - protected static IReadOnlyDictionary ChromiumCustomCommands - { - get { return new ReadOnlyDictionary(chromiumCustomCommands); } - } + protected static IReadOnlyDictionary ChromiumCustomCommands => new ReadOnlyDictionary(chromiumCustomCommands); /// /// Uses DriverFinder to set Service attributes if necessary when creating the command executor @@ -150,6 +152,16 @@ protected static IReadOnlyDictionary ChromiumCustomCommands /// private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout) { + if (service is null) + { + throw new ArgumentNullException(nameof(service)); + } + + if (options is null) + { + throw new ArgumentNullException(nameof(options)); + } + if (service.DriverServicePath == null) { DriverFinder finder = new DriverFinder(options); @@ -177,27 +189,31 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi /// in conjunction with a standalone WebDriver server. public override IFileDetector FileDetector { - get { return base.FileDetector; } + get => base.FileDetector; set { } } /// /// Gets a value indicating whether a DevTools session is active. /// - public bool HasActiveDevToolsSession - { - get { return this.devToolsSession != null; } - } + [MemberNotNullWhen(true, nameof(devToolsSession))] + public bool HasActiveDevToolsSession => this.devToolsSession != null; /// /// Gets or sets the network condition emulation for Chromium. /// + /// If the value is set to . public ChromiumNetworkConditions NetworkConditions { get { Response response = this.Execute(GetNetworkConditionsCommand, null); - return ChromiumNetworkConditions.FromDictionary(response.Value as Dictionary); + if (response.Value is not Dictionary responseDictionary) + { + throw new WebDriverException($"GetNetworkConditions command returned successfully, but data was not an object: {response.Value}"); + } + + return ChromiumNetworkConditions.FromDictionary(responseDictionary); } set @@ -209,6 +225,7 @@ public ChromiumNetworkConditions NetworkConditions Dictionary parameters = new Dictionary(); parameters["network_conditions"] = value; + this.Execute(SetNetworkConditionsCommand, parameters); } } @@ -217,6 +234,7 @@ public ChromiumNetworkConditions NetworkConditions /// Launches a Chromium based application. /// /// ID of the chromium app to launch. + /// If is . public void LaunchApp(string id) { if (id == null) @@ -226,6 +244,7 @@ public void LaunchApp(string id) Dictionary parameters = new Dictionary(); parameters["id"] = id; + this.Execute(LaunchAppCommand, parameters); } @@ -234,6 +253,7 @@ public void LaunchApp(string id) /// /// Name of item to set the permission on. /// Value to set the permission to. + /// If or are . public void SetPermission(string permissionName, string permissionValue) { if (permissionName == null) @@ -260,7 +280,8 @@ public void SetPermission(string permissionName, string permissionValue) /// Name of the command to execute. /// Parameters of the command to execute. /// An object representing the result of the command, if applicable. - public object ExecuteCdpCommand(string commandName, Dictionary commandParameters) + /// If is . + public object? ExecuteCdpCommand(string commandName, Dictionary commandParameters) { if (commandName == null) { @@ -296,21 +317,20 @@ public DevToolsSession GetDevToolsSession(DevToolsOptions options) throw new WebDriverException("Cannot find " + this.optionsCapabilityName + " capability for driver"); } - Dictionary optionsCapability = this.Capabilities.GetCapability(this.optionsCapabilityName) as Dictionary; - if (optionsCapability == null) + object? optionsCapabilityObject = this.Capabilities.GetCapability(this.optionsCapabilityName); + if (optionsCapabilityObject is not Dictionary optionsCapability) { - throw new WebDriverException("Found " + this.optionsCapabilityName + " capability, but is not an object"); + throw new WebDriverException($"Found {this.optionsCapabilityName} capability, but is not an object: {optionsCapabilityObject}"); } - if (!optionsCapability.ContainsKey("debuggerAddress")) + if (!optionsCapability.TryGetValue("debuggerAddress", out object? debuggerAddress)) { throw new WebDriverException("Did not find debuggerAddress capability in " + this.optionsCapabilityName); } - string debuggerAddress = optionsCapability["debuggerAddress"].ToString(); try { - DevToolsSession session = new DevToolsSession(debuggerAddress, options); + DevToolsSession session = new DevToolsSession(debuggerAddress?.ToString(), options); Task.Run(async () => await session.StartSession()).GetAwaiter().GetResult(); this.devToolsSession = session; } @@ -341,7 +361,7 @@ public void CloseDevToolsSession() { if (this.devToolsSession != null) { - Task.Run(async () => await this.devToolsSession.StopSession(true)).GetAwaiter().GetResult(); + Task.Run(async () => await this.devToolsSession.StopSession(manualDetach: true)).GetAwaiter().GetResult(); } } @@ -361,18 +381,16 @@ public List> GetCastSinks() { List> returnValue = new List>(); Response response = this.Execute(GetCastSinksCommand, null); - object[] responseValue = response.Value as object[]; - if (responseValue != null) + if (response.Value is object?[] responseValue) { - foreach (object entry in responseValue) + foreach (object? entry in responseValue) { - Dictionary entryValue = entry as Dictionary; - if (entryValue != null) + if (entry is Dictionary entryValue) { Dictionary sink = new Dictionary(); - foreach (KeyValuePair pair in entryValue) + foreach (KeyValuePair pair in entryValue) { - sink[pair.Key] = pair.Value.ToString(); + sink[pair.Key] = pair.Value!.ToString()!; } returnValue.Add(sink); @@ -434,10 +452,10 @@ public void StartDesktopMirroring(string deviceName) /// Returns the error message if there is any issue in a Cast session. /// /// An error message. - public String GetCastIssueMessage() + public string? GetCastIssueMessage() { Response response = this.Execute(GetCastIssueMessageCommand, null); - return (string)response.Value; + return (string?)response.Value; } /// diff --git a/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs b/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs index 78329f1722edb..6150bacaef766 100644 --- a/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs +++ b/dotnet/src/webdriver/Chromium/ChromiumNetworkConditions.cs @@ -91,12 +91,12 @@ public long UploadThroughput /// /// The dictionary to use to create the object. /// The ChromiumNetworkConditions object created from the dictionary. - public static ChromiumNetworkConditions FromDictionary(Dictionary dictionary) + public static ChromiumNetworkConditions FromDictionary(Dictionary dictionary) { ChromiumNetworkConditions conditions = new ChromiumNetworkConditions(); if (dictionary.TryGetValue("offline", out object? offline)) { - conditions.IsOffline = (bool)offline; + conditions.IsOffline = (bool)offline!; } if (dictionary.TryGetValue("latency", out object? latency)) @@ -106,12 +106,12 @@ public static ChromiumNetworkConditions FromDictionary(Dictionary @@ -30,7 +32,7 @@ namespace OpenQA.Selenium.Edge /// public class EdgeDriver : ChromiumDriver { - private static Dictionary edgeCustomCommands = new Dictionary() + private static readonly Dictionary edgeCustomCommands = new Dictionary() { { ExecuteCdp, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/ms/cdp/execute") }, { GetCastSinksCommand, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/ms/cast/get_sinks") }, @@ -53,6 +55,7 @@ public EdgeDriver() /// Initializes a new instance of the class using the specified options. /// /// The to be used with the Edge driver. + /// If is . public EdgeDriver(EdgeOptions options) : this(EdgeDriverService.CreateDefaultService(), options) { @@ -62,6 +65,7 @@ public EdgeDriver(EdgeOptions options) /// Initializes a new instance of the class using the specified driver service. /// /// The used to initialize the driver. + /// If is . public EdgeDriver(EdgeDriverService service) : this(service, new EdgeOptions()) { @@ -83,6 +87,7 @@ public EdgeDriver(string edgeDriverDirectory) /// /// The full path to the directory containing the WebDriver executable. /// The to be used with the Edge driver. + /// If is . public EdgeDriver(string edgeDriverDirectory, EdgeOptions options) : this(edgeDriverDirectory, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -95,6 +100,7 @@ public EdgeDriver(string edgeDriverDirectory, EdgeOptions options) /// The full path to the directory containing the WebDriver executable. /// The to be used with the Edge driver. /// The maximum amount of time to wait for each command. + /// If is . public EdgeDriver(string edgeDriverDirectory, EdgeOptions options, TimeSpan commandTimeout) : this(EdgeDriverService.CreateDefaultService(edgeDriverDirectory), options, commandTimeout) { @@ -106,6 +112,7 @@ public EdgeDriver(string edgeDriverDirectory, EdgeOptions options, TimeSpan comm /// /// The to use. /// The used to initialize the driver. + /// If or are . public EdgeDriver(EdgeDriverService service, EdgeOptions options) : this(service, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -117,6 +124,7 @@ public EdgeDriver(EdgeDriverService service, EdgeOptions options) /// The to use. /// The to be used with the Edge driver. /// The maximum amount of time to wait for each command. + /// If or are . public EdgeDriver(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout) : base(service, options, commandTimeout) { diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs index 256d6f2dac55b..e2b809791a835 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs @@ -24,7 +24,8 @@ using System.Globalization; using System.IO; using System.IO.Compression; -using System.Threading.Tasks; + +#nullable enable namespace OpenQA.Selenium.Firefox { @@ -97,7 +98,7 @@ public class FirefoxDriver : WebDriver /// public static readonly string GetFullPageScreenshotCommand = "fullPageScreenshot"; - private static Dictionary firefoxCustomCommands = new Dictionary() + private static readonly Dictionary firefoxCustomCommands = new Dictionary() { { SetContextCommand, new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/moz/context") }, { GetContextCommand, new HttpCommandInfo(HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/context") }, @@ -118,6 +119,7 @@ public FirefoxDriver() /// Initializes a new instance of the class using the specified options. Uses the Mozilla-provided Marionette driver implementation. /// /// The to be used with the Firefox driver. + /// If is . public FirefoxDriver(FirefoxOptions options) : this(FirefoxDriverService.CreateDefaultService(), options, RemoteWebDriver.DefaultCommandTimeout) { @@ -127,6 +129,7 @@ public FirefoxDriver(FirefoxOptions options) /// Initializes a new instance of the class using the specified driver service. Uses the Mozilla-provided Marionette driver implementation. /// /// The used to initialize the driver. + /// If is . public FirefoxDriver(FirefoxDriverService service) : this(service, new FirefoxOptions(), RemoteWebDriver.DefaultCommandTimeout) { @@ -134,9 +137,9 @@ public FirefoxDriver(FirefoxDriverService service) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing geckodriver.exe. + /// to the directory containing geckodriver.exe. /// - /// The full path to the directory containing geckodriver.exe. + /// The full path to the directory containing geckodriver.exe. public FirefoxDriver(string geckoDriverDirectory) : this(geckoDriverDirectory, new FirefoxOptions()) { @@ -144,10 +147,11 @@ public FirefoxDriver(string geckoDriverDirectory) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing geckodriver.exe and options. + /// to the directory containing geckodriver.exe and options. /// - /// The full path to the directory containing geckodriver.exe. + /// The full path to the directory containing geckodriver.exe. /// The to be used with the Firefox driver. + /// If is . public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options) : this(geckoDriverDirectory, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -155,11 +159,12 @@ public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing geckodriver.exe, options, and command timeout. + /// to the directory containing geckodriver.exe, options, and command timeout. /// - /// The full path to the directory containing geckodriver.exe. + /// The full path to the directory containing geckodriver.exe. /// The to be used with the Firefox driver. /// The maximum amount of time to wait for each command. + /// If is . public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout) : this(FirefoxDriverService.CreateDefaultService(geckoDriverDirectory), options, commandTimeout) { @@ -170,6 +175,7 @@ public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options, TimeSp /// /// The to use. /// The to be used with the Firefox driver. + /// If or are . public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options) : this(service, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -181,6 +187,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options) /// The to use. /// The to be used with the Firefox driver. /// The maximum amount of time to wait for each command. + /// If or are . public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout) : base(GenerateDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options)) { @@ -195,8 +202,19 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeS /// /// /// + /// If is . private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout) { + if (options is null) + { + throw new ArgumentNullException(nameof(options)); + } + + if (service is null) + { + throw new ArgumentNullException(nameof(service)); + } + if (service.DriverServicePath == null) { DriverFinder finder = new DriverFinder(options); @@ -217,10 +235,7 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi /// The keys of the dictionary are the names assigned to the command; the values are the /// objects describing the command behavior. /// - public static IReadOnlyDictionary CustomCommandDefinitions - { - get { return new ReadOnlyDictionary(firefoxCustomCommands); } - } + public static IReadOnlyDictionary CustomCommandDefinitions => new ReadOnlyDictionary(firefoxCustomCommands); /// /// Gets or sets the responsible for detecting @@ -234,31 +249,30 @@ public static IReadOnlyDictionary CustomCommandDefinitions /// conjunction with a standalone WebDriver server. public override IFileDetector FileDetector { - get { return base.FileDetector; } + get => base.FileDetector; set { } } /// - /// Sets the command context used when issuing commands to geckodriver. + /// Sets the command context used when issuing commands to geckodriver. /// /// If response is not recognized /// The context of commands. public FirefoxCommandContext GetContext() { - FirefoxCommandContext output; - string response = this.Execute(GetContextCommand, null).Value.ToString(); + Response commandResponse = this.Execute(GetContextCommand, null); - bool success = Enum.TryParse(response, true, out output); - if (!success) + if (commandResponse.Value is not string response + || !Enum.TryParse(response, ignoreCase: true, out FirefoxCommandContext output)) { - throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Do not recognize response: {0}; expected Context or Chrome")); + throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Do not recognize response: {0}; expected Context or Chrome", commandResponse.Value)); } return output; } /// - /// Sets the command context used when issuing commands to geckodriver. + /// Sets the command context used when issuing commands to geckodriver. /// /// The value to which to set the context. public void SetContext(FirefoxCommandContext context) @@ -313,12 +327,16 @@ public string InstallAddOnFromFile(string addOnFileToInstall, bool temporary = f throw new ArgumentNullException(nameof(addOnFileToInstall), "Add-on file name must not be null or the empty string"); } - if (!File.Exists(addOnFileToInstall)) + byte[] addOnBytes; + try + { + addOnBytes = File.ReadAllBytes(addOnFileToInstall); + } + catch (Exception ex) { - throw new ArgumentException("File " + addOnFileToInstall + " does not exist", nameof(addOnFileToInstall)); + throw new ArgumentException($"Failed to read from file {addOnFileToInstall}", nameof(addOnFileToInstall), ex); } - byte[] addOnBytes = File.ReadAllBytes(addOnFileToInstall); string base64EncodedAddOn = Convert.ToBase64String(addOnBytes); return this.InstallAddOn(base64EncodedAddOn, temporary); @@ -344,7 +362,8 @@ public string InstallAddOn(string base64EncodedAddOn, bool temporary = false) ["temporary"] = temporary }; Response response = this.Execute(InstallAddOnCommand, parameters); - return (string)response.Value; + + return (string)response.Value!; } /// @@ -371,7 +390,9 @@ public void UninstallAddOn(string addOnId) public Screenshot GetFullPageScreenshot() { Response screenshotResponse = this.Execute(GetFullPageScreenshotCommand, null); - string base64 = screenshotResponse.Value.ToString(); + + screenshotResponse.EnsureValueIsNotNull(); + string base64 = screenshotResponse.Value.ToString()!; return new Screenshot(base64); } diff --git a/dotnet/src/webdriver/IE/InternetExplorerDriver.cs b/dotnet/src/webdriver/IE/InternetExplorerDriver.cs index f129ef28e2769..dcc02890c7065 100644 --- a/dotnet/src/webdriver/IE/InternetExplorerDriver.cs +++ b/dotnet/src/webdriver/IE/InternetExplorerDriver.cs @@ -21,6 +21,8 @@ using System; using System.IO; +#nullable enable + namespace OpenQA.Selenium.IE { /// @@ -76,6 +78,7 @@ public InternetExplorerDriver() /// options. /// /// The used to initialize the driver. + /// If is . public InternetExplorerDriver(InternetExplorerOptions options) : this(InternetExplorerDriverService.CreateDefaultService(), options) { @@ -85,6 +88,7 @@ public InternetExplorerDriver(InternetExplorerOptions options) /// Initializes a new instance of the class using the specified driver service. /// /// The used to initialize the driver. + /// If is . public InternetExplorerDriver(InternetExplorerDriverService service) : this(service, new InternetExplorerOptions()) { @@ -92,9 +96,9 @@ public InternetExplorerDriver(InternetExplorerDriverService service) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing IEDriverServer.exe. + /// to the directory containing IEDriverServer.exe. /// - /// The full path to the directory containing IEDriverServer.exe. + /// The full path to the directory containing IEDriverServer.exe. public InternetExplorerDriver(string internetExplorerDriverServerDirectory) : this(internetExplorerDriverServerDirectory, new InternetExplorerOptions()) { @@ -102,10 +106,11 @@ public InternetExplorerDriver(string internetExplorerDriverServerDirectory) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing IEDriverServer.exe and options. + /// to the directory containing IEDriverServer.exe and options. /// - /// The full path to the directory containing IEDriverServer.exe. + /// The full path to the directory containing IEDriverServer.exe. /// The used to initialize the driver. + /// If is . public InternetExplorerDriver(string internetExplorerDriverServerDirectory, InternetExplorerOptions options) : this(internetExplorerDriverServerDirectory, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -113,11 +118,12 @@ public InternetExplorerDriver(string internetExplorerDriverServerDirectory, Inte /// /// Initializes a new instance of the class using the specified path - /// to the directory containing IEDriverServer.exe, options, and command timeout. + /// to the directory containing IEDriverServer.exe, options, and command timeout. /// - /// The full path to the directory containing IEDriverServer.exe. + /// The full path to the directory containing IEDriverServer.exe. /// The used to initialize the driver. /// The maximum amount of time to wait for each command. + /// If is . public InternetExplorerDriver(string internetExplorerDriverServerDirectory, InternetExplorerOptions options, TimeSpan commandTimeout) : this(InternetExplorerDriverService.CreateDefaultService(internetExplorerDriverServerDirectory), options, commandTimeout) { @@ -129,6 +135,7 @@ public InternetExplorerDriver(string internetExplorerDriverServerDirectory, Inte /// /// The to use. /// The used to initialize the driver. + /// If or are . public InternetExplorerDriver(InternetExplorerDriverService service, InternetExplorerOptions options) : this(service, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -141,6 +148,7 @@ public InternetExplorerDriver(InternetExplorerDriverService service, InternetExp /// The to use. /// The used to initialize the driver. /// The maximum amount of time to wait for each command. + /// If or are . public InternetExplorerDriver(InternetExplorerDriverService service, InternetExplorerOptions options, TimeSpan commandTimeout) : base(GenerateDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options)) { @@ -155,6 +163,16 @@ public InternetExplorerDriver(InternetExplorerDriverService service, InternetExp /// private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout) { + if (service is null) + { + throw new ArgumentNullException(nameof(service)); + } + + if (options is null) + { + throw new ArgumentNullException(nameof(options)); + } + if (service.DriverServicePath == null) { DriverFinder finder = new DriverFinder(options); @@ -170,14 +188,14 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi /// sequences of keystrokes representing file paths and names. /// /// The IE driver does not allow a file detector to be set, - /// as the server component of the IE driver (IEDriverServer.exe) only + /// as the server component of the IE driver (IEDriverServer.exe) only /// allows uploads from the local computer environment. Attempting to set /// this property has no effect, but does not throw an exception. If you /// are attempting to run the IE driver remotely, use /// in conjunction with a standalone WebDriver server. public override IFileDetector FileDetector { - get { return base.FileDetector; } + get => base.FileDetector; set { } } diff --git a/dotnet/src/webdriver/Safari/SafariDriver.cs b/dotnet/src/webdriver/Safari/SafariDriver.cs index b8d81c22ed56d..0f0526633bfb4 100644 --- a/dotnet/src/webdriver/Safari/SafariDriver.cs +++ b/dotnet/src/webdriver/Safari/SafariDriver.cs @@ -22,6 +22,8 @@ using System.Collections.Generic; using System.IO; +#nullable enable + namespace OpenQA.Selenium.Safari { /// @@ -80,6 +82,7 @@ public SafariDriver() /// Initializes a new instance of the class using the specified . /// /// The to use for this instance. + /// If is . public SafariDriver(SafariOptions options) : this(SafariDriverService.CreateDefaultService(), options) { @@ -89,6 +92,7 @@ public SafariDriver(SafariOptions options) /// Initializes a new instance of the class using the specified driver service. /// /// The used to initialize the driver. + /// If is . public SafariDriver(SafariDriverService service) : this(service, new SafariOptions()) { @@ -96,7 +100,7 @@ public SafariDriver(SafariDriverService service) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing safaridriver. + /// to the directory containing safaridriver. /// /// The full path to the directory containing SafariDriver executable. public SafariDriver(string safariDriverDirectory) @@ -106,10 +110,11 @@ public SafariDriver(string safariDriverDirectory) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing safaridriver and options. + /// to the directory containing safaridriver and options. /// /// The full path to the directory containing SafariDriver executable. /// The to be used with the Safari driver. + /// If is . public SafariDriver(string safariDriverDirectory, SafariOptions options) : this(safariDriverDirectory, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -117,11 +122,12 @@ public SafariDriver(string safariDriverDirectory, SafariOptions options) /// /// Initializes a new instance of the class using the specified path - /// to the directory containing safaridriver, options, and command timeout. + /// to the directory containing safaridriver, options, and command timeout. /// /// The full path to the directory containing SafariDriver executable. /// The to be used with the Safari driver. /// The maximum amount of time to wait for each command. + /// If is . public SafariDriver(string safariDriverDirectory, SafariOptions options, TimeSpan commandTimeout) : this(SafariDriverService.CreateDefaultService(safariDriverDirectory), options, commandTimeout) { @@ -133,6 +139,7 @@ public SafariDriver(string safariDriverDirectory, SafariOptions options, TimeSpa /// /// The to use. /// The used to initialize the driver. + /// If or are . public SafariDriver(SafariDriverService service, SafariOptions options) : this(service, options, RemoteWebDriver.DefaultCommandTimeout) { @@ -144,6 +151,7 @@ public SafariDriver(SafariDriverService service, SafariOptions options) /// The to use. /// The to be used with the Safari driver. /// The maximum amount of time to wait for each command. + /// If or are . public SafariDriver(SafariDriverService service, SafariOptions options, TimeSpan commandTimeout) : base(GenerateDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options)) { @@ -161,6 +169,16 @@ public SafariDriver(SafariDriverService service, SafariOptions options, TimeSpan /// private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout) { + if (service is null) + { + throw new ArgumentNullException(nameof(service)); + } + + if (options is null) + { + throw new ArgumentNullException(nameof(options)); + } + if (service.DriverServicePath == null) { DriverFinder finder = new DriverFinder(options); @@ -178,7 +196,7 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi /// public void AttachDebugger() { - Dictionary parameters = new Dictionary(); + Dictionary parameters = new Dictionary(); parameters["attachDebugger"] = null; this.Execute(AttachDebuggerCommand, parameters); } @@ -188,6 +206,7 @@ public void AttachDebugger() /// /// The name of the item to set permission on. /// Whether the permission has been granted. + /// If is or . public void SetPermission(string permissionName, bool permissionValue) { if (string.IsNullOrEmpty(permissionName)) @@ -206,7 +225,7 @@ public void SetPermission(string permissionName, bool permissionValue) /// Returns Each available permission item and whether it is allowed or not. /// /// whether the item is allowed or not. - public Object GetPermissions() + public object? GetPermissions() { Response response = this.Execute(GetPermissionsCommand, null); return response.Value; @@ -224,7 +243,7 @@ public Object GetPermissions() /// in conjunction with a standalone WebDriver server. public override IFileDetector FileDetector { - get { return base.FileDetector; } + get => base.FileDetector; set { } }