public void TakeScreenShotIfFailed() { if (ScenarioContext.Current.TestError == null) { return; } string testResultFolder = TestRunContext.GetValue <string>("TestResultFolder"); string screenShotFileName = $@"{ScenarioContext.Current.ScenarioInfo.Title}_{DateTime.Now.ToString("yyyyMMdd_hhmmss")}.jpg"; string screenShotFile = $@"{testResultFolder}\{screenShotFileName}"; // Please refer to: http://stackoverflow.com/questions/1163761/capture-screenshot-of-active-window Rectangle bounds = Screen.GetBounds(Point.Empty); using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size); } bitmap.Save(screenShotFile, ImageFormat.Jpeg); } TestScenarioDetailsManager .Instance .SaveScreenShotFile(screenShotFileName); }
public static void GenerateTestResultReportInHtml() { string testResultFolder = TestRunContext.GetValue <string>("TestResultFolder"); string htmlFile = $@"{testResultFolder}\TestReport.html"; var report = new TestResultReportInHtmlManager(htmlFile, TestScenarioDetailsManager.Instance.AllTestScenarios); report.GenerateReport(); }
public static void PublishTestResultByEmail() { try { if (Convert.ToBoolean(ConfigurationManager.AppSettings["sendEmailReport"])) { string testResultFolder = TestRunContext.GetValue <string>("TestResultFolder"); SendEmailManager.Instance.SendEmail(testResultFolder); } } catch (Exception e) { Console.WriteLine("Email sending meets some errors: {0}", e.Message); } }