Skip to content
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
45 changes: 27 additions & 18 deletions dotnet/src/support/Events/EventFiringWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ public TimeSpan PageLoad
/// <summary>
/// EventFiringWebElement allows you to have access to specific items that are found on the page
/// </summary>
private class EventFiringWebElement : ITakesScreenshot, IWebElement, IWrapsElement, IWrapsDriver
private class EventFiringWebElement : ITakesScreenshot, IWebElement, IWrapsElement, IWrapsDriver, IEquatable<IWebElement>
{
private readonly EventFiringWebDriver parentDriver;

Expand Down Expand Up @@ -1761,17 +1761,22 @@ public Screenshot GetScreenshot()
}

/// <summary>
/// Determines whether the specified <see cref="EventFiringWebElement"/> is equal to the current <see cref="EventFiringWebElement"/>.
/// Determines whether the specified <see cref="object"/> is equal to the current <see cref="EventFiringWebElement"/>.
/// </summary>
/// <param name="obj">The <see cref="EventFiringWebElement"/> to compare to the current <see cref="EventFiringWebElement"/>.</param>
/// <returns><see langword="true"/> if the specified <see cref="EventFiringWebElement"/> is equal to the current <see cref="EventFiringWebElement"/>; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object obj)
/// <param name="obj">The <see cref="object"/> to compare to the current <see cref="EventFiringWebElement"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="EventFiringWebElement"/> is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
if (obj is not IWebElement other)
{
return false;
}
return Equals(obj as IWebElement);
}

/// <summary>
/// Indicates whether the current <see cref="EventFiringWebElement"/> is equal to another <see cref="IWebElement"/>.
/// </summary>
/// <param name="other">An <see cref="IWebElement"/> to compare with this <see cref="EventFiringWebElement"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="EventFiringWebElement"/> is equal to the <paramref name="other"/> parameter; otherwise, <see langword="false"/>.</returns>
public bool Equals(IWebElement? other)
{
if (other is IWrapsElement otherWrapper)
{
other = otherWrapper.WrappedElement;
Expand All @@ -1793,7 +1798,7 @@ public override int GetHashCode()
/// <summary>
/// EventFiringShadowElement allows you to have access to specific shadow elements
/// </summary>
private class EventFiringShadowRoot : ISearchContext, IWrapsDriver
private class EventFiringShadowRoot : ISearchContext, IWrapsDriver, IEquatable<ISearchContext>
{
private readonly EventFiringWebDriver parentDriver;

Expand Down Expand Up @@ -1871,21 +1876,25 @@ public ReadOnlyCollection<IWebElement> FindElements(By by)
this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex));
throw;
}
}

/// <summary>
/// Determines whether the specified <see cref="object"/> is equal to the current <see cref="EventFiringShadowRoot"/>.
/// </summary>
/// <param name="obj">The <see cref="object"/> to compare to the current <see cref="EventFiringShadowRoot"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="EventFiringShadowRoot"/> is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
return Equals(obj as ISearchContext);
}

/// <summary>
/// Determines whether the specified <see cref="EventFiringShadowRoot"/> is equal to the current <see cref="EventFiringShadowRoot"/>.
/// </summary>
/// <param name="obj">The <see cref="EventFiringWebElement"/> to compare to the current <see cref="EventFiringShadowRoot"/>.</param>
/// <returns><see langword="true"/> if the specified <see cref="EventFiringShadowRoot"/> is equal to the current <see cref="EventFiringShadowRoot"/>; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object obj)
/// <param name="other">The <see cref="ISearchContext"/> to compare to the current <see cref="EventFiringShadowRoot"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="EventFiringShadowRoot"/> is equal to the <paramref name="other"/> parameter; otherwise, <see langword="false"/>.</returns>
public bool Equals(ISearchContext? other)
{
if (obj is not ISearchContext other)
{
return false;
}

return WrappedSearchContext.Equals(other);
}

Expand Down
36 changes: 24 additions & 12 deletions dotnet/src/webdriver/Cookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace OpenQA.Selenium;
/// Represents a cookie in the browser.
/// </summary>
[Serializable]
public class Cookie
public class Cookie : IEquatable<Cookie>
{
private readonly string cookieName;
private readonly string cookieValue;
Expand Down Expand Up @@ -330,32 +330,44 @@ public override string ToString()
/// <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
// Two cookies are equal if the name and value match
if (this == obj)
{
return true;
}
return Equals(obj as Cookie);
}

