firstly i must state, that i am new to Selenium testing framework and not very experienced in programming. I need to do client-side web testing and i think selenium is the way to go and i am trying to figure an architecture. At the moment i am struggeling with recovering from an exception.
So i am subscribing to an event, if any error occurs on my Main method:
class Program
{
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += ExceptionHandler.CurrentDomainOnUnhandledException;
var test = new Login.LoginPageTests();
test.DoLogin();
}
}
So if anything is thrown, it logs it and should return to baseURL.
class ExceptionHandler
{
internal static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
var screenShot = TestHelpers.TakeScreenShot();
var stack = new StackTrace();
var callingMethod = stack.GetFrame(1).GetMethod().Name;
var e = (Exception)unhandledExceptionEventArgs.ExceptionObject;
Console.WriteLine("{0} : {1}\nscreenshot: {2}", callingMethod, e.Message, screenShot);
var driver = TestHelpers.Driver;
driver.Navigate().GoToUrl(TestHelpers.BaseUrl);
}
}
But now, let's say i am inside test method and exception is thrown, it still crashes everything. Why is that? How can continue running next test?
EDIT: TestHelpers.Driver is:
internal class TestHelpers
{
internal const string BaseUrl = @"http://someUrl:8103";
private static IWebDriver _driver;
public static IWebDriver Driver
{
get
{
if (_driver == null)
{
_driver = new FirefoxDriver();
_driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
_driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));
}
return _driver;
}
}