public static string GetMailSubject(NunitGoTest nunitGoTest) { return nunitGoTest.IsSuccess() ? String.Format("Test '{0}' was finished successfully", nunitGoTest.Name) : (nunitGoTest.IsFailed() ? String.Format("Test '{0}' was failed", nunitGoTest.Name) : (nunitGoTest.IsBroken() ? String.Format("Test '{0}' was broken", nunitGoTest.Name) : (nunitGoTest.IsIgnored() ? String.Format("Test '{0}' was ignored", nunitGoTest.Name) : (nunitGoTest.IsInconclusive() ? String.Format("Test '{0}' is inconclusive", nunitGoTest.Name) : String.Format("Test '{0}' was not successfully finished", nunitGoTest.Name))))); }
private void TakeScreenshotIfFailed() { try { if (!_nunitGoTest.IsSuccess() && _configuration.TakeScreenshotAfterTestFailed) { var now = DateTime.Now; _nunitGoTest.Screenshots.Add(new Screenshot(now)); Taker.TakeScreenshot(_screenshotsPath, now); } } catch (Exception ex) { Log.Exception(ex, "Exception in TakeScreenshot"); } }
public static string GetMailSubject(NunitGoTest nunitGoTest, bool isEventEmail = false, string eventName = "") { if (isEventEmail) { return(string.Format("Test '{0}' has wrong event duration! Event '{1}'", nunitGoTest.Name, nunitGoTest.Events.First(x => x.Name.Equals(eventName)).Name)); } return(nunitGoTest.IsSuccess() ? string.Format("Test '{0}' was finished successfully", nunitGoTest.Name) : (nunitGoTest.IsFailed() ? string.Format("Test '{0}' was failed", nunitGoTest.Name) : (nunitGoTest.IsBroken() ? string.Format("Test '{0}' was broken", nunitGoTest.Name) : (nunitGoTest.IsIgnored() ? string.Format("Test '{0}' was ignored", nunitGoTest.Name) : (nunitGoTest.IsInconclusive() ? string.Format("Test '{0}' is inconclusive", nunitGoTest.Name) : string.Format("Test '{0}' was not successfully finished", nunitGoTest.Name)))))); }
public void AfterTest(ITest test) { _finish = DateTime.Now; _guid = _guid.Equals(Guid.Empty) ? (NunitGo.TestGuid.Equals(Guid.Empty) ? GuidConverter.ToMd5HashGuid(test.FullName) : NunitGo.TestGuid) : _guid; _testOutput = TestContext.Out.ToString(); _testName = _testName.Equals("") ? NunitGo.TestName : _testName; var context = TestContext.CurrentContext; var relativeTestHref = "Attachments" + @"/" + _guid + @"/" + Output.Files.GetTestHtmlName(_finish); _nunitGoTest = new NunitGoTest { DateTimeStart = _start, DateTimeFinish = _finish, TestDuration = (_finish - _start).TotalSeconds, FullName = test.FullName, ProjectName = _projectName.Equals("") ? test.FullName.Split('.').First() : _projectName, ClassName = _className.Equals("") ? test.FullName.Split('.').Skip(1).First() : _className, Name = _testName.Equals("") ? test.Name : _testName, TestStackTrace = context.Result.StackTrace ?? "", TestMessage = context.Result.Message ?? "", Result = context.Result.Outcome?.ToString() ?? "Unknown", Guid = _guid, HasOutput = !_testOutput.Equals(string.Empty), AttachmentsPath = _attachmentsPath + _guid + @"\", TestHrefRelative = relativeTestHref, TestHrefAbsolute = _configuration.ServerLink + relativeTestHref, Events = NunitGo.GetEvents() }; TakeScreenshotIfFailed(); AddScreenshots(); CleanUpTestFiles(); SaveTestFiles(); SendEmails(_nunitGoTest.IsSuccess()); SendEmailsForEvents(); GenerateReport(); Flush(); }
public static HtmlTextWriter AddFailure(this HtmlTextWriter writer, NunitGoTest nunitGoTest, string id = "") { writer.AddAttribute(HtmlTextWriterAttribute.Id, id.Equals("") ? "table-cell" : id); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "20px"); writer.RenderBeginTag(HtmlTextWriterTag.Div); if (!nunitGoTest.IsSuccess()) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Message: "); writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestMessage)); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Stack trace: "); writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestStackTrace)); writer.RenderEndTag(); //P } else { writer.Write("Test was successful, there is no failure message"); } writer.RenderEndTag();//DIV return(writer); }
public static string GetMailBody(NunitGoTest nunitGoTest, bool addLinks, bool isEventEmail = false, string eventName = "", TestEvent previousRunEvent = null) { var strWr = new StringWriter(); using (var writer = new HtmlTextWriter(strWr)) { writer.Write("<!DOCTYPE html>"); writer.Write(Environment.NewLine); writer.RenderBeginTag(HtmlTextWriterTag.Head); writer.Tag(HtmlTextWriterTag.Meta, new Dictionary<string, string> { {"http-equiv", "X-UA-Compatible"}, {"content", @"IE=edge"}, {"charset", "utf-8"} }); writer.Tag(HtmlTextWriterTag.Title, "NUnitGo Email"); writer.Tag(HtmlTextWriterTag.Style, new Dictionary<HtmlTextWriterAttribute, string> { {HtmlTextWriterAttribute.Type, @"text/css"} }); writer.Tag(HtmlTextWriterTag.Link, new Dictionary<HtmlTextWriterAttribute, string> { {HtmlTextWriterAttribute.Rel, @"stylesheet"}, {HtmlTextWriterAttribute.Type, @"text/css"} }); writer.RenderEndTag(); //HEAD writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, Colors.White); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px"); writer.AddStyleAttribute("border", "10px solid " + Colors.TestBorderColor); writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "0px"); writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Tahoma,Verdana,Segoe,sans-serif"); writer.RenderBeginTag(HtmlTextWriterTag.Body); writer.AddStyleAttribute("box-sizing", "border-box"); writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "auto"); writer.AddStyleAttribute(HtmlTextWriterStyle.Top, "0%"); writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "test-window"); writer.AddAttribute(HtmlTextWriterAttribute.Title, "Test"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px"); writer.AddAttribute(HtmlTextWriterAttribute.Id, nunitGoTest.Guid.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test full name: "); writer.Write(nunitGoTest.FullName); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test name: "); writer.Write(nunitGoTest.Name); writer.RenderEndTag(); //P if (isEventEmail && previousRunEvent != null) { var currentEvent = nunitGoTest.Events.First(x => x.Name.Equals(eventName)); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Event name: "); writer.Write(currentEvent.Name); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, string.Format("Current duration (event finished at {0}): ", currentEvent.Finished)); writer.Write(TimeSpan.FromSeconds(currentEvent.Duration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, string.Format("Previous duration (event finished at {0}): ", previousRunEvent.Finished)); writer.Write(TimeSpan.FromSeconds(previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Difference: "); writer.Write(TimeSpan.FromSeconds(currentEvent.Duration - previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P } writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, nunitGoTest.GetColor()); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.RenderBeginTag(HtmlTextWriterTag.B); writer.Write("Test result: "); writer.RenderEndTag(); //B writer.Write(nunitGoTest.Result); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test duration: "); writer.Write(TimeSpan.FromSeconds(nunitGoTest.TestDuration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Time period: "); var start = nunitGoTest.DateTimeStart.ToString("dd.MM.yy HH:mm:ss.fff"); var end = nunitGoTest.DateTimeFinish.ToString("dd.MM.yy HH:mm:ss.fff"); writer.Write(start + " - " + end); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Screenshots: "); writer.Write(nunitGoTest.Screenshots.Count); writer.RenderEndTag(); //P var screens = nunitGoTest.Screenshots.OrderBy(x => x.Date); foreach (var screenshot in screens) { writer.Write("Screenshot (Date: " + screenshot.Date.ToString("dd.MM.yy HH:mm:ss.fff") + "):"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "inherited"); writer.AddAttribute(HtmlTextWriterAttribute.Src, @"cid:" + screenshot.Name); writer.AddAttribute(HtmlTextWriterAttribute.Alt, screenshot.Name); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag();//IMG writer.RenderEndTag();//DIV } if (!nunitGoTest.IsSuccess()) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Stack trace: "); writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestStackTrace)); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Message: "); writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestMessage)); writer.RenderEndTag(); //P } if (addLinks) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test page: "); writer.AddStyleAttribute("background", Colors.OpenLogsButtonBackground); writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "black"); writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, "none !important"); writer.AddAttribute(HtmlTextWriterAttribute.Href, nunitGoTest.TestHrefAbsolute); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write(Environment.NewLine + "View on site"); writer.RenderEndTag(); //A writer.RenderEndTag(); //P } writer.RenderEndTag(); //DIV writer.RenderEndTag(); //DIV writer.RenderEndTag(); //BODY writer.Write(Environment.NewLine); writer.Write("</html>"); writer.Write(Environment.NewLine); } return strWr.ToString(); }
public static string GetMailSubject(NunitGoTest nunitGoTest, bool isEventEmail = false, string eventName = "") { if (isEventEmail) { return string.Format("Test '{0}' has wrong event duration! Event '{1}'", nunitGoTest.Name, nunitGoTest.Events.First(x => x.Name.Equals(eventName)).Name); } return nunitGoTest.IsSuccess() ? string.Format("Test '{0}' was finished successfully", nunitGoTest.Name) : (nunitGoTest.IsFailed() ? string.Format("Test '{0}' was failed", nunitGoTest.Name) : (nunitGoTest.IsBroken() ? string.Format("Test '{0}' was broken", nunitGoTest.Name) : (nunitGoTest.IsIgnored() ? string.Format("Test '{0}' was ignored", nunitGoTest.Name) : (nunitGoTest.IsInconclusive() ? string.Format("Test '{0}' is inconclusive", nunitGoTest.Name) : string.Format("Test '{0}' was not successfully finished", nunitGoTest.Name))))); }
public static string GetMailBody(NunitGoTest nunitGoTest, bool addLinks, bool isEventEmail = false, string eventName = "", TestEvent previousRunEvent = null) { var strWr = new StringWriter(); using (var writer = new HtmlTextWriter(strWr)) { writer.Write("<!DOCTYPE html>"); writer.Write(Environment.NewLine); writer.RenderBeginTag(HtmlTextWriterTag.Head); writer.Tag(HtmlTextWriterTag.Meta, new Dictionary <string, string> { { "http-equiv", "X-UA-Compatible" }, { "content", @"IE=edge" }, { "charset", "utf-8" } }); writer.Tag(HtmlTextWriterTag.Title, "NUnitGo Email"); writer.Tag(HtmlTextWriterTag.Style, new Dictionary <HtmlTextWriterAttribute, string> { { HtmlTextWriterAttribute.Type, @"text/css" } }); writer.Tag(HtmlTextWriterTag.Link, new Dictionary <HtmlTextWriterAttribute, string> { { HtmlTextWriterAttribute.Rel, @"stylesheet" }, { HtmlTextWriterAttribute.Type, @"text/css" } }); writer.RenderEndTag(); //HEAD writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, Colors.White); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px"); writer.AddStyleAttribute("border", "10px solid " + Colors.TestBorderColor); writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "0px"); writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Tahoma,Verdana,Segoe,sans-serif"); writer.RenderBeginTag(HtmlTextWriterTag.Body); writer.AddStyleAttribute("box-sizing", "border-box"); writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "auto"); writer.AddStyleAttribute(HtmlTextWriterStyle.Top, "0%"); writer.AddStyleAttribute(HtmlTextWriterStyle.Height, "100%"); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px"); writer.AddAttribute(HtmlTextWriterAttribute.Class, "test-window"); writer.AddAttribute(HtmlTextWriterAttribute.Title, "Test"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "10px"); writer.AddAttribute(HtmlTextWriterAttribute.Id, nunitGoTest.Guid.ToString()); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test full name: "); writer.Write(nunitGoTest.FullName); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test name: "); writer.Write(nunitGoTest.Name); writer.RenderEndTag(); //P if (isEventEmail && previousRunEvent != null) { var currentEvent = nunitGoTest.Events.First(x => x.Name.Equals(eventName)); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Event name: "); writer.Write(currentEvent.Name); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, string.Format("Current duration (event finished at {0}): ", currentEvent.Finished)); writer.Write(TimeSpan.FromSeconds(currentEvent.Duration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, string.Format("Previous duration (event finished at {0}): ", previousRunEvent.Finished)); writer.Write(TimeSpan.FromSeconds(previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Difference: "); writer.Write(TimeSpan.FromSeconds(currentEvent.Duration - previousRunEvent.Duration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P } writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, nunitGoTest.GetColor()); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.RenderBeginTag(HtmlTextWriterTag.B); writer.Write("Test result: "); writer.RenderEndTag(); //B writer.Write(nunitGoTest.Result); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test duration: "); writer.Write(TimeSpan.FromSeconds(nunitGoTest.TestDuration).ToString(@"hh\:mm\:ss\:fff")); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Time period: "); var start = nunitGoTest.DateTimeStart.ToString("dd.MM.yy HH:mm:ss.fff"); var end = nunitGoTest.DateTimeFinish.ToString("dd.MM.yy HH:mm:ss.fff"); writer.Write(start + " - " + end); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Screenshots: "); writer.Write(nunitGoTest.Screenshots.Count); writer.RenderEndTag(); //P var screens = nunitGoTest.Screenshots.OrderBy(x => x.Date); foreach (var screenshot in screens) { writer.Write("Screenshot (Date: " + screenshot.Date.ToString("dd.MM.yy HH:mm:ss.fff") + "):"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "inherited"); writer.AddAttribute(HtmlTextWriterAttribute.Src, @"cid:" + screenshot.Name); writer.AddAttribute(HtmlTextWriterAttribute.Alt, screenshot.Name); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); //IMG writer.RenderEndTag(); //DIV } if (!nunitGoTest.IsSuccess()) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Stack trace: "); writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestStackTrace)); writer.RenderEndTag(); //P writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Message: "); writer.Write(NunitTestHtml.GenerateTxtView(nunitGoTest.TestMessage)); writer.RenderEndTag(); //P } if (addLinks) { writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddTag(HtmlTextWriterTag.B, "Test page: "); writer.AddStyleAttribute("background", Colors.OpenLogsButtonBackground); writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "black"); writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, "none !important"); writer.AddAttribute(HtmlTextWriterAttribute.Href, nunitGoTest.TestHrefAbsolute); writer.RenderBeginTag(HtmlTextWriterTag.A); writer.Write(Environment.NewLine + "View on site"); writer.RenderEndTag(); //A writer.RenderEndTag(); //P } writer.RenderEndTag(); //DIV writer.RenderEndTag(); //DIV writer.RenderEndTag(); //BODY writer.Write(Environment.NewLine); writer.Write("</html>"); writer.Write(Environment.NewLine); } return(strWr.ToString()); }