Skip to content

Instantly share code, notes, and snippets.

@elgatov
Created May 29, 2019 15:05
Show Gist options
  • Save elgatov/c566736afc163c0cda45489433c477e9 to your computer and use it in GitHub Desktop.
Save elgatov/c566736afc163c0cda45489433c477e9 to your computer and use it in GitHub Desktop.
using OpenQA.Selenium;
using OpenQA.Selenium.Support.Events;
using OpenQA.Selenium.Support.UI;
using System;
namespace InfrastructureSelenium.Helper
{
class EventFiringWebDriverWait : WebDriverWait
{
private event EventHandler<WebDriverExceptionEventArgs> TimedOut;
private IWebDriver driver { get; set; }
public EventFiringWebDriverWait(IWebDriver driver, TimeSpan timeout) : base(driver, timeout)
{
this.driver = driver;
TimedOut = new EventHandler<WebDriverExceptionEventArgs>(EventListeners._ExceptionThrown);
IgnoreExceptionTypes(typeof(NotFoundException));
Message = "El elemento no ha sido encontrado en el tiempo límite. Finalizando ejecución";
}
protected override void ThrowTimeoutException(string exceptionMessage, Exception lastException)
{
EventHandler<WebDriverExceptionEventArgs> handler = TimedOut;
handler(this, new WebDriverExceptionEventArgs(driver,
new WebDriverTimeoutException(Message, lastException))
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment