private static bool SingleSend(EmailInformations from, EmailInformations to, MailMessage message)
        {
            try
            {
                var fromAddress = new MailAddress(from.Email, from.Name);
                var toAddress   = new MailAddress(to.Email, to.Name);
                var config      = ReportHelper.Configuration;
                var smtp        = new SmtpClient
                {
                    Host                  = config.SmtpHost,
                    Port                  = config.SmtpPort,
                    EnableSsl             = config.EnableSsl,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(from.Email.Split('@').First(), from.Password),
                    Timeout               = 10000
                };

                using (smtp)
                {
                    message.From = fromAddress;
                    message.To.Add(toAddress);
                    smtp.Send(message);
                }
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Failure in SingleSend method!");
                return(false);
            }
            return(true);
        }
        public static List <TestInformations> GetNewestTests(string attachmentsPath)
        {
            var tests   = new List <TestInformations>();
            var folders = Directory.GetDirectories(attachmentsPath);

            foreach (var folder in folders)
            {
                try
                {
                    var dirInfo  = new DirectoryInfo(folder);
                    var allFiles = dirInfo.GetFiles("*.xml").OrderByDescending(x => x.CreationTime);
                    if (allFiles.Any())
                    {
                        var newestFile = allFiles.First().FullName;
                        tests.Add(Load(newestFile));
                    }
                    else
                    {
                        Directory.Delete(dirInfo.FullName);
                    }
                }
                catch (Exception ex)
                {
                    InternalLogs.Exception(ex, "Exception while loading test xml file");
                }
            }

            return(tests);
        }
        private void SendEmailsForEvents()
        {
            try
            {
                if (!_configuration.SendEmails)
                {
                    return;
                }

                var eventSubs = _methodInfo.GetCustomAttributes <EventNotification>();
                foreach (var sub in eventSubs)
                {
                    var currentTestVersions = ReportTestHelper.GetTestsFromFolder(_test.AttachmentsPath);
                    var subscription        = _configuration.EventDurationSubscriptions.FirstOrDefault(x => x.Name.Equals(sub.Name));
                    if (currentTestVersions.Count > 1)
                    {
                        var previousTest = currentTestVersions
                                           .OrderByDescending(x => x.DateTimeFinish)
                                           .Skip(1)
                                           .First(x => x.Events.Any(e => e.Name.Equals(sub.EventName)));
                        var previuosEvent = previousTest.Events.First(x => x.Name.Equals(sub.EventName));
                        var currentEvent  = _test.Events.First(x => x.Name.Equals(sub.EventName));

                        if (currentEvent.Duration - previuosEvent.Duration > sub.MaxDifference)
                        {
                            if (subscription != null)
                            {
                                ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                       _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                       true, sub.EventName, previuosEvent);
                            }
                            else if (sub.FullPath != null)
                            {
                                subscription = ReportXMLHelper.Load <EventDurationSubscription>(sub.FullPath);
                                ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                       _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                       true, sub.EventName, previuosEvent);
                            }
                            else if (sub.Targets.Any())
                            {
                                ReportEmailHelper.Send(_configuration.SendFromList, sub.Targets,
                                                       _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                       true, sub.EventName, previuosEvent);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception in SendEmailsForEvents");
            }
        }
Пример #4
0
 public static void Save <T> (this T t, string fullPath) where T : class
 {
     try
     {
         var ser = new XmlSerializer(typeof(T));
         using (var fs = new FileStream(fullPath, FileMode.CreateNew))
         {
             ser.Serialize(fs, t);
         }
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Save exception");
     }
 }
Пример #5
0
 static ReportHelper()
 {
     try
     {
         var path = GetPath();
         Directory.SetCurrentDirectory(path);
         var configuration = ReportConfigurationHelper.Load(@"ReportConfig.xml");
         //var configuration = NunitGoConfigurationHelper.Load(Path.Combine(path, "NUnitGoConfig.xml"));
         Configuration = configuration;
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, GetPath(), "Exception in ReportHelper constructor");
     }
 }
        public static List <TestInformations> GetTestsFromFolder(string folder)
        {
            var tests = new List <TestInformations>();

            try
            {
                var dirInfo = new DirectoryInfo(folder);
                var files   = dirInfo.GetFiles("*.xml", SearchOption.AllDirectories);
                tests.AddRange(files.Select(fileInfo => Load(fileInfo.FullName)));
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception while loading test xml file");
            }
            return(tests);
        }
        private List <Remark> GetTestRemarks()
        {
            var remarks = new List <Remark>();

            try
            {
                var rmrks = _methodInfo.GetCustomAttributes <TestRemark>();
                remarks.AddRange(rmrks.Select(
                                     remarkAttribute => new Remark(remarkAttribute.RemarkDate, remarkAttribute.RemarkMessage)));
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception in GetTestRemarks");
            }
            return(remarks);
        }
 private void TakeScreenshotIfFailed()
 {
     try
     {
         if (!_test.IsSuccess() && _configuration.TakeScreenshotAfterTestFailed)
         {
             var now = DateTime.Now;
             _test.Screenshots.Add(new Screenshot(now));
             ScreenshotTaker.TakeScreenshot(_screenshotsPath, now);
         }
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Exception in TakeScreenshot");
     }
 }
Пример #9
0
 public static T Load <T> (string fullPath, string exceptionMessage = "") where T : class
 {
     try
     {
         T   t;
         var ser = new XmlSerializer(typeof(T));
         using (var fs = new FileStream(fullPath, FileMode.Open))
         {
             t = (T)ser.Deserialize(fs);
         }
         return(t);
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, exceptionMessage.Equals("") ? "Load exception" : exceptionMessage);
         return(null);
     }
 }
        private void SaveTestFiles()
        {
            try
            {
                Directory.CreateDirectory(_test.AttachmentsPath);
                _test.SaveAsXml(_test.AttachmentsPath + Output.Files.GetTestXmlName(_test.DateTimeFinish));
                var testVersions     = ReportTestHelper.GetTestsFromFolder(_test.AttachmentsPath);
                var testRemarks      = GetTestRemarks();
                var chartId          = Output.GetHistoryChartId(_test.Guid, _test.DateTimeFinish);
                var highstockHistory = new ReportJsHighstock(testVersions, testRemarks, chartId);
                highstockHistory.SaveScript(_test.AttachmentsPath);

                var testPath = _test.AttachmentsPath + Output.Files.GetTestHtmlName(_test.DateTimeFinish);
                _test.GenerateTestPage(testPath, _testOutput, Output.Files.GetTestHistoryScriptName(_test.DateTimeFinish));
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception in SaveTestFiles");
            }
        }
