Skip to content

Commit

Permalink
Adds equals override to EventFiringWebElement
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Evans <[email protected]>
  • Loading branch information
Jordan Mace authored and jimevans committed Mar 17, 2020
1 parent f683dd2 commit f336673
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dotnet/src/support/Events/EventFiringWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,20 @@ public void Submit()
}
}

public override bool Equals(object obj)
{
if (!(obj is IWebElement))
return false;

IWebElement other = (IWebElement)obj;
if(other is IWrapsElement wrapper)
{
other = ((IWrapsElement)wrapper).WrappedElement;
}

return underlyingElement.Equals(other);
}

/// <summary>
/// Click this element. If this causes a new page to load, this method will block until
/// the page has loaded. At this point, you should discard all references to this element
Expand Down
12 changes: 12 additions & 0 deletions dotnet/test/support/Events/EventFiringWebDriverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public void ShouldFireValueChangedEvent()
Assert.AreEqual(expectedLog, log.ToString());
}

[Test]
public void ElementsCanEqual()
{
mockDriver.Setup(_ => _.FindElement(It.Is<By>(x => x.Equals(By.Id("foo"))))).Returns(mockElement.Object);

EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object);
var element1 = firingDriver.FindElement(By.Id("foo"));
var element2 = firingDriver.FindElement(By.Id("foo"));

Assert.AreEqual(element1, element2);
}

[Test]
public void ShouldFireFindByEvent()
{
Expand Down

0 comments on commit f336673

Please sign in to comment.