diff --git a/dotnet/src/webdriver/INavigation.cs b/dotnet/src/webdriver/INavigation.cs index e105e00b40e81..a7cb84db9544f 100644 --- a/dotnet/src/webdriver/INavigation.cs +++ b/dotnet/src/webdriver/INavigation.cs @@ -20,6 +20,8 @@ using System; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium { /// @@ -64,6 +66,7 @@ public interface INavigation /// should the underlying page change while your test is executing the results of /// future calls against this interface will be against the freshly loaded page. /// + /// If is null. void GoToUrl(string url); /// @@ -71,6 +74,7 @@ public interface INavigation /// /// String of where you want the browser to go. /// A task object representing the asynchronous operation. + /// If is null. Task GoToUrlAsync(string url); /// @@ -86,6 +90,7 @@ public interface INavigation /// should the underlying page change while your test is executing the results of /// future calls against this interface will be against the freshly loaded page. /// + /// If is null. void GoToUrl(Uri url); /// @@ -93,6 +98,7 @@ public interface INavigation /// /// Uri object of where you want the browser to go. /// A task object representing the asynchronous operation. + /// If is null. Task GoToUrlAsync(Uri url); /// diff --git a/dotnet/src/webdriver/ITargetLocator.cs b/dotnet/src/webdriver/ITargetLocator.cs index 933e9d928ce6f..68b55610626bb 100644 --- a/dotnet/src/webdriver/ITargetLocator.cs +++ b/dotnet/src/webdriver/ITargetLocator.cs @@ -17,6 +17,10 @@ // under the License. // +#nullable enable + +using System; + namespace OpenQA.Selenium { /// @@ -38,6 +42,7 @@ public interface ITargetLocator /// The name of the frame to select. /// An instance focused on the specified frame. /// If the frame cannot be found. + /// If is . IWebDriver Frame(string frameName); /// @@ -47,6 +52,8 @@ public interface ITargetLocator /// An instance focused on the specified frame. /// If the element is neither a FRAME nor an IFRAME element. /// If the element is no longer valid. + /// If is . + /// If cannot be converted to an . IWebDriver Frame(IWebElement frameElement); /// @@ -61,6 +68,7 @@ public interface ITargetLocator /// The name of the window to select. /// An instance focused on the given window. /// If the window cannot be found. + /// If is . IWebDriver Window(string windowName); /// diff --git a/dotnet/src/webdriver/Navigator.cs b/dotnet/src/webdriver/Navigator.cs index 9faf79f6aa3ac..44604094058a2 100644 --- a/dotnet/src/webdriver/Navigator.cs +++ b/dotnet/src/webdriver/Navigator.cs @@ -21,22 +21,25 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium { /// /// Provides a mechanism for Navigating with the driver. /// - internal class Navigator : INavigation + internal sealed class Navigator : INavigation { - private WebDriver driver; + private readonly WebDriver driver; /// /// Initializes a new instance of the class /// /// Driver in use + /// If is null. public Navigator(WebDriver driver) { - this.driver = driver; + this.driver = driver ?? throw new ArgumentNullException(nameof(driver)); } /// @@ -83,6 +86,7 @@ public async Task ForwardAsync() /// Navigate to a url. /// /// String of where you want the browser to go to + /// If is null. public void GoToUrl(string url) { Task.Run(async delegate @@ -96,6 +100,7 @@ public void GoToUrl(string url) /// /// String of where you want the browser to go. /// A task object representing the asynchronous operation. + /// If is null. public async Task GoToUrlAsync(string url) { if (url == null) @@ -114,6 +119,7 @@ public async Task GoToUrlAsync(string url) /// Navigate to a url. /// /// Uri object of where you want the browser to go. + /// If is null. public void GoToUrl(Uri url) { Task.Run(async delegate @@ -127,6 +133,7 @@ public void GoToUrl(Uri url) /// /// Uri object of where you want the browser to go. /// A task object representing the asynchronous operation. + /// If is null. public async Task GoToUrlAsync(Uri url) { if (url == null) diff --git a/dotnet/src/webdriver/TargetLocator.cs b/dotnet/src/webdriver/TargetLocator.cs index c93a783493b90..d8d57d933dcda 100644 --- a/dotnet/src/webdriver/TargetLocator.cs +++ b/dotnet/src/webdriver/TargetLocator.cs @@ -23,22 +23,25 @@ using System.Collections.ObjectModel; using System.Text.RegularExpressions; +#nullable enable + namespace OpenQA.Selenium { /// /// Provides a mechanism for finding elements on the page with locators. /// - internal class TargetLocator : ITargetLocator + internal sealed class TargetLocator : ITargetLocator { - private WebDriver driver; + private readonly WebDriver driver; /// /// Initializes a new instance of the class /// /// The driver that is currently in use + /// If is . public TargetLocator(WebDriver driver) { - this.driver = driver; + this.driver = driver ?? throw new ArgumentNullException(nameof(driver)); } /// @@ -59,6 +62,7 @@ public IWebDriver Frame(int frameIndex) /// /// name of the frame /// A WebDriver instance that is currently in use + /// If is . public IWebDriver Frame(string frameName) { if (frameName == null) @@ -85,6 +89,8 @@ public IWebDriver Frame(string frameName) /// /// a previously found FRAME or IFRAME element. /// A WebDriver instance that is currently in use. + /// If is . + /// If cannot be converted to an . public IWebDriver Frame(IWebElement frameElement) { if (frameElement == null) @@ -92,11 +98,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; - if (elementWrapper != null) + if (frameElement is IWrapsElement elementWrapper) { elementReference = elementWrapper.WrappedElement as IWebDriverObjectReference; } @@ -104,7 +109,7 @@ public IWebDriver Frame(IWebElement frameElement) if (elementReference == null) { - throw new ArgumentException("frameElement cannot be converted to IWebElementReference", nameof(frameElement)); + throw new ArgumentException($"{nameof(frameElement)} cannot be converted to {nameof(IWebDriverObjectReference)}", nameof(frameElement)); } Dictionary elementDictionary = elementReference.ToDictionary(); @@ -131,8 +136,14 @@ 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 . public IWebDriver Window(string windowHandleOrName) { + if (windowHandleOrName is null) + { + throw new ArgumentNullException(nameof(windowHandleOrName)); + } + Dictionary parameters = new Dictionary(); parameters.Add("handle", windowHandleOrName); try @@ -143,7 +154,7 @@ public IWebDriver Window(string windowHandleOrName) catch (NoSuchWindowException) { // simulate search by name - string original = null; + string? original = null; try { original = this.driver.CurrentWindowHandle; @@ -183,10 +194,13 @@ 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; } @@ -196,7 +210,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;