I'm using the NUnit framework. If my test-case failed with an exception like a timeout or any other exceptions. After the test it should go to [Teardown]
but it is not going struck there abort the operation.
Agenda is trying to log the errors and capture it to the extent report.
[Obsolete]
[Test]
public void TestMethod()
{
try
{
...Throwing exceptions
}
catch(Exception ex)
{
// throw new NotImplementedException();
// Assert.Fail("No exception was thrown");
// AfterTest();
}
}
[TearDown]
public void AfterTest()
{
try
{
var status = TestContext.CurrentContext.Result.Outcome.Status;
var stacktrace = " " +TestContext.CurrentContext.Result.StackTrace + " ";
var errorMessage = TestContext.CurrentContext.Result.Message;
Status logstatus;
switch (status)
{
case TestStatus.Failed:
logstatus = Status.Fail;
string screenShotPath = Capture(driver, TestContext.CurrentContext.Test.Name);
_test.Log(logstatus, "Test ended with " +logstatus + " – " +errorMessage);
_test.Log(logstatus, "Snapshot below: " +_test.AddScreenCaptureFromPath(screenShotPath));
break;
case TestStatus.Skipped:
logstatus = Status.Skip;
_test.Log(logstatus, "Test ended with " +logstatus);
break;
default:
logstatus = Status.Pass;
_test.Log(logstatus, "Test ended with " +logstatus);
break;
}
driver.Quit();
}
catch (Exception e)
{
throw (e);
}
}
[Teardown]
annotation. Then you should not use thetry-catch
inside the test annotations because Test annotations provide test results based on the exception so try by removingtry-catch
blocks