While running a Test method, suppose the application went down suddenly or a time out issue came up because of which ContolNotFound exception occurred and got existed from the test method.
In this scenario in order to invoke the test method from the TestCleanup again this is how we do
[TestCleanup]
public override void MyTestCleanup()
{
// Here i am writing for an generic flow checking my test failed.
// you can check if any time out window availability or application down messages in browser
// Here i am writing for an generic flow checking my test failed.
// you can check if any time out window availability or application down messages in browser
if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
{
var type = Type.GetType(TestContext.FullyQualifiedTestClassName);
if (type != null)
{
var instance = Activator.CreateInstance(type);
var method = type.GetMethod(TestContext.TestName);
try
{
method.Invoke(instance, null);
}
catch
{
}
}
}}