if (obj is not Cookie cookie)
/// <summary>
/// Indicates whether the current <see cref="Cookie"/> is equal to another <see cref="Cookie"/>.
/// </summary>
/// <param name="other">A <see cref="Cookie"/> to compare with this <see cref="Cookie"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="Cookie"/> is equal to the <paramref name="other"/> parameter; otherwise, <see langword="false"/>.</returns>
/// <remarks>Two cookies are equal if the <see cref="Name"/> and <see cref="Value"/> match.</remarks>
public bool Equals(Cookie? other)
{
if (other is null)
{
return false;
}

if (!this.cookieName.Equals(cookie.cookieName))
if (ReferenceEquals(this, other))
{
return false;
return true;
}

return string.Equals(this.cookieValue, cookie.cookieValue);
return string.Equals(this.cookieName, other.cookieName)
&& string.Equals(this.cookieValue, other.cookieValue);
}

/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>A hash code for the current <see cref="object">Object</see>.</returns>
/// <returns>A hash code for the current <see cref="Cookie" />, based on the <see cref="Name"/> and <see cref="Value"/>.</returns>
public override int GetHashCode()
{
return this.cookieName.GetHashCode();
unchecked
{
int hash = 17;
hash = hash * 23 + this.cookieName.GetHashCode();
hash = hash * 23 + (this.cookieValue?.GetHashCode() ?? 0);
return hash;
}
}

