Skip to content

Commit

Permalink
[dotnet] Start adding nullable reference type annotations to the `Sup…
Browse files Browse the repository at this point in the history
…port` package (#14779)

* [dotnet] All nullable reference type annotations to support (part 1)

* minimize diffs

* Add exception XMLDoc to `PopupWindowFinder`

* Make some updates to `SelectElement`

* [dotnet] Update bazel build to recognize Support as nullable-annotated and langversion

* fix `nullable` variable name
  • Loading branch information
RenderMichael authored Jan 15, 2025
1 parent cc814a8 commit fc463fd
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 287 deletions.
4 changes: 4 additions & 0 deletions dotnet/src/support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ csharp_library(
"UI/*.cs",
]) + [":assembly-info"],
out = "WebDriver.Support",
langversion = "12.0",
nullable = "annotations",
target_frameworks = [
"netstandard2.0",
],
Expand Down Expand Up @@ -74,6 +76,8 @@ csharp_library(
]) + [":assembly-info"],
out = "WebDriver.Support.StrongNamed",
keyfile = "//dotnet:WebDriver.snk",
langversion = "12.0",
nullable = "annotations",
target_frameworks = [
"netstandard2.0",
],
Expand Down
35 changes: 12 additions & 23 deletions dotnet/src/support/Events/FindElementEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ namespace OpenQA.Selenium.Support.Events
/// </summary>
public class FindElementEventArgs : EventArgs
{
private IWebDriver driver;
private IWebElement element;
private By method;

/// <summary>
/// Initializes a new instance of the <see cref="FindElementEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance used in finding elements.</param>
/// <param name="method">The <see cref="By"/> object containing the method used to find elements</param>
/// <param name="method">The <see cref="By"/> object containing the method used to find elements.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="method"/> are <see langword="null"/>.</exception>
public FindElementEventArgs(IWebDriver driver, By method)
: this(driver, null, method)
{
Expand All @@ -44,37 +41,29 @@ public FindElementEventArgs(IWebDriver driver, By method)
/// Initializes a new instance of the <see cref="FindElementEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance used in finding elements.</param>
/// <param name="element">The parent element used as the context for the search.</param>
/// <param name="element">The parent element used as the context for the search, or <see langword="null"/> if none exists.</param>
/// <param name="method">The <see cref="By"/> object containing the method used to find elements.</param>
public FindElementEventArgs(IWebDriver driver, IWebElement element, By method)
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="method"/> are <see langword="null"/>.</exception>
public FindElementEventArgs(IWebDriver driver, IWebElement? element, By method)
{
this.driver = driver;
this.element = element;
this.method = method;
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
this.Element = element;
this.FindMethod = method ?? throw new ArgumentNullException(nameof(method));
}

/// <summary>
/// Gets the WebDriver instance used in finding elements.
/// </summary>
public IWebDriver Driver
{
get { return this.driver; }
}
public IWebDriver Driver { get; }

/// <summary>
/// Gets the parent element used as the context for the search.
/// Gets the parent element used as the context for the search, or <see langword="null"/> if no element is associated.
/// </summary>
public IWebElement Element
{
get { return this.element; }
}
public IWebElement? Element { get; }

/// <summary>
/// Gets the <see cref="By"/> object containing the method used to find elements.
/// </summary>
public By FindMethod
{
get { return this.method; }
}
public By FindMethod { get; }
}
}
18 changes: 5 additions & 13 deletions dotnet/src/support/Events/GetShadowRootEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
/// </summary>
public class GetShadowRootEventArgs : EventArgs
{
private IWebDriver driver;
private ISearchContext searchContext;

/// <summary>
/// Initializes a new instance of the <see cref="GetShadowRootEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance used in the current context.</param>
/// <param name="searchContext">The parent searc context used as the context for getting shadow root.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="searchContext"/> are <see langword="null"/>.</exception>
public GetShadowRootEventArgs(IWebDriver driver, ISearchContext searchContext)
{
this.driver = driver;
this.searchContext = searchContext;
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
this.SearchContext = searchContext ?? throw new ArgumentNullException(nameof(searchContext));
}

/// <summary>
/// Gets the WebDriver instance used in the current context.
/// </summary>
public IWebDriver Driver
{
get { return this.driver; }
}
public IWebDriver Driver { get; }

/// <summary>
/// Gets the parent search context used as the context for getting shadow root.
/// </summary>
public ISearchContext SearchContext
{
get { return this.searchContext; }
}
public ISearchContext SearchContext { get; }
}
}
20 changes: 6 additions & 14 deletions dotnet/src/support/Events/WebDriverExceptionEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
/// </summary>
public class WebDriverExceptionEventArgs : EventArgs
{
private Exception thrownException;
private IWebDriver driver;

/// <summary>
/// Initializes a new instance of the <see cref="WebDriverExceptionEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance throwing the exception.</param>
/// <param name="thrownException">The exception thrown by the driver.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="thrownException"/> are <see langword="null"/>.</exception>
public WebDriverExceptionEventArgs(IWebDriver driver, Exception thrownException)
{
this.driver = driver;
this.thrownException = thrownException;
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
this.ThrownException = thrownException ?? throw new ArgumentNullException(nameof(thrownException));
}

/// <summary>
/// Gets the exception thrown by the driver.
/// </summary>
public Exception ThrownException
{
get { return this.thrownException; }
}
public Exception ThrownException { get; }

/// <summary>
/// Gets the WebDriver instance .
/// Gets the WebDriver instance.
/// </summary>
public IWebDriver Driver
{
get { return this.driver; }
}
public IWebDriver Driver { get; }
}
}
25 changes: 9 additions & 16 deletions dotnet/src/support/Events/WebDriverNavigationEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ namespace OpenQA.Selenium.Support.Events
/// </summary>
public class WebDriverNavigationEventArgs : EventArgs
{
private string url;
private IWebDriver driver;

/// <summary>
/// Initializes a new instance of the <see cref="WebDriverNavigationEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance used in navigation.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> is <see langword="null"/>.</exception>
public WebDriverNavigationEventArgs(IWebDriver driver)
: this(driver, null)
{
Expand All @@ -42,27 +40,22 @@ public WebDriverNavigationEventArgs(IWebDriver driver)
/// Initializes a new instance of the <see cref="WebDriverNavigationEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance used in navigation.</param>
/// <param name="url">The URL navigated to by the driver.</param>
public WebDriverNavigationEventArgs(IWebDriver driver, string url)
/// <param name="url">The URL navigated to by the driver, or <see langword="null"/> if none exists.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> is <see langword="null"/>.</exception>
public WebDriverNavigationEventArgs(IWebDriver driver, string? url)
{
this.url = url;
this.driver = driver;
this.Url = url;
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
}

/// <summary>
/// Gets the URL navigated to by the driver.
/// Gets the URL navigated to by the driver, or <see langword="null"/> if no URL could be determined.
/// </summary>
public string Url
{
get { return this.url; }
}
public string? Url { get; }

/// <summary>
/// Gets the WebDriver instance used in navigation.
/// </summary>
public IWebDriver Driver
{
get { return this.driver; }
}
public IWebDriver Driver { get; }
}
}
18 changes: 5 additions & 13 deletions dotnet/src/support/Events/WebDriverScriptEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
/// </summary>
public class WebDriverScriptEventArgs : EventArgs
{
private IWebDriver driver;
private string script;

/// <summary>
/// Initializes a new instance of the <see cref="WebDriverScriptEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance used to execute the script.</param>
/// <param name="script">The script executed by the driver.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="script"/> are <see langword="null"/>.</exception>
public WebDriverScriptEventArgs(IWebDriver driver, string script)
{
this.driver = driver;
this.script = script;
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
this.Script = script ?? throw new ArgumentNullException(nameof(script));
}

/// <summary>
/// Gets the WebDriver instance used to execute the script.
/// </summary>
public IWebDriver Driver
{
get { return this.driver; }
}
public IWebDriver Driver { get; }

/// <summary>
/// Gets the script executed by the driver.
/// </summary>
public string Script
{
get { return this.script; }
}
public string Script { get; }
}
}
18 changes: 5 additions & 13 deletions dotnet/src/support/Events/WebElementEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,26 @@ namespace OpenQA.Selenium.Support.Events
/// </summary>
public class WebElementEventArgs : EventArgs
{
private IWebDriver driver;
private IWebElement element;

/// <summary>
/// Initializes a new instance of the <see cref="WebElementEventArgs"/> class.
/// </summary>
/// <param name="driver">The WebDriver instance used for the action.</param>
/// <param name="element">The element used for the action.</param>
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="element"/> are <see langword="null"/>.</exception>
public WebElementEventArgs(IWebDriver driver, IWebElement element)
{
this.driver = driver;
this.element = element;
this.Driver = driver ?? throw new ArgumentNullException(nameof(driver));
this.Element = element ?? throw new ArgumentNullException(nameof(element));
}

/// <summary>
/// Gets the WebDriver instance used for the action.
/// </summary>
public IWebDriver Driver
{
get { return this.driver; }
}
public IWebDriver Driver { get; }

/// <summary>
/// Gets the element used for the action.
/// </summary>
public IWebElement Element
{
get { return this.element; }
}
public IWebElement Element { get; }
}
}
9 changes: 6 additions & 3 deletions dotnet/src/support/Events/WebElementValueEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// under the License.
// </copyright>

using System;

namespace OpenQA.Selenium.Support.Events
{
/// <summary>
Expand All @@ -30,15 +32,16 @@ public class WebElementValueEventArgs : WebElementEventArgs
/// <param name="driver">The WebDriver instance used for the action.</param>
/// <param name="element">The element used for the action.</param>
/// <param name="value">The new value for the element.</param>
public WebElementValueEventArgs(IWebDriver driver, IWebElement element, string value)
/// <exception cref="ArgumentNullException">If <paramref name="driver"/> or <paramref name="element"/> are <see langword="null"/>.</exception>
public WebElementValueEventArgs(IWebDriver driver, IWebElement element, string? value)
: base(driver, element)
{
this.Value = value;
}

/// <summary>
/// Gets the Value that is written to the element
/// Gets the Value that is written to the element.
/// </summary>
public string Value { get; private set; }
public string? Value { get; }
}
}
Loading

0 comments on commit fc463fd

Please sign in to comment.