Пример #11
0
 public static void GenerateStyleFile(string cssFullPath)
 {
     try
     {
         var cssPage = new CssPage();
         cssPage.AddStyles(new List <string>
         {
             HtmlPage.StyleString,
             Tooltip.StyleString,
             HorizontalBar.StyleString,
             Bullet.StyleString,
             NunitTestHtml.StyleString
         });
         cssPage.SavePage(cssFullPath);
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Exception while generating css style page");
     }
 }
        public void GenerateReport()
        {
            try
            {
                if (!_configuration.GenerateReport)
                {
                    return;
                }

                const string cssPageName = Output.Files.ReportStyleFile;
                var          cssFullPath = Path.Combine(_outputPath, cssPageName);
                if (!File.Exists(cssFullPath))
                {
                    PageGenerator.GenerateStyleFile(cssFullPath);
                }

                /*
                 * var primerName = Output.Files.PrimerStyleFile;
                 * ExtractResource(primerName, _outputPath);
                 *
                 * var octiconsName = Output.Files.OcticonsStyleFiles;
                 * ExtractResources(octiconsName, _outputPath);
                 *
                 * //jquery - 1.11.0.min.js
                 * var jqueryName = Output.Files.JQueryScriptFile;
                 * ExtractResource(jqueryName, _outputPath);
                 */
                var tests      = ReportTestHelper.GetNewestTests(_attachmentsPath).OrderBy(x => x.DateTimeFinish).ToList();
                var stats      = new MainStatistics(tests, _startSuite);
                var statsChart = new MainInfoChart(stats, Output.GetStatsPieId());
                statsChart.SaveScript(_outputPath);
                tests.GenerateTimelinePage(Path.Combine(_outputPath, Output.Files.TimelineFile));
                stats.GenerateMainStatisticsPage(Path.Combine(_outputPath, Output.Files.TestStatisticsFile));
                tests.GenerateTestListPage(Path.Combine(_outputPath, Output.Files.TestListFile));
                tests.GenerateReportMainPage(_outputPath, stats);
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception in GenerateReport");
            }
        }
 public static void DeleteTestFiles(this TestInformations test, string screenshotsPath)
 {
     try
     {
         var finishDate = test.DateTimeFinish;
         var scriptPath = Path.Combine(test.AttachmentsPath, Output.Files.GetTestHistoryScriptName(finishDate));
         var htmlPath   = Path.Combine(test.AttachmentsPath, Output.Files.GetTestHtmlName(finishDate));
         var xmlPath    = Path.Combine(test.AttachmentsPath, Output.Files.GetTestXmlName(finishDate));
         File.Delete(scriptPath);
         File.Delete(htmlPath);
         File.Delete(xmlPath);
         foreach (var screenshot in test.Screenshots)
         {
             File.Delete(Path.Combine(screenshotsPath, screenshot.Name));
         }
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Exception in CleanUpTestFiles");
     }
 }
