Skip to content

Commit

Permalink
[dotnet] Add nullability to Alerts (#14669)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenderMichael authored Dec 11, 2024
1 parent 0174bce commit 6442f61
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
11 changes: 7 additions & 4 deletions dotnet/src/webdriver/Alert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}

Expand All @@ -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.");
}
Expand Down
6 changes: 2 additions & 4 deletions dotnet/src/webdriver/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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>
Expand Down
7 changes: 6 additions & 1 deletion dotnet/src/webdriver/IAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
// under the License.
// </copyright>

using System;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
Expand All @@ -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.
Expand All @@ -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);
}
}

0 comments on commit 6442f61

Please sign in to comment.