public void AfterTest(ITest test)
        {
            //Log.Write("FINISH: " + test.FullName);
            
            _finish = DateTime.Now;
            _guid = _guid.Equals(Guid.Empty) 
                ? (TestGuid.Equals(Guid.Empty) ? Guid.NewGuid() : TestGuid)
                : _guid;

            var context = TestContext.CurrentContext;
            var outputPath = _configuration.LocalOutputPath;
            var screenshotsPath = outputPath + @"\Screenshots\";
            var attachmentsPath = outputPath + @"\Attachments\";
            var relativeTestHref = "Attachments" + @"/" + _guid + @"/" + Output.Files.TestHtmlFile;
            
            _nunitGoTest = new NunitGoTest
            {
                DateTimeStart = _start,
                DateTimeFinish = DateTime.Now,
                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 != null ? context.Result.Outcome.ToString() : "Unknown",
                Guid = _guid,
                Screenshots = new List<Screenshot>(),
                HasOutput = !TestContext.Out.ToString().Equals(string.Empty),
                AttachmentsPath = attachmentsPath + _guid + @"\",
                TestHrefRelative = relativeTestHref,
                TestHrefAbsolute = _configuration.ServerLink + relativeTestHref,
                LogHref = Output.Files.TestOutputFile
            };

            CreateDirectories();
            
            TakeScreenshot(screenshotsPath);
            
            _nunitGoTest.AddScreenshots(ScreenshotHelper.GetScreenshots(screenshotsPath));
            _nunitGoTest.Save(_nunitGoTest.AttachmentsPath + Output.Files.TestXmlFile);

            SendEmails(_nunitGoTest.IsSuccess(), test, screenshotsPath);
            
            GenerateReport();

            Flush();
        }
Example #2
0
        public NunitTestHtml(NunitGoTest nunitGoTest)
        {
            ModalWindowsHtml = "";

            Style = GetStyle();
            BackgroundColor = nunitGoTest.GetBackgroundColor();

            var strWr = new StringWriter();
            using (var writer = new HtmlTextWriter(strWr))
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.Left, "0%");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "test-window");
                writer.AddAttribute(HtmlTextWriterAttribute.Title, Title);
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                writer.AddAttribute(HtmlTextWriterAttribute.Id, Id);
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "1% 2% 3% 97%");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.Write(new CloseButton("Back", "./../../" + Output.Files.TestListFile).ButtonHtml);
                writer.RenderEndTag(); //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

                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, nunitGoTest.GetBackgroundColor());
                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(nunitGoTest.TestDuration);
                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.AddAttribute(HtmlTextWriterAttribute.Href, @"./../../Screenshots/" + screenshot.Name);
                    writer.RenderBeginTag(HtmlTextWriterTag.A);
                    writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, @"./../../Screenshots/" + screenshot.Name);
                    writer.AddAttribute(HtmlTextWriterAttribute.Alt, screenshot.Name);
                    writer.RenderBeginTag(HtmlTextWriterTag.Img);
                    writer.RenderEndTag();//IMG
                    writer.RenderEndTag();//A
                }

                if (nunitGoTest.HasOutput)
                {
                    var openButton = new OpenButton("View full log", nunitGoTest.LogHref, Colors.OpenLogsButtonBackground);
                    writer.Write(openButton.ButtonHtml);
                    //writer.Write(GenerateHtmlView(nunitGoTest.AttachmentsPath + Structs.Outputs.Out));
                }
                
                if (!nunitGoTest.IsSuccess())
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, "Stack trace: ");
                    writer.Write(GenerateTxtView(nunitGoTest.TestStackTrace));
                    writer.RenderEndTag(); //P
                    writer.RenderBeginTag(HtmlTextWriterTag.P);
                    writer.AddTag(HtmlTextWriterTag.B, "Message: ");
                    writer.Write(GenerateTxtView(nunitGoTest.TestMessage));
                    writer.RenderEndTag(); //P
                }

                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.AddTag(HtmlTextWriterTag.B, "Test guid: ");
                writer.Write(nunitGoTest.Guid);
                writer.RenderEndTag(); //P

                writer.RenderEndTag(); //DIV
                writer.RenderEndTag(); //DIV

            }

            HtmlCode = strWr.ToString();
        }