public void TestFilteringLoggerImportantArea() { var lines = LogInput.Split(new[] { "\r\n" }, StringSplitOptions.None); var output = new AccumulationLogger(); var logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages); var config = new ManualConfig(); config.Add(logger); using (LoggerHelpers.BeginImportantLogScope(config)) { foreach (var line in lines) { logger.WriteLine(line); } Assert.AreEqual(output.GetLog(), LogInput + "\r\n"); output = new AccumulationLogger(); logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages); var i = 0; foreach (var line in lines) { if (i++ % 2 == 0) { logger.WriteLineError(line); } else { logger.WriteLineHint(line); } } Assert.AreEqual(output.GetLog(), LogInput + "\r\n"); output = new AccumulationLogger(); logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages); LogMessages(logger); // ReSharper disable once StringLiteralTypo const string Expected = @"ABCDEFGH TST0 // !TST1 TST2 // !<-- TST3 // !<-- TST4 TST5 // !--> TST6 // !--> TST7 TST8 // !TST9 TST10 "; Assert.AreEqual(output.GetLog(), Expected); } }
internal bool IsContactPageOpened() { var testStepResult = Driver.FindElement(ContactUs).Displayed; LoggerHelpers.LogInfoAboutPageOrWindowOpening("ContactPage"); return(testStepResult); }
internal T ClickLink <T>(LinkText link) { switch (link) { case LinkText.Home: Click(Home); LoggerHelpers.LogInfoAboutPageOrWindowOpening("HomePage"); return((T)Convert.ChangeType(new HomePage(Driver), typeof(T))); case LinkText.About: Click(AboutLinkLocator); LoggerHelpers.LogInfoAboutPageOrWindowOpening("AboutPage"); return((T)Convert.ChangeType(new AboutPage(Driver), typeof(T))); case LinkText.Business: Click(BusinessLinkLocator); LoggerHelpers.LogInfoAboutPageOrWindowOpening("BusinessPage"); return((T)Convert.ChangeType(new BusinessPage(Driver), typeof(T))); case LinkText.Careers: Click(CareersLinkLocator); LoggerHelpers.LogInfoAboutPageOrWindowOpening("CareerPage"); return((T)Convert.ChangeType(new CareersPage(Driver), typeof(T))); case LinkText.Contact: Click(ContactLinkLocator); LoggerHelpers.LogInfoAboutPageOrWindowOpening("ContactPage"); return((T)Convert.ChangeType(new ContactPage(Driver), typeof(T))); default: throw new Exception("No such link text"); } }
internal bool IsBusinessPageOpened() { var testStepResult = Driver.FindElement(OurBusinesses).Displayed; LoggerHelpers.LogInfoAboutPageOrWindowOpening("BusinessPage"); return(testStepResult); }
internal bool IsInsightsPageOpened() { var testStepResult = Driver.FindElement(InsightsLinkLocator).Displayed; LoggerHelpers.LogInfoAboutPageOrWindowOpening("InsightsPage"); return(testStepResult); }
internal static CompetitionState Run( [NotNull] Type benchmarkType, [NotNull] ICompetitionConfig competitionConfig) { var competitionState = InitCompetitionState(benchmarkType, competitionConfig); var runLogger = new MessageLogger(competitionState.Config, MessageSource.Runner); try { LogCompetitionHeader(competitionState); using (var mutex = new Mutex(false, $"Global\\{typeof(CompetitionCore).FullName}")) { var lockTaken = false; try { var timeout = competitionState.Options.RunOptions.Concurrent == ConcurrentRunBehavior.Lock ? _totalWaitTimeout : TimeSpan.Zero; lockTaken = SpinWait(mutex, timeout, _spinWaitRunTimeout, runLogger); if (CheckPreconditions(competitionState, lockTaken, runLogger)) { RunCore(competitionState, runLogger); } } finally { if (lockTaken) { mutex.ReleaseMutex(); } } } } catch (TargetInvocationException ex) { runLogger.WriteExceptionMessage( MessageSeverity.ExecutionError, $"Benchmark {competitionState.BenchmarkType.Name} failed.", ex.InnerException ?? ex); } catch (Exception ex) { runLogger.WriteExceptionMessage( MessageSeverity.ExecutionError, $"Benchmark {competitionState.BenchmarkType.Name} failed.", ex); } finally { LoggerHelpers.FlushLoggers(competitionState.Config); competitionState.CompetitionCompleted(); } return(competitionState); }
private static void LogCompetitionHeader(CompetitionState competitionState) { var logger = competitionState.Logger; var benchmarkType = competitionState.BenchmarkType; using (LoggerHelpers.BeginImportantLogScope(competitionState.Config)) { logger.WriteSeparatorLine(benchmarkType.Name, true); logger.WriteHelpHintLine(benchmarkType.GetShortAssemblyQualifiedName()); } }
private void ProcessRunComplete([NotNull] CompetitionState competitionState) { var logger = competitionState.Logger; var summary = competitionState.LastRunSummary; if (summary == null) { return; } logger.WriteVerboseLine($"{competitionState.BenchmarkType.Name} completed."); if (competitionState.Options.RunOptions.DetailedLogging) { var messages = competitionState.GetMessages(); if (messages.Any()) { logger.WriteSeparatorLine("All messages"); foreach (var message in messages) { logger.LogMessage(message); } } else { logger.WriteSeparatorLine(); logger.WriteVerboseLine("No messages in run."); } logger.WriteLine(); } else { using (LoggerHelpers.BeginImportantLogScope(summary.Config)) { var summaryLogger = DumpSummaryToHostLogger ? logger : new CompositeLogger( summary.Config .GetLoggers() .Where(l => !(l is HostLogger)) .ToArray()); // Dumping the benchmark summary summaryLogger.WriteSeparatorLine("Summary"); MarkdownExporter.Console.ExportToLog(summary, summaryLogger); logger.WriteLine(); } } }
private static void LogCompetitionRunHeader(CompetitionState competitionState) { var logger = competitionState.Logger; using (LoggerHelpers.BeginImportantLogScope(competitionState.Config)) { var run = competitionState.RunNumber; var runsExpected = competitionState.RunNumber + competitionState.RunsLeft; var runMessage = competitionState.RunLimitExceeded ? $"Run {run}, total runs (expected): {runsExpected} (rerun limit exceeded, last run)" : $"Run {run}, total runs (expected): {runsExpected}"; logger.WriteSeparatorLine(runMessage); } }
private CompetitionState RunCore( [NotNull] Type benchmarkType, [CanBeNull] ICompetitionConfig competitionConfig, [CanBeNull] CompetitionFeatures competitionFeatures) { Code.NotNull(benchmarkType, nameof(benchmarkType)); competitionConfig = CreateBenchmarkConfig(benchmarkType, competitionConfig, competitionFeatures); var hostLogger = competitionConfig.GetLoggers().OfType <HostLogger>().Single(); var previousDirectory = Environment.CurrentDirectory; var currentDirectory = GetOutputDirectory(benchmarkType.Assembly); if (currentDirectory == previousDirectory) { currentDirectory = null; previousDirectory = null; } CompetitionState competitionState = null; try { SetCurrentDirectoryIfNotNull(currentDirectory); try { competitionState = CompetitionCore.Run(benchmarkType, competitionConfig); ProcessRunComplete(competitionState); } finally { ReportHostLogger(hostLogger, competitionState?.LastRunSummary); } using (FilteringLogger.BeginLogImportant(competitionState.Config)) { ReportMessagesToUser(competitionState); } } finally { LoggerHelpers.FlushLoggers(competitionConfig); SetCurrentDirectoryIfNotNull(previousDirectory); } return(competitionState); }
protected void SetText(By locator, string text) { LocateElement(locator).SendKeys(text); LoggerHelpers.LogInfoAboutValueEnteredIntoFormField(text); }
internal static CompetitionState Run( [NotNull] Type benchmarkType, [NotNull] ICompetitionConfig competitionConfig) { Code.NotNull(benchmarkType, nameof(benchmarkType)); Code.NotNull(competitionConfig, nameof(competitionConfig)); var runStateSlots = competitionConfig.GetValidators().OfType <RunStateSlots>(); if (runStateSlots.Count() != 1) { throw CodeExceptions.Argument( nameof(competitionConfig), $"The competition config should include single instance of {nameof(RunStateSlots)} validator."); } var competitionState = RunState[competitionConfig]; try { competitionState.FirstTimeInit(benchmarkType, competitionConfig); var logger = competitionState.Logger; using (BeginLogImportant(competitionConfig)) { logger.WriteSeparatorLine(benchmarkType.Name, true); logger.WriteLineHelp($"{LogInfoPrefix} {benchmarkType.GetShortAssemblyQualifiedName()}"); } using (var mutex = new Mutex(false, $"Global\\{typeof(CompetitionCore).FullName}")) { var lockTaken = false; try { var timeout = competitionState.Options.RunOptions.Concurrent == ConcurrentRunBehavior.Lock ? TotalWaitTimeout : TimeSpan.Zero; lockTaken = SpinWait(mutex, timeout, SpinWaitRunTimeout, competitionState); if (CheckPreconditions(benchmarkType, lockTaken, competitionState)) { RunCore(benchmarkType, competitionState); } } finally { if (lockTaken) { mutex.ReleaseMutex(); } } } } catch (TargetInvocationException ex) { competitionState.WriteExceptionMessage( MessageSource.Runner, MessageSeverity.ExecutionError, $"Benchmark {benchmarkType.Name} failed.", ex.InnerException ?? ex); } catch (Exception ex) { competitionState.WriteExceptionMessage( MessageSource.Runner, MessageSeverity.ExecutionError, $"Benchmark {benchmarkType.Name} failed.", ex); } finally { LoggerHelpers.FlushLoggers(competitionConfig); } competitionState.CompetitionCompleted(); return(competitionState); }