Skip to content

Commit b0ff8df

Browse files
[dotnet] Add screenshot support for EventFiringWebElement (#9258)
* Add screenshot support for EventFiringWebElement * Add EventFiringWebElement screenshot test Co-authored-by: Diego Molina <[email protected]>
1 parent 720451f commit b0ff8df

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

dotnet/src/support/Events/EventFiringWebDriver.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ public TimeSpan PageLoad
11741174
/// <summary>
11751175
/// EventFiringWebElement allows you to have access to specific items that are found on the page
11761176
/// </summary>
1177-
private class EventFiringWebElement : IWebElement, IWrapsElement, IWrapsDriver
1177+
private class EventFiringWebElement : ITakesScreenshot, IWebElement, IWrapsElement, IWrapsDriver
11781178
{
11791179
private IWebElement underlyingElement;
11801180
private EventFiringWebDriver parentDriver;
@@ -1566,6 +1566,23 @@ public ReadOnlyCollection<IWebElement> FindElements(By by)
15661566
return wrappedElementList.AsReadOnly();
15671567
}
15681568

1569+
/// <summary>
1570+
/// Gets a <see cref="Screenshot"/> object representing the image of the page on the screen.
1571+
/// </summary>
1572+
/// <returns>A <see cref="Screenshot"/> object containing the image.</returns>
1573+
public Screenshot GetScreenshot()
1574+
{
1575+
ITakesScreenshot screenshotDriver = this.underlyingElement as ITakesScreenshot;
1576+
if (this.underlyingElement == null)
1577+
{
1578+
throw new NotSupportedException("Underlying element instance does not support taking screenshots");
1579+
}
1580+
1581+
Screenshot screen = null;
1582+
screen = screenshotDriver.GetScreenshot();
1583+
return screen;
1584+
}
1585+
15691586
/// <summary>
15701587
/// Determines whether the specified <see cref="EventFiringWebElement"/> is equal to the current <see cref="EventFiringWebElement"/>.
15711588
/// </summary>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using NUnit.Framework;
2+
3+
namespace OpenQA.Selenium.Support.Events
4+
{
5+
[TestFixture]
6+
public class EventFiringWebDriverElementTest : DriverTestFixture
7+
{
8+
[SetUp]
9+
public void Setup()
10+
{
11+
driver.Url = formsPage;
12+
}
13+
14+
[Test]
15+
public void CanTakeEventFiringWebElementScreenshot()
16+
{
17+
var firingDriver = new EventFiringWebDriver(driver);
18+
IWebElement element = firingDriver.FindElement(By.Name("checky"));
19+
Screenshot screenshot = ((ITakesScreenshot)element).GetScreenshot();
20+
21+
Assert.IsNotNull(screenshot);
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)