private static string? StripPort(string? domain)
Expand Down
14 changes: 12 additions & 2 deletions dotnet/src/webdriver/InitializationScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace OpenQA.Selenium;
/// <summary>
/// Represents a JavaScript script that is loaded and run on every document load.
/// </summary>
public class InitializationScript
public class InitializationScript : IEquatable<InitializationScript>
{
internal InitializationScript(string scriptId, string scriptName, string scriptSource)
{
Expand Down Expand Up @@ -59,7 +59,17 @@ internal InitializationScript(string scriptId, string scriptName, string scriptS
/// <returns><see langword="true"/> if the current <see cref="InitializationScript"/> is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
return obj is InitializationScript other && this.ScriptId == other.ScriptId && this.ScriptName == other.ScriptName && this.ScriptSource == other.ScriptSource;
return Equals(obj as InitializationScript);
}

/// <summary>
/// Indicates whether the current <see cref="InitializationScript"/> is equal to another <see cref="InitializationScript"/> of the same type.
/// </summary>
/// <param name="other">An <see cref="InitializationScript"/> to compare with this <see cref="InitializationScript"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="InitializationScript"/> is equal to the <paramref name="other"/> parameter; otherwise, <see langword="false"/>.</returns>
public bool Equals(InitializationScript? other)
{
return other is not null && this.ScriptId == other.ScriptId && this.ScriptName == other.ScriptName && this.ScriptSource == other.ScriptSource;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Internal/Logging/ILogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface ILogContext : IDisposable
/// </summary>
/// <param name="logger">The specified logger instance to be checked.</param>
/// <param name="level">The specified log event level to be checked.</param>
/// <returns><c>true</c> if log messages emitting is enabled for the specified logger and log event level, otherwise <c>false</c>.</returns>
/// <returns><see langword="true"/> if log messages emitting is enabled for the specified logger and log event level, otherwise <see langword="false"/>.</returns>
internal bool IsEnabled(ILogger logger, LogEventLevel level);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Internal/Logging/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ internal interface ILogger
/// Checks whether logs emitting is enabled for this logger and a log event level.
/// </summary>
/// <param name="level">The specified log event level to be checked.</param>
/// <returns><c>true</c> if log messages emitting is enabled for the specified log event level, otherwise <c>false</c>.</returns>
/// <returns><see langword="true"/> if log messages emitting is enabled for the specified log event level, otherwise <see langword="false"/>.</returns>
bool IsEnabled(LogEventLevel level);
}
36 changes: 23 additions & 13 deletions dotnet/src/webdriver/Remote/DesiredCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace OpenQA.Selenium.Remote;
/// <summary>
/// Internal class to specify the requested capabilities of the browser for <see cref="IWebDriver"/>.
/// </summary>
internal class DesiredCapabilities : IWritableCapabilities, IHasCapabilitiesDictionary
internal class DesiredCapabilities : IWritableCapabilities, IHasCapabilitiesDictionary, IEquatable<DesiredCapabilities>
{
private readonly Dictionary<string, object> capabilities = new Dictionary<string, object>();

Expand Down Expand Up @@ -229,9 +229,9 @@ public void SetCapability(string capability, object capabilityValue)
public override int GetHashCode()
{
int result;
result = this.BrowserName != null ? this.BrowserName.GetHashCode() : 0;
result = (31 * result) + (this.Version != null ? this.Version.GetHashCode() : 0);
result = (31 * result) + (this.Platform != null ? this.Platform.GetHashCode() : 0);
result = this.BrowserName?.GetHashCode() ?? 0;
result = (31 * result) + (this.Version?.GetHashCode() ?? 0);
result = (31 * result) + (this.Platform?.GetHashCode() ?? 0);
return result;
}

Expand All @@ -245,23 +245,33 @@ public override string ToString()
}

/// <summary>
/// Compare two DesiredCapabilities and will return either true or false
/// Indicates whether the current <see cref="DesiredCapabilities"/> is equal to another <see cref="object"/>.
/// </summary>
/// <param name="obj">DesiredCapabilities you wish to compare</param>
/// <returns>true if they are the same or false if they are not</returns>
/// <param name="obj">An object to compare with this <see cref="DesiredCapabilities"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="DesiredCapabilities"/> is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
if (this == obj)
return Equals(obj as DesiredCapabilities);
}

/// <summary>
/// Indicates whether the current <see cref="DesiredCapabilities"/> is equal to another <see cref="DesiredCapabilities"/>.
/// </summary>
/// <param name="other">An <see cref="DesiredCapabilities"/> to compare with this <see cref="DesiredCapabilities"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="DesiredCapabilities"/> is equal to the <paramref name="other"/> parameter; otherwise, <see langword="false"/>.</returns>
public bool Equals(DesiredCapabilities? other)
{
if (other is null)
{
return true;
return false;
}

if (obj is not DesiredCapabilities other)
if (ReferenceEquals(this, other))
{
return false;
return true;
}

if (this.BrowserName != null ? this.BrowserName != other.BrowserName : other.BrowserName != null)
if (this.BrowserName != other.BrowserName)
{
return false;
}
Expand All @@ -271,7 +281,7 @@ public override bool Equals(object? obj)
return false;
}

if (this.Version != null ? this.Version != other.Version : other.Version != null)
if (this.Version != other.Version)
{
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/webdriver/Remote/ReadOnlyDesiredCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public IDictionary<string, object> ToDictionary()
public override int GetHashCode()
{
int result;
result = this.BrowserName != null ? this.BrowserName.GetHashCode() : 0;
result = (31 * result) + (this.Version != null ? this.Version.GetHashCode() : 0);
result = (31 * result) + (this.Platform != null ? this.Platform.GetHashCode() : 0);
result = this.BrowserName?.GetHashCode() ?? 0;
result = (31 * result) + (this.Version?.GetHashCode() ?? 0);
result = (31 * result) + (this.Platform?.GetHashCode() ?? 0);
return result;
}

Expand Down
14 changes: 12 additions & 2 deletions dotnet/src/webdriver/SessionId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenQA.Selenium;
/// <summary>
/// Provides a mechanism for maintaining a session for a test
/// </summary>
public class SessionId
public class SessionId : IEquatable<SessionId>
{
private readonly string sessionOpaqueKey;

Expand Down Expand Up @@ -63,6 +63,16 @@ public override int GetHashCode()
/// <returns><see langword="true"/> if the values are equal; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
return obj is SessionId otherSession && this.sessionOpaqueKey.Equals(otherSession.sessionOpaqueKey);
return Equals(obj as SessionId);
}

/// <summary>
/// Indicates whether the current session ID value is the same as <paramref name="other"/>.
/// </summary>
/// <param name="other">The session to compare to.</param>
/// <returns><see langword="true"/> if the values are equal; otherwise, <see langword="false"/>.</returns>
public bool Equals(SessionId? other)
{
return other is not null && string.Equals(this.sessionOpaqueKey, other.sessionOpaqueKey);
}
}
24 changes: 15 additions & 9 deletions dotnet/src/webdriver/WebElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace OpenQA.Selenium;
/// <summary>
/// A base class representing an HTML element on a page.
/// </summary>
public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, ITakesScreenshot, IWebDriverObjectReference
public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, ITakesScreenshot, IWebDriverObjectReference, IEquatable<IWebElement>
{
/// <summary>
/// The property name that represents a web element in the wire protocol.
Expand Down Expand Up @@ -652,18 +652,24 @@ public override int GetHashCode()
}

/// <summary>
/// Compares if two elements are equal
/// Indicates whether the current <see cref="WebElement"/> is equal to another object.
/// </summary>
/// <param name="obj">Object to compare against</param>
/// <returns>A boolean if it is equal or not</returns>
/// <param name="obj">An object to compare with this <see cref="WebElement"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="WebElement"/> is equal to the other parameter; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
if (obj is not IWebElement other)
{
return false;
}
return Equals(obj as IWebElement);
}

if (obj is IWrapsElement objAsWrapsElement)
/// <summary>
/// Indicates whether the current <see cref="WebElement"/> is equal to another <see cref="IWebElement"/>.
/// </summary>
/// <param name="other">An <see cref="IWebElement"/> to compare with this <see cref="WebElement"/>.</param>
/// <returns><see langword="true"/> if the current <see cref="WebElement"/> is equal to the <paramref name="other"/> parameter; otherwise, <see langword="false"/>.</returns>
/// <remarks>This method only returns <see langword="true"/> if <paramref name="other"/> is or wraps a <see cref="WebElement"/>.</remarks>
public bool Equals(IWebElement? other)
{
if (other is IWrapsElement objAsWrapsElement)
{
other = objAsWrapsElement.WrappedElement;
}
Expand Down
Loading