From 0353a656a5a19567295e95b40b06900047623739 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 28 Oct 2024 18:05:43 -0400 Subject: [PATCH 1/4] [dotnet] Add NRT to `Manage()` and friends --- dotnet/src/webdriver/Alert.cs | 7 ++- dotnet/src/webdriver/Cookie.cs | 49 ++++++++++--------- dotnet/src/webdriver/CookieJar.cs | 26 ++++++---- dotnet/src/webdriver/ICookieJar.cs | 10 ++-- dotnet/src/webdriver/ILogs.cs | 4 ++ dotnet/src/webdriver/INetwork.cs | 7 ++- dotnet/src/webdriver/IOptions.cs | 2 + dotnet/src/webdriver/ITargetLocator.cs | 3 ++ dotnet/src/webdriver/ITimeouts.cs | 2 + dotnet/src/webdriver/IWindow.cs | 2 + .../src/webdriver/Internal/ReturnedCookie.cs | 6 ++- dotnet/src/webdriver/LogEntry.cs | 21 +++++--- dotnet/src/webdriver/Logs.cs | 16 ++++-- dotnet/src/webdriver/NetworkManager.cs | 11 +++-- dotnet/src/webdriver/OptionsManager.cs | 2 + dotnet/src/webdriver/TargetLocator.cs | 26 +++++++--- dotnet/src/webdriver/Timeouts.cs | 2 + dotnet/src/webdriver/Window.cs | 8 +-- 18 files changed, 140 insertions(+), 64 deletions(-) diff --git a/dotnet/src/webdriver/Alert.cs b/dotnet/src/webdriver/Alert.cs index 843372dad9834..cac46bd8cee8f 100644 --- a/dotnet/src/webdriver/Alert.cs +++ b/dotnet/src/webdriver/Alert.cs @@ -19,6 +19,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium { /// @@ -26,7 +28,7 @@ namespace OpenQA.Selenium /// internal class Alert : IAlert { - private WebDriver driver; + private readonly WebDriver driver; /// /// Initializes a new instance of the class. @@ -45,7 +47,7 @@ public string Text get { Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAlertText, null); - return commandResponse.Value.ToString(); + return commandResponse.Value.ToString()!; } } @@ -69,6 +71,7 @@ public void Accept() /// Sends keys to the alert. /// /// The keystrokes to send. + /// If is null. public void SendKeys(string keysToSend) { if (keysToSend == null) diff --git a/dotnet/src/webdriver/Cookie.cs b/dotnet/src/webdriver/Cookie.cs index 5b28cd46b7ff6..08e2d7a111b20 100644 --- a/dotnet/src/webdriver/Cookie.cs +++ b/dotnet/src/webdriver/Cookie.cs @@ -23,6 +23,8 @@ using System.Linq; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium { /// @@ -33,9 +35,9 @@ public class Cookie { private string cookieName; private string cookieValue; - private string cookiePath; - private string cookieDomain; - private string sameSite; + private string? cookiePath; + private string? cookieDomain; + private string? sameSite; private bool isHttpOnly; private bool secure; private DateTime? cookieExpiry; @@ -64,7 +66,7 @@ public Cookie(string name, string value) /// If the name is or an empty string, /// or if it contains a semi-colon. /// If the value is . - public Cookie(string name, string value, string path) + public Cookie(string name, string value, string? path) : this(name, value, path, null) { } @@ -80,7 +82,7 @@ public Cookie(string name, string value, string path) /// If the name is or an empty string, /// or if it contains a semi-colon. /// If the value is . - public Cookie(string name, string value, string path, DateTime? expiry) + public Cookie(string name, string value, string? path, DateTime? expiry) : this(name, value, null, path, expiry) { } @@ -97,7 +99,7 @@ public Cookie(string name, string value, string path, DateTime? expiry) /// If the name is or an empty string, /// or if it contains a semi-colon. /// If the value is . - public Cookie(string name, string value, string domain, string path, DateTime? expiry) + public Cookie(string name, string value, string? domain, string? path, DateTime? expiry) : this(name, value, domain, path, expiry, false, false, null) { } @@ -117,7 +119,7 @@ public Cookie(string name, string value, string domain, string path, DateTime? e /// If the name and value are both an empty string, /// if the name contains a semi-colon, or if same site value is not valid. /// If the name, value or currentUrl is . - public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite) + public Cookie(string name, string value, string? domain, string? path, DateTime? expiry, bool secure, bool isHttpOnly, string? sameSite) { if (name == null) { @@ -190,7 +192,7 @@ public string Value /// [JsonPropertyName("domain")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string Domain + public string? Domain { get { return this.cookieDomain; } } @@ -200,7 +202,7 @@ public string Domain /// [JsonPropertyName("path")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public virtual string Path + public virtual string? Path { get { return this.cookiePath; } } @@ -229,7 +231,7 @@ public virtual bool IsHttpOnly /// [JsonPropertyName("sameSite")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public virtual string SameSite + public virtual string? SameSite { get { return this.sameSite; } } @@ -272,6 +274,7 @@ internal long? ExpirySeconds /// /// The Dictionary object containing the cookie parameters. /// A object with the proper parameters set. + /// If is null. public static Cookie FromDictionary(Dictionary rawCookie) { if (rawCookie == null) @@ -279,20 +282,20 @@ public static Cookie FromDictionary(Dictionary rawCookie) throw new ArgumentNullException(nameof(rawCookie), "Dictionary cannot be null"); } - string name = rawCookie["name"].ToString(); + string name = rawCookie["name"].ToString()!; string value = string.Empty; if (rawCookie["value"] != null) { - value = rawCookie["value"].ToString(); + value = rawCookie["value"].ToString()!; } - string path = "/"; + string? path = "/"; if (rawCookie.ContainsKey("path") && rawCookie["path"] != null) { path = rawCookie["path"].ToString(); } - string domain = string.Empty; + string? domain = string.Empty; if (rawCookie.ContainsKey("domain") && rawCookie["domain"] != null) { domain = rawCookie["domain"].ToString(); @@ -307,16 +310,16 @@ public static Cookie FromDictionary(Dictionary rawCookie) bool secure = false; if (rawCookie.ContainsKey("secure") && rawCookie["secure"] != null) { - secure = bool.Parse(rawCookie["secure"].ToString()); + secure = bool.Parse(rawCookie["secure"].ToString()!); } bool isHttpOnly = false; if (rawCookie.ContainsKey("httpOnly") && rawCookie["httpOnly"] != null) { - isHttpOnly = bool.Parse(rawCookie["httpOnly"].ToString()); + isHttpOnly = bool.Parse(rawCookie["httpOnly"].ToString()!); } - string sameSite = null; + string? sameSite = null; if (rawCookie.ContainsKey("sameSite") && rawCookie["sameSite"] != null) { sameSite = rawCookie["sameSite"].ToString(); @@ -347,10 +350,10 @@ public override string ToString() /// if the specified Object /// is equal to the current Object; otherwise, /// . - public override bool Equals(object obj) + public override bool Equals(object? obj) { // Two cookies are equal if the name and value match - Cookie cookie = obj as Cookie; + Cookie? cookie = obj as Cookie; if (this == obj) { @@ -367,7 +370,7 @@ public override bool Equals(object obj) return false; } - return !(this.cookieValue != null ? !this.cookieValue.Equals(cookie.cookieValue) : cookie.Value != null); + return string.Equals(this.cookieValue, cookie.cookieValue); } /// @@ -379,12 +382,12 @@ public override int GetHashCode() return this.cookieName.GetHashCode(); } - private static string StripPort(string domain) + private static string? StripPort(string? domain) { - return string.IsNullOrEmpty(domain) ? null : domain.Split(':')[0]; + return string.IsNullOrEmpty(domain) ? null : domain!.Split(':')[0]; } - private static DateTime? ConvertExpirationTime(string expirationTime) + private static DateTime? ConvertExpirationTime(string? expirationTime) { DateTime? expires = null; double seconds = 0; diff --git a/dotnet/src/webdriver/CookieJar.cs b/dotnet/src/webdriver/CookieJar.cs index be698efa93a11..d6aca00e3e200 100644 --- a/dotnet/src/webdriver/CookieJar.cs +++ b/dotnet/src/webdriver/CookieJar.cs @@ -20,6 +20,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +#nullable enable + namespace OpenQA.Selenium { /// @@ -27,7 +29,7 @@ namespace OpenQA.Selenium /// internal class CookieJar : ICookieJar { - private WebDriver driver; + private readonly WebDriver driver; /// /// Initializes a new instance of the class. @@ -50,8 +52,14 @@ public ReadOnlyCollection AllCookies /// Method for creating a cookie in the browser /// /// that represents a cookie in the browser + /// If is . public void AddCookie(Cookie cookie) { + if (cookie == null) + { + throw new ArgumentNullException(nameof(cookie)); + } + Dictionary parameters = new Dictionary(); parameters.Add("cookie", cookie); this.driver.InternalExecute(DriverCommand.AddCookie, parameters); @@ -61,9 +69,9 @@ public void AddCookie(Cookie cookie) /// Delete the cookie by passing in the name of the cookie /// /// The name of the cookie that is in the browser - public void DeleteCookieNamed(string name) + public void DeleteCookieNamed(string? name) { - Dictionary parameters = new Dictionary(); + Dictionary parameters = new Dictionary(); parameters.Add("name", name); this.driver.InternalExecute(DriverCommand.DeleteCookie, parameters); } @@ -72,7 +80,7 @@ public void DeleteCookieNamed(string name) /// Delete a cookie in the browser by passing in a copy of a cookie /// /// An object that represents a copy of the cookie that needs to be deleted - public void DeleteCookie(Cookie cookie) + public void DeleteCookie(Cookie? cookie) { if (cookie != null) { @@ -92,10 +100,10 @@ public void DeleteAllCookies() /// Method for returning a getting a cookie by name /// /// name of the cookie that needs to be returned - /// A Cookie from the name - public Cookie GetCookieNamed(string name) + /// A Cookie from the name, or if not found. + public Cookie? GetCookieNamed(string? name) { - Cookie cookieToReturn = null; + Cookie? cookieToReturn = null; if (name != null) { ReadOnlyCollection allCookies = this.AllCookies; @@ -123,12 +131,12 @@ private ReadOnlyCollection GetAllCookies() try { - object[] cookies = returned as object[]; + object[]? cookies = returned as object[]; if (cookies != null) { foreach (object rawCookie in cookies) { - Dictionary cookieDictionary = rawCookie as Dictionary; + Dictionary cookieDictionary = (Dictionary)rawCookie; if (rawCookie != null) { toReturn.Add(Cookie.FromDictionary(cookieDictionary)); diff --git a/dotnet/src/webdriver/ICookieJar.cs b/dotnet/src/webdriver/ICookieJar.cs index 82b919a33959e..3655b801382ef 100644 --- a/dotnet/src/webdriver/ICookieJar.cs +++ b/dotnet/src/webdriver/ICookieJar.cs @@ -16,8 +16,11 @@ // limitations under the License. // +using System; using System.Collections.ObjectModel; +#nullable enable + namespace OpenQA.Selenium { /// @@ -34,6 +37,7 @@ public interface ICookieJar /// Adds a cookie to the current page. /// /// The object to be added. + /// If is . void AddCookie(Cookie cookie); /// @@ -42,19 +46,19 @@ public interface ICookieJar /// The name of the cookie to retrieve. /// The containing the name. Returns /// if no cookie with the specified name is found. - Cookie GetCookieNamed(string name); + Cookie? GetCookieNamed(string? name); /// /// Deletes the specified cookie from the page. /// /// The to be deleted. - void DeleteCookie(Cookie cookie); + void DeleteCookie(Cookie? cookie); /// /// Deletes the cookie with the specified name from the page. /// /// The name of the cookie to be deleted. - void DeleteCookieNamed(string name); + void DeleteCookieNamed(string? name); /// /// Deletes all cookies from the page. diff --git a/dotnet/src/webdriver/ILogs.cs b/dotnet/src/webdriver/ILogs.cs index 89a00aa0a39f5..ab752b7b2c697 100644 --- a/dotnet/src/webdriver/ILogs.cs +++ b/dotnet/src/webdriver/ILogs.cs @@ -16,8 +16,11 @@ // limitations under the License. // +using System; using System.Collections.ObjectModel; +#nullable enable + namespace OpenQA.Selenium { /// @@ -36,6 +39,7 @@ public interface ILogs /// The log for which to retrieve the log entries. /// Log types can be found in the class. /// The list of objects for the specified log. + /// If is . ReadOnlyCollection GetLog(string logKind); } } diff --git a/dotnet/src/webdriver/INetwork.cs b/dotnet/src/webdriver/INetwork.cs index a9a4eb2f0b2b4..0dea1843ee110 100644 --- a/dotnet/src/webdriver/INetwork.cs +++ b/dotnet/src/webdriver/INetwork.cs @@ -19,6 +19,8 @@ using System; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium { /// @@ -29,18 +31,19 @@ public interface INetwork /// /// Occurs when a browser sends a network request. /// - event EventHandler NetworkRequestSent; + event EventHandler? NetworkRequestSent; /// /// Occurs when a browser receives a network response. /// - event EventHandler NetworkResponseReceived; + event EventHandler? NetworkResponseReceived; /// /// Adds a to examine incoming network requests, /// and optionally modify the request or provide a response. /// /// The to add. + /// If is . void AddRequestHandler(NetworkRequestHandler handler); /// diff --git a/dotnet/src/webdriver/IOptions.cs b/dotnet/src/webdriver/IOptions.cs index 2cac7344a7265..347ee5ebd2fb3 100644 --- a/dotnet/src/webdriver/IOptions.cs +++ b/dotnet/src/webdriver/IOptions.cs @@ -16,6 +16,8 @@ // limitations under the License. // +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/ITargetLocator.cs b/dotnet/src/webdriver/ITargetLocator.cs index ed299ef8e8c25..62407a1c77c09 100644 --- a/dotnet/src/webdriver/ITargetLocator.cs +++ b/dotnet/src/webdriver/ITargetLocator.cs @@ -16,6 +16,8 @@ // limitations under the License. // +using System; + namespace OpenQA.Selenium { /// @@ -59,6 +61,7 @@ public interface ITargetLocator /// /// The name of the window to select. /// An instance focused on the given window. + /// If is . /// If the window cannot be found. IWebDriver Window(string windowName); diff --git a/dotnet/src/webdriver/ITimeouts.cs b/dotnet/src/webdriver/ITimeouts.cs index 40e64a4bf7b60..f1c35f4d55aea 100644 --- a/dotnet/src/webdriver/ITimeouts.cs +++ b/dotnet/src/webdriver/ITimeouts.cs @@ -18,6 +18,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/IWindow.cs b/dotnet/src/webdriver/IWindow.cs index 362cc99d574a3..c1101dd17413f 100644 --- a/dotnet/src/webdriver/IWindow.cs +++ b/dotnet/src/webdriver/IWindow.cs @@ -18,6 +18,8 @@ using System.Drawing; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/Internal/ReturnedCookie.cs b/dotnet/src/webdriver/Internal/ReturnedCookie.cs index cc2283f505da1..0902bf8b6efd3 100644 --- a/dotnet/src/webdriver/Internal/ReturnedCookie.cs +++ b/dotnet/src/webdriver/Internal/ReturnedCookie.cs @@ -19,6 +19,8 @@ using System; using System.Globalization; +#nullable enable + namespace OpenQA.Selenium.Internal { /// @@ -41,7 +43,7 @@ public class ReturnedCookie : Cookie /// If the name is or an empty string, /// or if it contains a semi-colon. /// If the value or currentUrl is . - public ReturnedCookie(string name, string value, string domain, string path, DateTime? expiry, bool isSecure, bool isHttpOnly) + public ReturnedCookie(string name, string value, string? domain, string? path, DateTime? expiry, bool isSecure, bool isHttpOnly) : this(name, value, domain, path, expiry, isSecure, isHttpOnly, null) { } @@ -61,7 +63,7 @@ public ReturnedCookie(string name, string value, string domain, string path, Dat /// If the name is or an empty string, /// or if it contains a semi-colon. /// If the value or currentUrl is . - public ReturnedCookie(string name, string value, string domain, string path, DateTime? expiry, bool isSecure, bool isHttpOnly, string sameSite) + public ReturnedCookie(string name, string value, string? domain, string? path, DateTime? expiry, bool isSecure, bool isHttpOnly, string? sameSite) : base(name, value, domain, path, expiry, isSecure, isHttpOnly, sameSite) { diff --git a/dotnet/src/webdriver/LogEntry.cs b/dotnet/src/webdriver/LogEntry.cs index a33ad6ba866db..84ccf5961e00e 100644 --- a/dotnet/src/webdriver/LogEntry.cs +++ b/dotnet/src/webdriver/LogEntry.cs @@ -20,6 +20,8 @@ using System.Collections.Generic; using System.Globalization; +#nullable enable + namespace OpenQA.Selenium { /// @@ -29,7 +31,7 @@ public class LogEntry { private LogLevel level = LogLevel.All; private DateTime timestamp = DateTime.MinValue; - private string message = string.Empty; + private string? message = string.Empty; /// /// Initializes a new instance of the class. @@ -57,7 +59,7 @@ public LogLevel Level /// /// Gets the message of the log entry. /// - public string Message + public string? Message { get { return this.message; } } @@ -77,8 +79,14 @@ public override string ToString() /// The from /// which to create the . /// A with the values in the dictionary. + /// If is . internal static LogEntry FromDictionary(Dictionary entryDictionary) { + if (entryDictionary == null) + { + throw new ArgumentNullException(nameof(entryDictionary)); + } + LogEntry entry = new LogEntry(); if (entryDictionary.ContainsKey("message")) { @@ -94,12 +102,13 @@ internal static LogEntry FromDictionary(Dictionary entryDictiona if (entryDictionary.ContainsKey("level")) { - string levelValue = entryDictionary["level"].ToString(); - try + string? levelValue = entryDictionary["level"].ToString(); + + if (Enum.TryParse(levelValue, ignoreCase: true, out LogLevel level)) { - entry.level = (LogLevel)Enum.Parse(typeof(LogLevel), levelValue, true); + entry.level = level; } - catch (ArgumentException) + else { // If the requested log level string is not a valid log level, // ignore it and use LogLevel.All. diff --git a/dotnet/src/webdriver/Logs.cs b/dotnet/src/webdriver/Logs.cs index 6c903dccc9efd..3894e8bae82e8 100644 --- a/dotnet/src/webdriver/Logs.cs +++ b/dotnet/src/webdriver/Logs.cs @@ -20,6 +20,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +#nullable enable + namespace OpenQA.Selenium { /// @@ -49,12 +51,12 @@ public ReadOnlyCollection AvailableLogTypes try { Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAvailableLogTypes, null); - object[] responseValue = commandResponse.Value as object[]; + object[]? responseValue = commandResponse.Value as object[]; if (responseValue != null) { foreach (object logKind in responseValue) { - availableLogTypes.Add(logKind.ToString()); + availableLogTypes.Add(logKind.ToString()!); } } } @@ -73,20 +75,26 @@ public ReadOnlyCollection AvailableLogTypes /// The log for which to retrieve the log entries. /// Log types can be found in the class. /// The list of objects for the specified log. + /// If is null. public ReadOnlyCollection GetLog(string logKind) { + if (logKind == null) + { + throw new ArgumentNullException(nameof(logKind)); + } + List entries = new List(); Dictionary parameters = new Dictionary(); parameters.Add("type", logKind); Response commandResponse = this.driver.InternalExecute(DriverCommand.GetLog, parameters); - object[] responseValue = commandResponse.Value as object[]; + object[]? responseValue = commandResponse.Value as object[]; if (responseValue != null) { foreach (object rawEntry in responseValue) { - Dictionary entryDictionary = rawEntry as Dictionary; + Dictionary entryDictionary = (Dictionary)rawEntry; if (entryDictionary != null) { entries.Add(LogEntry.FromDictionary(entryDictionary)); diff --git a/dotnet/src/webdriver/NetworkManager.cs b/dotnet/src/webdriver/NetworkManager.cs index 7d3131c7a6114..2ee46c46e784b 100644 --- a/dotnet/src/webdriver/NetworkManager.cs +++ b/dotnet/src/webdriver/NetworkManager.cs @@ -21,6 +21,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium { /// @@ -44,7 +46,7 @@ public NetworkManager(IWebDriver driver) // StartMonitoring(). this.session = new Lazy(() => { - IDevTools devToolsDriver = driver as IDevTools; + IDevTools? devToolsDriver = driver as IDevTools; if (devToolsDriver == null) { throw new WebDriverException("Driver must implement IDevTools to use these features"); @@ -57,12 +59,12 @@ public NetworkManager(IWebDriver driver) /// /// Occurs when a browser sends a network request. /// - public event EventHandler NetworkRequestSent; + public event EventHandler? NetworkRequestSent; /// /// Occurs when a browser receives a network response. /// - public event EventHandler NetworkResponseReceived; + public event EventHandler? NetworkResponseReceived; /// /// Asynchronously starts monitoring for network traffic. @@ -95,6 +97,7 @@ public async Task StopMonitoring() /// and optionally modify the request or provide a response. /// /// The to add. + /// If is null. public void AddRequestHandler(NetworkRequestHandler handler) { if (handler == null) @@ -199,7 +202,7 @@ private async Task OnAuthRequired(object sender, AuthRequiredEventArgs e) { if (authenticationHandler.UriMatcher.Invoke(uri)) { - PasswordCredentials credentials = authenticationHandler.Credentials as PasswordCredentials; + PasswordCredentials credentials = (PasswordCredentials)authenticationHandler.Credentials; await this.session.Value.Domains.Network.ContinueWithAuth(e.RequestId, credentials.UserName, credentials.Password).ConfigureAwait(false); successfullyAuthenticated = true; break; diff --git a/dotnet/src/webdriver/OptionsManager.cs b/dotnet/src/webdriver/OptionsManager.cs index 6f0b6155b2875..e14e5c517b5b5 100644 --- a/dotnet/src/webdriver/OptionsManager.cs +++ b/dotnet/src/webdriver/OptionsManager.cs @@ -16,6 +16,8 @@ // limitations under the License. // +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/TargetLocator.cs b/dotnet/src/webdriver/TargetLocator.cs index 60652a620b232..9bf2d0e7f5849 100644 --- a/dotnet/src/webdriver/TargetLocator.cs +++ b/dotnet/src/webdriver/TargetLocator.cs @@ -22,6 +22,8 @@ using System.Collections.ObjectModel; using System.Text.RegularExpressions; +#nullable enable + namespace OpenQA.Selenium { /// @@ -58,6 +60,8 @@ public IWebDriver Frame(int frameIndex) /// /// name of the frame /// A WebDriver instance that is currently in use + /// If is null. + /// If a non-existent iFrame is queried for. public IWebDriver Frame(string frameName) { if (frameName == null) @@ -84,6 +88,8 @@ public IWebDriver Frame(string frameName) /// /// a previously found FRAME or IFRAME element. /// A WebDriver instance that is currently in use. + /// If is null. + /// If is an invalid object reference. public IWebDriver Frame(IWebElement frameElement) { if (frameElement == null) @@ -91,10 +97,10 @@ public IWebDriver Frame(IWebElement frameElement) throw new ArgumentNullException(nameof(frameElement), "Frame element cannot be null"); } - IWebDriverObjectReference elementReference = frameElement as IWebDriverObjectReference; + IWebDriverObjectReference? elementReference = frameElement as IWebDriverObjectReference; if (elementReference == null) { - IWrapsElement elementWrapper = frameElement as IWrapsElement; + IWrapsElement? elementWrapper = frameElement as IWrapsElement; if (elementWrapper != null) { elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; @@ -130,8 +136,15 @@ public IWebDriver ParentFrame() /// /// Window handle or name of the window that you wish to move to /// A WebDriver instance that is currently in use + /// If is . + /// If no window matching the provided handle or name exists. public IWebDriver Window(string windowHandleOrName) { + if (windowHandleOrName == null) + { + throw new ArgumentNullException(nameof(windowHandleOrName)); + } + Dictionary parameters = new Dictionary(); parameters.Add("handle", windowHandleOrName); try @@ -142,7 +155,7 @@ public IWebDriver Window(string windowHandleOrName) catch (NoSuchWindowException) { // simulate search by name - string original = null; + string? original = null; try { original = this.driver.CurrentWindowHandle; @@ -183,8 +196,8 @@ public IWebDriver NewWindow(WindowType typeHint) Dictionary parameters = new Dictionary(); parameters.Add("type", typeHint.ToString().ToLowerInvariant()); Response response = this.driver.InternalExecute(DriverCommand.NewWindow, parameters); - Dictionary result = response.Value as Dictionary; - string newWindowHandle = result["handle"].ToString(); + Dictionary result = (Dictionary)response.Value; + string newWindowHandle = result["handle"].ToString()!; this.Window(newWindowHandle); return this.driver; } @@ -195,7 +208,7 @@ public IWebDriver NewWindow(WindowType typeHint) /// Element of the default public IWebDriver DefaultContent() { - Dictionary parameters = new Dictionary(); + Dictionary parameters = new Dictionary(); parameters.Add("id", null); this.driver.InternalExecute(DriverCommand.SwitchToFrame, parameters); return this.driver; @@ -215,6 +228,7 @@ public IWebElement ActiveElement() /// Switches to the currently active modal dialog for this particular driver instance. /// /// A handle to the dialog. + /// No alert is present. public IAlert Alert() { // N.B. We only execute the GetAlertText command to be able to throw diff --git a/dotnet/src/webdriver/Timeouts.cs b/dotnet/src/webdriver/Timeouts.cs index ee83696c0401a..bafa40a5e6317 100644 --- a/dotnet/src/webdriver/Timeouts.cs +++ b/dotnet/src/webdriver/Timeouts.cs @@ -20,6 +20,8 @@ using System.Collections.Generic; using System.Globalization; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/Window.cs b/dotnet/src/webdriver/Window.cs index 036f00a7da0ae..32f0f8f5ab6a3 100644 --- a/dotnet/src/webdriver/Window.cs +++ b/dotnet/src/webdriver/Window.cs @@ -21,6 +21,8 @@ using System.Drawing; using System.Globalization; +#nullable enable + namespace OpenQA.Selenium { /// @@ -95,7 +97,7 @@ public Size Size /// public void Maximize() { - Dictionary parameters = null; + Dictionary? parameters = null; this.driver.InternalExecute(DriverCommand.MaximizeWindow, parameters); } @@ -104,7 +106,7 @@ public void Maximize() /// public void Minimize() { - Dictionary parameters = null; + Dictionary? parameters = null; this.driver.InternalExecute(DriverCommand.MinimizeWindow, parameters); } @@ -113,7 +115,7 @@ public void Minimize() /// public void FullScreen() { - Dictionary parameters = null; + Dictionary? parameters = null; this.driver.InternalExecute(DriverCommand.FullScreenWindow, parameters); } } From 184bd6a5b9748f6c3e750f0351af03f2402e55dd Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 28 Oct 2024 18:06:34 -0400 Subject: [PATCH 2/4] Fix XML DOC --- dotnet/src/webdriver/Alert.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/Alert.cs b/dotnet/src/webdriver/Alert.cs index cac46bd8cee8f..74f8ac67e904d 100644 --- a/dotnet/src/webdriver/Alert.cs +++ b/dotnet/src/webdriver/Alert.cs @@ -71,7 +71,7 @@ public void Accept() /// Sends keys to the alert. /// /// The keystrokes to send. - /// If is null. + /// If is . public void SendKeys(string keysToSend) { if (keysToSend == null) From fff58e43a82b9fe4c135859e903c6aff49316bed Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 28 Oct 2024 18:18:23 -0400 Subject: [PATCH 3/4] Fix CookieJar.GetAllCookies() --- dotnet/src/webdriver/CookieJar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/CookieJar.cs b/dotnet/src/webdriver/CookieJar.cs index d6aca00e3e200..d9928a9532ab0 100644 --- a/dotnet/src/webdriver/CookieJar.cs +++ b/dotnet/src/webdriver/CookieJar.cs @@ -136,9 +136,9 @@ private ReadOnlyCollection GetAllCookies() { foreach (object rawCookie in cookies) { - Dictionary cookieDictionary = (Dictionary)rawCookie; if (rawCookie != null) { + Dictionary cookieDictionary = (Dictionary)rawCookie; toReturn.Add(Cookie.FromDictionary(cookieDictionary)); } } From eaae0e69e410daf20372ed3ee4ee31e620238928 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 28 Oct 2024 18:19:55 -0400 Subject: [PATCH 4/4] Fix Logs.GetLog(string) --- dotnet/src/webdriver/Logs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/Logs.cs b/dotnet/src/webdriver/Logs.cs index 3894e8bae82e8..0be03a6a88b35 100644 --- a/dotnet/src/webdriver/Logs.cs +++ b/dotnet/src/webdriver/Logs.cs @@ -94,7 +94,7 @@ public ReadOnlyCollection GetLog(string logKind) { foreach (object rawEntry in responseValue) { - Dictionary entryDictionary = (Dictionary)rawEntry; + Dictionary? entryDictionary = rawEntry as Dictionary; if (entryDictionary != null) { entries.Add(LogEntry.FromDictionary(entryDictionary));