I'm writing a number of unit tests and I would like to print the line of code where I get an exception into my error log.
I'm not sure if you can do this
My demo test looks something like this and you can see from this what I'm currently passing but the message "Couldn't find element" is imprecise.
I pass a message, the line number and the method, however the line number doesn't serve much purpose as it only gets the line number where the catch is triggered.
public void createTest()
{
try
{
excelSession.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
excelSession.FindElementByName("Blank workbook").Click();
excelSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
excelSession.FindElementByName("Create").Click();
skipTearDown = true;
}
catch (Exception)
{
CommonMethods.ExceptionHandler("Couldn't find element", new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), excelSession);
}
TearDown();
}