Skip to content

Commit f336673

Browse files
Jordan Macejimevans
authored andcommitted
Adds equals override to EventFiringWebElement
Signed-off-by: Jim Evans <[email protected]>
1 parent f683dd2 commit f336673

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

dotnet/src/support/Events/EventFiringWebDriver.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,20 @@ public void Submit()
14191419
}
14201420
}
14211421

1422+
public override bool Equals(object obj)
1423+
{
1424+
if (!(obj is IWebElement))
1425+
return false;
1426+
1427+
IWebElement other = (IWebElement)obj;
1428+
if(other is IWrapsElement wrapper)
1429+
{
1430+
other = ((IWrapsElement)wrapper).WrappedElement;
1431+
}
1432+
1433+
return underlyingElement.Equals(other);
1434+
}
1435+
14221436
/// <summary>
14231437
/// Click this element. If this causes a new page to load, this method will block until
14241438
/// the page has loaded. At this point, you should discard all references to this element

dotnet/test/support/Events/EventFiringWebDriverTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ public void ShouldFireValueChangedEvent()
106106
Assert.AreEqual(expectedLog, log.ToString());
107107
}
108108

109+
[Test]
110+
public void ElementsCanEqual()
111+
{
112+
mockDriver.Setup(_ => _.FindElement(It.Is<By>(x => x.Equals(By.Id("foo"))))).Returns(mockElement.Object);
113+
114+
EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object);
115+
var element1 = firingDriver.FindElement(By.Id("foo"));
116+
var element2 = firingDriver.FindElement(By.Id("foo"));
117+
118+
Assert.AreEqual(element1, element2);
119+
}
120+
109121
[Test]
110122
public void ShouldFireFindByEvent()
111123
{

0 commit comments

Comments
 (0)