I'm writing a simple extension library to Selenium Webdriver. I have my "wrapper" class WebDriverManager
which defines event delegates as follows:
public delegate void OnStartEventHandler();
public delegate void OnTerminateEventHandler();
public delegate void OnCheckpointEventHandler();
public event OnStartEventHandler OnStartTesting;
public event OnTerminateEventHandler OnTerminateTesting;
public event OnCheckpointEventHandler OnCheckpointTesting;
/// <summary>
/// Method that should be fired inside method with [OneTimeSetUp] attribute
/// </summary>
public void OnStart() { if (OnStartTesting != null) OnStartTesting(); }
/// <summary>
/// Method that should be fired inside method with [OneTimeTearDown] attribute
/// </summary>
public void OnTerminate() { if (OnTerminateTesting != null) OnTerminateTesting(); }
/// <summary>
/// Method that should be fired inside method with either [SetUp] or [TearDown] attribute
/// </summary>
public void OnCheckpoint() { if (OnCheckpointTesting != null) OnCheckpointTesting(); }
In my target project I add a reference to library that contains WebDriverManager
class and write a simple method:
[OneTimeSetUp]
public void SetUp()
{
// wdmChrome and wdmFirefox are instances of WebDriverManager
wdmChrome.OnStartTesting += () => { Console.WriteLine("Starting testing Chrome browser"); };
wdmFirefox.OnStartTesting += () => { Console.WriteLine("Starting testing Firefox browser"); };
wdmChrome.OnTerminateTesting += () => { Console.WriteLine("Terminating test of Chrome browser"); };
wdmFirefox.OnTerminateTesting += () => { Console.WriteLine("Terminating test of Firefox browser"); };
wdmChrome.OnStart();
wdmFirefox.OnStart();
// other stuff that initializes webdriver
}
[OneTimeTearDown]
public void TearDown()
{
wdmChrome.OnTerminate();
wdmFirefox.OnTerminate();
wdmChrome.WebDriver.Close();
wdmFirefox.WebDriver.Close();
}
Test gets fired properly and passes, but in "Output" there are no messages from delegates. I also tried to change body of OnStart()
to OnStartTesting?.Invoke()
as suggested by Visual Studio, but nothing changed in result. What's going on?