Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Add nullability to Manage() #15210

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dotnet/src/webdriver/INavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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.
/// </remarks>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
void GoToUrl(string url);

/// <summary>
/// Navigate to a url as an asynchronous task.
/// </summary>
/// <param name="url">String of where you want the browser to go.</param>
/// <returns>A task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
Task GoToUrlAsync(string url);

/// <summary>
Expand All @@ -90,15 +90,15 @@ 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.
/// </remarks>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
void GoToUrl(Uri url);

/// <summary>
/// Navigate to a url as an asynchronous task.
/// </summary>
/// <param name="url">Uri object of where you want the browser to go.</param>
/// <returns>A task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
Task GoToUrlAsync(Uri url);

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/IOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// under the License.
// </copyright>

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/ITimeouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using System;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/IWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using System.Drawing;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/webdriver/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task ForwardAsync()
/// Navigate to a url.
/// </summary>
/// <param name="url">String of where you want the browser to go to</param>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
public void GoToUrl(string url)
{
Task.Run(async delegate
Expand All @@ -100,7 +100,7 @@ public void GoToUrl(string url)
/// </summary>
/// <param name="url">String of where you want the browser to go.</param>
/// <returns>A task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
public async Task GoToUrlAsync(string url)
{
if (url == null)
Expand All @@ -119,7 +119,7 @@ public async Task GoToUrlAsync(string url)
/// Navigate to a url.
/// </summary>
/// <param name="url">Uri object of where you want the browser to go.</param>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
public void GoToUrl(Uri url)
{
Task.Run(async delegate
Expand All @@ -133,7 +133,7 @@ public void GoToUrl(Uri url)
/// </summary>
/// <param name="url">Uri object of where you want the browser to go.</param>
/// <returns>A task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is null.</exception>
/// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
public async Task GoToUrlAsync(Uri url)
{
if (url == null)
Expand Down
28 changes: 9 additions & 19 deletions dotnet/src/webdriver/OptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,42 @@
// under the License.
// </copyright>

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Provides a mechanism for setting options needed for the driver during the test.
/// </summary>
internal class OptionsManager : IOptions
internal sealed class OptionsManager : IOptions
{
private WebDriver driver;
private readonly WebDriver driver;

/// <summary>
/// Initializes a new instance of the <see cref="OptionsManager"/> class
/// </summary>
/// <param name="driver">Instance of the driver currently in use</param>
public OptionsManager(WebDriver driver)
{
this.driver = driver;
this.driver = driver ?? throw new System.ArgumentNullException(nameof(driver));
}

/// <summary>
/// Gets an object allowing the user to manipulate cookies on the page.
/// </summary>
public ICookieJar Cookies
{
get { return new CookieJar(this.driver); }
}
public ICookieJar Cookies => new CookieJar(this.driver);

/// <summary>
/// Gets an object allowing the user to manipulate the currently-focused browser window.
/// </summary>
/// <remarks>"Currently-focused" is defined as the browser window having the window handle
/// returned when IWebDriver.CurrentWindowHandle is called.</remarks>
public IWindow Window
{
get { return new Window(this.driver); }
}
public IWindow Window => new Window(this.driver);

/// <summary>
/// Gets an object allowing the user to examine the logs of the current driver instance.
/// </summary>
public ILogs Logs
{
get { return new Logs(this.driver); }
}
public ILogs Logs => new Logs(this.driver);

/// <summary>
/// Provides access to the timeouts defined for this driver.
Expand All @@ -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;
}
}
41 changes: 18 additions & 23 deletions dotnet/src/webdriver/Timeouts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Globalization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand All @@ -33,19 +35,19 @@ 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;

/// <summary>
/// Initializes a new instance of the <see cref="Timeouts"/> class
/// </summary>
/// <param name="driver">The driver that is currently in use</param>
public Timeouts(WebDriver driver)
{
this.driver = driver;
this.driver = driver ?? throw new ArgumentNullException(nameof(driver));
}

/// <summary>
Expand All @@ -70,8 +72,8 @@ public Timeouts(WebDriver driver)
/// </remarks>
public TimeSpan ImplicitWait
{
get { return this.ExecuteGetTimeout(ImplicitTimeoutName); }
set { this.ExecuteSetTimeout(ImplicitTimeoutName, value); }
get => this.ExecuteGetTimeout(ImplicitTimeoutName);
set => this.ExecuteSetTimeout(ImplicitTimeoutName, value);
}

/// <summary>
Expand All @@ -87,8 +89,8 @@ public TimeSpan ImplicitWait
/// </remarks>
public TimeSpan AsynchronousJavaScript
{
get { return this.ExecuteGetTimeout(AsyncScriptTimeoutName); }
set { this.ExecuteSetTimeout(AsyncScriptTimeoutName, value); }
get => this.ExecuteGetTimeout(AsyncScriptTimeoutName);
set => this.ExecuteSetTimeout(AsyncScriptTimeoutName, value);
}

/// <summary>
Expand All @@ -103,29 +105,21 @@ public TimeSpan AsynchronousJavaScript
/// </remarks>
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<string, object> responseValue = (Dictionary<string, object>)commandResponse.Value;
if (!responseValue.ContainsKey(timeoutType))

Dictionary<string, object?> responseValue = (Dictionary<string, object?>)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)
Expand All @@ -149,6 +143,7 @@ private void ExecuteSetTimeout(string timeoutType, TimeSpan timeToWait)

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add(timeoutType, Convert.ToInt64(milliseconds));

this.driver.InternalExecute(DriverCommand.SetTimeouts, parameters);
}
}
Expand Down
28 changes: 14 additions & 14 deletions dotnet/src/webdriver/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
using System.Drawing;
using System.Globalization;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Defines the interface through which the user can manipulate the browser window.
/// </summary>
internal class Window : IWindow
internal sealed class Window : IWindow
{
private WebDriver driver;

Expand All @@ -37,7 +39,7 @@ internal class Window : IWindow
/// <param name="driver">Instance of the driver currently in use</param>
public Window(WebDriver driver)
{
this.driver = driver;
this.driver = driver ?? throw new ArgumentNullException(nameof(driver));
}

/// <summary>
Expand All @@ -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<string, object> rawPosition = (Dictionary<string, object>)commandResponse.Value;
Dictionary<string, object?> rawPosition = (Dictionary<string, object?>)commandResponse.Value!;
int x = Convert.ToInt32(rawPosition["x"], CultureInfo.InvariantCulture);
int y = Convert.ToInt32(rawPosition["y"], CultureInfo.InvariantCulture);

return new Point(x, y);
}

Expand All @@ -74,11 +76,12 @@ public Size Size
{
get
{
Response commandResponse;
commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);
Dictionary<string, object> rawPosition = (Dictionary<string, object>)commandResponse.Value;
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetWindowRect, null);

Dictionary<string, object?> rawPosition = (Dictionary<string, object?>)commandResponse.Value!;
int height = Convert.ToInt32(rawPosition["height"], CultureInfo.InvariantCulture);
int width = Convert.ToInt32(rawPosition["width"], CultureInfo.InvariantCulture);

return new Size(width, height);
}

Expand All @@ -96,26 +99,23 @@ public Size Size
/// </summary>
public void Maximize()
{
Dictionary<string, object> parameters = null;
this.driver.InternalExecute(DriverCommand.MaximizeWindow, parameters);
this.driver.InternalExecute(DriverCommand.MaximizeWindow, null);
}

/// <summary>
/// Minimizes the current window if it is not already minimized.
/// </summary>
public void Minimize()
{
Dictionary<string, object> parameters = null;
this.driver.InternalExecute(DriverCommand.MinimizeWindow, parameters);
this.driver.InternalExecute(DriverCommand.MinimizeWindow, null);
}

/// <summary>
/// Sets the current window to full screen if it is not already in that state.
/// </summary>
public void FullScreen()
{
Dictionary<string, object> parameters = null;
this.driver.InternalExecute(DriverCommand.FullScreenWindow, parameters);
this.driver.InternalExecute(DriverCommand.FullScreenWindow, null);
}
}
}