Пример #14
0
        public static void GenerateTestPage(this TestInformations test, string fullPath, string testOutput, string chartFile)
        {
            try
            {
                const string script   = @"
					$(document).ready(function() {
						$("".tabs-menu a"").click(function(event) {
							event.preventDefault();
							$(this).parent().addClass(""current"");
							$(this).parent().siblings().removeClass(""current"");
							var tab = $(this).attr(""href"");
							$("".tab-content"").not(tab).css(""display"", ""none"");
							$(tab).fadeIn();
						});
					});
				"                ;
                var          htmlTest = new NunitTestHtml(test, testOutput);
                var          page     = new HtmlPage("Test page")
                {
                    PageStylePaths = new List <string>
                    {
                        "./../../" + Output.Files.ReportStyleFile,
                        "./../../" + Output.Files.PrimerStyleFile
                    },
                    PageScriptString = script,
                    ScriptFilePaths  = new List <string>
                    {
                        "./../../" + Output.Files.JQueryScriptFile,
                        Output.Files.HighstockScriptFile,
                        chartFile
                    },
                    PageBodyCode = htmlTest.HtmlCode
                };
                page.SavePage(fullPath);
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception while generating test html page");
            }
        }
Пример #15
0
 public static void GenerateTimelinePage(this List <TestInformations> tests, string fullPath)
 {
     try
     {
         var reportMenuTitle = new SectionName("Tests timeline");
         var timeline        = new TimelineSection(tests);
         var page            = new HtmlPage("Timeline page")
         {
             PageStylePaths = new List <string>
             {
                 Output.Files.ReportStyleFile,
                 Output.Files.PrimerStyleFile
             },
             PageBodyCode = reportMenuTitle.HtmlCode + timeline.HtmlCode
         };
         page.SavePage(fullPath);
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Exception while generating timeline page");
     }
 }
Пример #16
0
 public static void GenerateMainStatisticsPage(this MainStatistics stats, string fullPath)
 {
     try
     {
         var reportMenuTitle   = new SectionName("Main statistics");
         var statisticsSection = new StatisticsSection(stats);
         var page = new HtmlPage("Main statistics page")
         {
             PageStylePaths = new List <string>
             {
                 Output.Files.ReportStyleFile,
                 Output.Files.PrimerStyleFile
             },
             PageBodyCode = reportMenuTitle.HtmlCode + statisticsSection.HtmlCode
         };
         page.SavePage(fullPath);
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Exception while generating main statistics page");
     }
 }
 private void CleanUpTestFiles()
 {
     try
     {
         var maxDate = DateTime.Now.AddDays(-_configuration.TestHistoryDaysLength);
         var folders = Directory.GetDirectories(_attachmentsPath);
         foreach (var folder in folders)
         {
             var dirInfo  = new DirectoryInfo(folder);
             var allFiles = dirInfo.GetFiles("*.xml").OrderByDescending(x => x.CreationTime);
             if (dirInfo.LastWriteTime < maxDate || dirInfo.CreationTime < maxDate || !allFiles.Any())
             {
                 Directory.Delete(dirInfo.FullName, true);
             }
             else
             {
                 var folderTestVersions       = ReportTestHelper.GetTestsFromFolder(folder);
                 var folderTestVersionsNumber = folderTestVersions.Count;
                 if (folderTestVersionsNumber >= _configuration.MaxTestVersionsNumber)
                 {
                     folderTestVersions.OrderByDescending(x => x.DateTimeFinish)
                     .Skip(_configuration.MaxTestVersionsNumber)
                     .ToList()
                     .ForEach(x => x.DeleteTestFiles(_screenshotsPath));
                 }
                 ReportTestHelper
                 .GetTestsFromFolder(folder)
                 .Where(x => x.DateTimeFinish < maxDate)
                 .ToList()
                 .ForEach(x => x.DeleteTestFiles(_screenshotsPath));
             }
         }
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Exception in CleanUpTestFiles");
     }
 }
