protected void ReportResult(Status status, string reportFilePath) { test = extent.CreateTest("Test Summary"); if (status == Status.Pass) { test.Pass(TestContext.TestName + " Passed"); for (int i = 0; i < validations.Count; i++) { test.Info(string.Join(Environment.NewLine, validations[i])); } } else { //ExtentReportsHelper.test.Error(lastException); //string callingMethodName = new StackFrame(1, true).GetMethod().Name; //string callingClassName = GetType().Name; string timeStamp = DateTime.Now.ToString("ddMMyyyyHHmmss"); string filePath = captureLocation + "ErrorCapture" + timeStamp + ".png"; try { Screenshot screenshot = ((ITakesScreenshot)Browser.Driver).GetScreenshot(); screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png); } catch (Exception e) { Console.WriteLine("TakeScreenshot encountered an error. " + e.Message); } finally { try { if (lastException == null || lastException.ToString().Contains("Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException")) { test.Fail(TestContext.TestName + " Failed - " + lastException.Message); for (int i = 0; i < validations.Count; i++) { test.Info(string.Join(Environment.NewLine, validations[i])); } } else { if (ExtentReportsHelper.nodeList.LastOrDefault() != null) { ExtentReportsHelper.nodeList.LastOrDefault().Error(lastException.ToString(), ExtentReportsHelper.AttachScreenshot(filePath)); } { test.Error(TestContext.TestName + " Got Exception During Execution - " + lastException.Message + " " + lastException.StackTrace, ExtentReportsHelper.AttachScreenshot(filePath)); for (int i = 0; i < validations.Count; i++) { test.Info(string.Join(Environment.NewLine, validations[i])); } } } } catch (Exception) { // do nothing } } TestContext.AddResultFile(filePath); } extent.AnalysisStrategy = AnalysisStrategy.Test; extent.Flush(); TestContext.AddResultFile(reportPath); }