diff --git a/dotnet/src/webdriver/INavigation.cs b/dotnet/src/webdriver/INavigation.cs index a7cb84db9544f..5fd4e19e1cd58 100644 --- a/dotnet/src/webdriver/INavigation.cs +++ b/dotnet/src/webdriver/INavigation.cs @@ -66,7 +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. + /// If is . void GoToUrl(string url); /// @@ -74,7 +74,7 @@ public interface INavigation /// /// String of where you want the browser to go. /// A task object representing the asynchronous operation. - /// If is null. + /// If is . Task GoToUrlAsync(string url); /// @@ -90,7 +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. + /// If is . void GoToUrl(Uri url); /// @@ -98,7 +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. + /// If is . Task GoToUrlAsync(Uri url); /// diff --git a/dotnet/src/webdriver/IOptions.cs b/dotnet/src/webdriver/IOptions.cs index 78fd14514ba37..6c704000879e2 100644 --- a/dotnet/src/webdriver/IOptions.cs +++ b/dotnet/src/webdriver/IOptions.cs @@ -17,6 +17,8 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/ITimeouts.cs b/dotnet/src/webdriver/ITimeouts.cs index 2e39ace5227f4..a0a4594e6088e 100644 --- a/dotnet/src/webdriver/ITimeouts.cs +++ b/dotnet/src/webdriver/ITimeouts.cs @@ -19,6 +19,8 @@ using System; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/IWindow.cs b/dotnet/src/webdriver/IWindow.cs index c09ddd7341b22..e5202ed629319 100644 --- a/dotnet/src/webdriver/IWindow.cs +++ b/dotnet/src/webdriver/IWindow.cs @@ -19,6 +19,8 @@ using System.Drawing; +#nullable enable + namespace OpenQA.Selenium { /// diff --git a/dotnet/src/webdriver/Navigator.cs b/dotnet/src/webdriver/Navigator.cs index 44604094058a2..4e50ec8ee8d29 100644 --- a/dotnet/src/webdriver/Navigator.cs +++ b/dotnet/src/webdriver/Navigator.cs @@ -86,7 +86,7 @@ public async Task ForwardAsync() /// Navigate to a url. /// /// String of where you want the browser to go to - /// If is null. + /// If is . public void GoToUrl(string url) { Task.Run(async delegate @@ -100,7 +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. + /// If is . public async Task GoToUrlAsync(string url) { if (url == null) @@ -119,7 +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. + /// If is . public void GoToUrl(Uri url) { Task.Run(async delegate @@ -133,7 +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. + /// If is . public async Task GoToUrlAsync(Uri url) { if (url == null) diff --git a/dotnet/src/webdriver/OptionsManager.cs b/dotnet/src/webdriver/OptionsManager.cs index 4fc01194dc1c5..b7c4b85c1adb0 100644 --- a/dotnet/src/webdriver/OptionsManager.cs +++ b/dotnet/src/webdriver/OptionsManager.cs @@ -17,14 +17,16 @@ // under the License. // +#nullable enable + namespace OpenQA.Selenium { /// /// Provides a mechanism for setting options needed for the driver during the test. /// - internal class OptionsManager : IOptions + internal sealed class OptionsManager : IOptions { - private WebDriver driver; + private readonly WebDriver driver; /// /// Initializes a new instance of the class @@ -32,34 +34,25 @@ internal class OptionsManager : IOptions /// Instance of the driver currently in use public OptionsManager(WebDriver driver) { - this.driver = driver; + this.driver = driver ?? throw new System.ArgumentNullException(nameof(driver)); } /// /// Gets an object allowing the user to manipulate cookies on the page. /// - public ICookieJar Cookies - { - get { return new CookieJar(this.driver); } - } + public ICookieJar Cookies => new CookieJar(this.driver); /// /// Gets an object allowing the user to manipulate the currently-focused browser window. /// /// "Currently-focused" is defined as the browser window having the window handle /// returned when IWebDriver.CurrentWindowHandle is called. - public IWindow Window - { - get { return new Window(this.driver); } - } + public IWindow Window => new Window(this.driver); /// /// Gets an object allowing the user to examine the logs of the current driver instance. /// - public ILogs Logs - { - get { return new Logs(this.driver); } - } + public ILogs Logs => new Logs(this.driver); /// /// Provides access to the timeouts defined for this driver. @@ -70,9 +63,6 @@ public ITimeouts Timeouts() return new Timeouts(this.driver); } - public INetwork Network - { - get { return this.driver.Network; } - } + public INetwork Network => this.driver.Network; } } diff --git a/dotnet/src/webdriver/Timeouts.cs b/dotnet/src/webdriver/Timeouts.cs index 63422d21db6f9..b0f5882a7642d 100644 --- a/dotnet/src/webdriver/Timeouts.cs +++ b/dotnet/src/webdriver/Timeouts.cs @@ -21,6 +21,8 @@ using System.Collections.Generic; using System.Globalization; +#nullable enable + namespace OpenQA.Selenium { /// @@ -33,11 +35,11 @@ internal class Timeouts : ITimeouts private const string PageLoadTimeoutName = "pageLoad"; private const string LegacyPageLoadTimeoutName = "page load"; - private readonly TimeSpan DefaultImplicitWaitTimeout = TimeSpan.FromSeconds(0); - private readonly TimeSpan DefaultAsyncScriptTimeout = TimeSpan.FromSeconds(30); - private readonly TimeSpan DefaultPageLoadTimeout = TimeSpan.FromSeconds(300); + private static readonly TimeSpan DefaultImplicitWaitTimeout = TimeSpan.FromSeconds(0); + private static readonly TimeSpan DefaultAsyncScriptTimeout = TimeSpan.FromSeconds(30); + private static readonly TimeSpan DefaultPageLoadTimeout = TimeSpan.FromSeconds(300); - private WebDriver driver; + private readonly WebDriver driver; /// /// Initializes a new instance of the class @@ -45,7 +47,7 @@ internal class Timeouts : ITimeouts /// The driver that is currently in use public Timeouts(WebDriver driver) { - this.driver = driver; + this.driver = driver ?? throw new ArgumentNullException(nameof(driver)); } /// @@ -70,8 +72,8 @@ public Timeouts(WebDriver driver) /// public TimeSpan ImplicitWait { - get { return this.ExecuteGetTimeout(ImplicitTimeoutName); } - set { this.ExecuteSetTimeout(ImplicitTimeoutName, value); } + get => this.ExecuteGetTimeout(ImplicitTimeoutName); + set => this.ExecuteSetTimeout(ImplicitTimeoutName, value); } /// @@ -87,8 +89,8 @@ public TimeSpan ImplicitWait /// public TimeSpan AsynchronousJavaScript { - get { return this.ExecuteGetTimeout(AsyncScriptTimeoutName); } - set { this.ExecuteSetTimeout(AsyncScriptTimeoutName, value); } + get => this.ExecuteGetTimeout(AsyncScriptTimeoutName); + set => this.ExecuteSetTimeout(AsyncScriptTimeoutName, value); } /// @@ -103,29 +105,21 @@ public TimeSpan AsynchronousJavaScript /// public TimeSpan PageLoad { - get - { - string timeoutName = PageLoadTimeoutName; - return this.ExecuteGetTimeout(timeoutName); - } - - set - { - string timeoutName = PageLoadTimeoutName; - this.ExecuteSetTimeout(timeoutName, value); - } + get => this.ExecuteGetTimeout(PageLoadTimeoutName); + set => this.ExecuteSetTimeout(PageLoadTimeoutName, value); } private TimeSpan ExecuteGetTimeout(string timeoutType) { Response commandResponse = this.driver.InternalExecute(DriverCommand.GetTimeouts, null); - Dictionary responseValue = (Dictionary)commandResponse.Value; - if (!responseValue.ContainsKey(timeoutType)) + + Dictionary responseValue = (Dictionary)commandResponse.Value!; + if (!responseValue.TryGetValue(timeoutType, out object? timeout)) { throw new WebDriverException("Specified timeout type not defined"); } - return TimeSpan.FromMilliseconds(Convert.ToDouble(responseValue[timeoutType], CultureInfo.InvariantCulture)); + return TimeSpan.FromMilliseconds(Convert.ToDouble(timeout, CultureInfo.InvariantCulture)); } private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait) @@ -149,6 +143,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait) Dictionary parameters = new Dictionary(); parameters.Add(timeoutType, Convert.ToInt64(milliseconds)); + this.driver.InternalExecute(DriverCommand.SetTimeouts, parameters); } } diff --git a/dotnet/src/webdriver/Window.cs b/dotnet/src/webdriver/Window.cs index 6283f1ba3ef77..c856306bb668b 100644 --- a/dotnet/src/webdriver/Window.cs +++ b/dotnet/src/webdriver/Window.cs @@ -22,12 +22,14 @@ using System.Drawing; using System.Globalization; +#nullable enable + namespace OpenQA.Selenium { /// /// Defines the interface through which the user can manipulate the browser window. /// - internal class Window : IWindow + internal sealed class Window : IWindow { private WebDriver driver; @@ -37,7 +39,7 @@ internal class Window : IWindow /// Instance of the driver currently in use public Window(WebDriver driver) { - this.driver = driver; + this.driver = driver ?? throw new ArgumentNullException(nameof(driver)); } /// @@ -48,12 +50,12 @@ public Point Position { get { - Response commandResponse; - commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null); + Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null); - Dictionary rawPosition = (Dictionary)commandResponse.Value; + Dictionary rawPosition = (Dictionary)commandResponse.Value!; int x = Convert.ToInt32(rawPosition["x"], CultureInfo.InvariantCulture); int y = Convert.ToInt32(rawPosition["y"], CultureInfo.InvariantCulture); + return new Point(x, y); } @@ -74,11 +76,12 @@ public Size Size { get { - Response commandResponse; - commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null); - Dictionary rawPosition = (Dictionary)commandResponse.Value; + Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null); + + Dictionary rawPosition = (Dictionary)commandResponse.Value!; int height = Convert.ToInt32(rawPosition["height"], CultureInfo.InvariantCulture); int width = Convert.ToInt32(rawPosition["width"], CultureInfo.InvariantCulture); + return new Size(width, height); } @@ -96,8 +99,7 @@ public Size Size /// public void Maximize() { - Dictionary parameters = null; - this.driver.InternalExecute(DriverCommand.MaximizeWindow, parameters); + this.driver.InternalExecute(DriverCommand.MaximizeWindow, null); } /// @@ -105,8 +107,7 @@ public void Maximize() /// public void Minimize() { - Dictionary parameters = null; - this.driver.InternalExecute(DriverCommand.MinimizeWindow, parameters); + this.driver.InternalExecute(DriverCommand.MinimizeWindow, null); } /// @@ -114,8 +115,7 @@ public void Minimize() /// public void FullScreen() { - Dictionary parameters = null; - this.driver.InternalExecute(DriverCommand.FullScreenWindow, parameters); + this.driver.InternalExecute(DriverCommand.FullScreenWindow, null); } } }