Пример #18
0
 public static void GenerateReportMainPage(this List <TestInformations> tests,
                                           string pathToSave, MainStatistics mainStats)
 {
     try
     {
         var menuElements = new List <ReportMenuItem>
         {
             new ReportMenuItem("Main statistics", Output.Files.TestStatisticsFile, "octicon octicon-graph"),
             new ReportMenuItem("Test list", Output.Files.TestListFile, "octicon octicon-checklist"),
             new ReportMenuItem("Timeline", Output.Files.TimelineFile, "octicon octicon-clock")
         };
         var mainTitle       = new SectionName("Test Run Report");
         var mainInformation = new MainInformationSection(mainStats);
         var reportMenu      = new MenuSection(menuElements, "main-menu", "Report menu");
         var report          = new HtmlPage("Automation Report")
         {
             ScriptFilePaths = new List <string>
             {
                 Output.Files.JQueryScriptFile,
                 Output.Files.HighstockScriptFile,
                 Output.Files.StatsScript
             },
             PageStylePaths = new List <string>
             {
                 Output.Files.ReportStyleFile,
                 Output.Files.PrimerStyleFile,
                 Output.Files.OcticonStyleFile
             },
             PageBodyCode = mainTitle.HtmlCode + mainInformation.HtmlCode + reportMenu.ReportMenuHtml
         };
         report.SavePage(Path.Combine(pathToSave, Output.Files.FullReportFile));
     }
     catch (Exception ex)
     {
         InternalLogs.Exception(ex, "Exception while generating full report page");
     }
 }
        private void SendEmails(bool isSuccess)
        {
            try
            {
                if (!_configuration.SendEmails)
                {
                    return;
                }

                var subs = _methodInfo.GetCustomAttributes <Notification>();
                foreach (var sub in subs)
                {
                    var sendCondition = (sub.UnsuccessfulOnly && !isSuccess) || (!sub.UnsuccessfulOnly);
                    if (!sendCondition)
                    {
                        continue;
                    }

                    var subscription = _configuration.Subsciptions.FirstOrDefault(x => x.Name.Equals(sub.Name));
                    if (subscription != null)
                    {
                        ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                               _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                    }
                    else if (sub.FullPath != null)
                    {
                        subscription = ReportXMLHelper.Load <Subsciption>(sub.FullPath);
                        ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                               _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                    }
                    else if (sub.Targets.Any())
                    {
                        ReportEmailHelper.Send(_configuration.SendFromList, sub.Targets,
                                               _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                    }
                }

                /*
                 * var singleSubs = _methodInfo.GetCustomAttributes<SingleTestSubscriptionAttribute>();
                 * foreach (var singleSub in singleSubs)
                 * {
                 *  var sendCondition = (singleSub.UnsuccessfulOnly && !isSuccess) || (!singleSub.UnsuccessfulOnly);
                 *  if (!sendCondition) continue;
                 *
                 *  var singleTestSubscription =
                 *      _configuration.SingleTestSubscriptions.FirstOrDefault(x => x.TestGuid.Equals(_test.Guid));
                 *  if (singleTestSubscription != null)
                 *  {
                 *      ReportEmailHelper.Send(_configuration.SendFromList, singleTestSubscription.TargetEmails,
                 *          _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                 *  }
                 *  else if (singleSub.FullPath != null)
                 *  {
                 *      var singleSubFromXml = ReportXMLHelper.Load<SingleTestSubscription>(singleSub.FullPath);
                 *      ReportEmailHelper.Send(_configuration.SendFromList, singleSubFromXml.TargetEmails,
                 *          _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                 *  }
                 *  else if (singleSub.Targets.Any())
                 *  {
                 *      ReportEmailHelper.Send(_configuration.SendFromList, singleSub.Targets,
                 *          _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                 *  }
                 * }
                 */
                var eventSubs = _methodInfo.GetCustomAttributes <EventNotification>();
                foreach (var sub in eventSubs)
                {
                    var currentTestVersions = ReportTestHelper.GetTestsFromFolder(_test.AttachmentsPath);

                    if (currentTestVersions.Count <= 1)
                    {
                        continue;
                    }

                    var previousTest = currentTestVersions
                                       .OrderByDescending(x => x.DateTimeFinish)
                                       .Skip(1)
                                       .First(x => x.Events.Any(e => e.Name.Equals(sub.EventName)));
                    var previuosEvent = previousTest.Events.First(x => x.Name.Equals(sub.EventName));
                    var currentEvent  = _test.Events.First(x => x.Name.Equals(sub.EventName));

                    if (Math.Abs(currentEvent.Duration - previuosEvent.Duration) > sub.MaxDifference)
                    {
                        var subscription = _configuration.EventDurationSubscriptions.FirstOrDefault(x => x.Name.Equals(sub.Name));
                        if (subscription != null)
                        {
                            ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                   _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                   true, sub.EventName, previuosEvent);
                        }
                        else if (sub.FullPath != null)
                        {
                            subscription = ReportXMLHelper.Load <EventDurationSubscription>(sub.FullPath);
                            ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                   _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                   true, sub.EventName, previuosEvent);
                        }
                        else if (sub.Targets.Any())
                        {
                            ReportEmailHelper.Send(_configuration.SendFromList, sub.Targets,
                                                   _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                   true, sub.EventName, previuosEvent);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception in SendEmail");
            }
        }