Skip to content

[dotnet] Add nullability to Alerts #14669

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

Merged
merged 19 commits into from
Dec 11, 2024
Merged
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
11 changes: 7 additions & 4 deletions dotnet/src/webdriver/Alert.cs
Original file line number Diff line number Diff line change
@@ -20,14 +20,16 @@
using System;
using System.Collections.Generic;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Defines the interface through which the user can manipulate JavaScript alerts.
/// </summary>
internal class Alert : IAlert
{
private WebDriver driver;
private readonly WebDriver driver;

/// <summary>
/// Initializes a new instance of the <see cref="Alert"/> class.
@@ -41,12 +43,12 @@ public Alert(WebDriver driver)
/// <summary>
/// Gets the text of the alert.
/// </summary>
public string Text
public string? Text
{
get
{
Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAlertText, null);
return commandResponse.Value.ToString();
return (string?)commandResponse.Value;
}
}

@@ -70,9 +72,10 @@ public void Accept()
/// Sends keys to the alert.
/// </summary>
/// <param name="keysToSend">The keystrokes to send.</param>
/// <exception cref="ArgumentNullException">If <paramref name="keysToSend" /> is <see langword="null"/>.</exception>
public void SendKeys(string keysToSend)
{
if (keysToSend == null)
if (keysToSend is null)
{
throw new ArgumentNullException(nameof(keysToSend), "Keys to send must not be null.");
}
6 changes: 2 additions & 4 deletions dotnet/src/webdriver/Cookie.cs
Original file line number Diff line number Diff line change
@@ -351,14 +351,12 @@ public override string ToString()
public override bool Equals(object obj)
{
// Two cookies are equal if the name and value match
Cookie cookie = obj as Cookie;

if (this == obj)
{
return true;
}

if (cookie == null)
if (obj is not Cookie cookie)
{
return false;
}
@@ -368,7 +366,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);
}

/// <summary>
7 changes: 6 additions & 1 deletion dotnet/src/webdriver/IAlert.cs
Original file line number Diff line number Diff line change
@@ -17,6 +17,10 @@
// under the License.
// </copyright>

using System;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
@@ -27,7 +31,7 @@ public interface IAlert
/// <summary>
/// Gets the text of the alert.
/// </summary>
string Text { get; }
string? Text { get; }

/// <summary>
/// Dismisses the alert.
@@ -43,6 +47,7 @@ public interface IAlert
/// Sends keys to the alert.
/// </summary>
/// <param name="keysToSend">The keystrokes to send.</param>
/// <exception cref="ArgumentNullException">If <paramref name="keysToSend"/> is <see langword="null"/>.</exception>
void SendKeys(string keysToSend);
}
}