public void AfterStep() { try { var currentStep = ReportPortalAddin.GetStepTestReporter(this.StepContext); var stepFinishRequest = new FinishTestItemRequest { EndTime = DateTime.UtcNow }; if (this.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.TestError) { stepFinishRequest.Status = Status.Failed; } var eventArg = new StepFinishedEventArgs(_service, stepFinishRequest, currentStep, this.FeatureContext, this.ScenarioContext, this.StepContext); ReportPortalAddin.OnBeforeStepFinished(this, eventArg); if (!eventArg.Canceled) { currentStep.Finish(stepFinishRequest); ReportPortalAddin.RemoveStepTestReporter(this.StepContext, currentStep); ReportPortalAddin.OnAfterStepFinished(this, eventArg); } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } finally { ContextAwareLogHandler.ActiveStepContext = null; } }
public static void BeforeTestRun() { if (Configuration.ReportPortal.Enabled) { var request = new StartLaunchRequest { Name = Configuration.ReportPortal.Launch.Name, StartTime = DateTime.UtcNow }; if (Configuration.ReportPortal.Launch.DebugMode) { request.Mode = LaunchMode.Debug; } request.Tags = new List <string>(Configuration.ReportPortal.Launch.Tags.Split(',')); var eventArg = new RunStartedEventArgs(Bridge.Service, request); ReportPortalAddin.OnBeforeRunStarted(null, eventArg); if (!eventArg.Canceled) { Bridge.Context.LaunchReporter = new LaunchReporter(Bridge.Service); Bridge.Context.LaunchReporter.Start(request); Bridge.Context.LaunchReporter.StartTask.Wait(); ReportPortalAddin.OnAfterRunStarted(null, new RunStartedEventArgs(Bridge.Service, request, Bridge.Context.LaunchReporter)); } } }
public void BeforeScenario() { var currentFeature = ReportPortalAddin.GetFeatureTestReporter(this.FeatureContext); if (currentFeature != null) { var request = new StartTestItemRequest { Name = this.ScenarioContext.ScenarioInfo.Title, StartTime = DateTime.UtcNow, Type = TestItemType.Step, Tags = new List <string>(this.ScenarioContext.ScenarioInfo.Tags) }; var eventArg = new TestItemStartedEventArgs(Bridge.Service, request); ReportPortalAddin.OnBeforeScenarioStarted(this, eventArg); if (!eventArg.Canceled) { var currentScenario = currentFeature.StartNewTestNode(request); ReportPortalAddin.SetScenarioTestReporter(this.ScenarioContext, currentScenario); ReportPortalAddin.OnAfterScenarioStarted(this, new TestItemStartedEventArgs(Bridge.Service, request, currentFeature)); } } }
public static void AfterFeature(FeatureContext featureContext) { lock (LockHelper.GetLock(FeatureInfoEqualityComparer.GetFeatureInfoHashCode(featureContext.FeatureInfo))) { var currentFeature = ReportPortalAddin.GetFeatureTestReporter(featureContext); var remainingThreadCount = ReportPortalAddin.DecrementFeatureThreadCount(featureContext); if (currentFeature != null && currentFeature.FinishTask == null && remainingThreadCount == 0) { var request = new FinishTestItemRequest { EndTime = DateTime.UtcNow, Status = Status.Skipped }; var eventArg = new TestItemFinishedEventArgs(Bridge.Service, request, currentFeature); ReportPortalAddin.OnBeforeFeatureFinished(null, eventArg); if (!eventArg.Canceled) { currentFeature.Finish(request); currentFeature.FinishTask.Wait(); ReportPortalAddin.OnAfterFeatureFinished(null, new TestItemFinishedEventArgs(Bridge.Service, request, currentFeature)); } } } }
public static void AfterTestRun() { try { if (_launchReporter != null) { var request = new FinishLaunchRequest { EndTime = DateTime.UtcNow }; var eventArg = new RunFinishedEventArgs(_service, request, _launchReporter); ReportPortalAddin.OnBeforeRunFinished(null, eventArg); if (!eventArg.Canceled) { _launchReporter.Finish(request); var sw = Stopwatch.StartNew(); _traceLogger.Info($"Finishing to send results to ReportPortal..."); _launchReporter.Sync(); _traceLogger.Info($"Elapsed: {sw.Elapsed}"); _traceLogger.Info(_launchReporter.StatisticsCounter.ToString()); ReportPortalAddin.OnAfterRunFinished(null, new RunFinishedEventArgs(_service, request, _launchReporter)); } } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } }
public void AfterStep() { var currentScenario = ReportPortalAddin.GetScenarioTestReporter(this.ScenarioContext); if (currentScenario != null) { var eventArg = new StepFinishedEventArgs(Bridge.Service, null, null); ReportPortalAddin.OnBeforeStepFinished(this, eventArg); if (!eventArg.Canceled) { ReportPortalAddin.OnAfterStepFinished(this, eventArg); } } }
public static void BeforeFeature(FeatureContext featureContext) { try { if (_launchReporter != null) { ContextAwareLogHandler.ActiveFeatureContext = featureContext; lock (LockHelper.GetLock(FeatureInfoEqualityComparer.GetFeatureInfoHashCode(featureContext.FeatureInfo))) { var currentFeature = ReportPortalAddin.GetFeatureTestReporter(featureContext); if (currentFeature == null || currentFeature.FinishTask != null) { var request = new StartTestItemRequest { Name = featureContext.FeatureInfo.Title, Description = featureContext.FeatureInfo.Description, StartTime = DateTime.UtcNow, Type = TestItemType.Suite, Attributes = featureContext.FeatureInfo.Tags?.Select(t => new ItemAttributeConverter().ConvertFrom(t, (opts) => opts.UndefinedKey = "Tag")).ToList() }; var eventArg = new TestItemStartedEventArgs(_service, request, null, featureContext, null); ReportPortalAddin.OnBeforeFeatureStarted(null, eventArg); if (!eventArg.Canceled) { currentFeature = _launchReporter.StartChildTestReporter(request); ReportPortalAddin.SetFeatureTestReporter(featureContext, currentFeature); ReportPortalAddin.OnAfterFeatureStarted(null, new TestItemStartedEventArgs(_service, request, currentFeature, featureContext, null)); } } else { ReportPortalAddin.IncrementFeatureThreadCount(featureContext); } } } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } }
public static void BeforeTestRun() { try { var config = Initialize(); var request = new StartLaunchRequest { Name = config.GetValue(ConfigurationPath.LaunchName, "SpecFlow Launch"), StartTime = DateTime.UtcNow }; if (config.GetValue(ConfigurationPath.LaunchDebugMode, false)) { request.Mode = LaunchMode.Debug; } request.Attributes = config.GetKeyValues("Launch:Attributes", new List <KeyValuePair <string, string> >()).Select(a => new ItemAttribute { Key = a.Key, Value = a.Value }).ToList(); request.Description = config.GetValue(ConfigurationPath.LaunchDescription, string.Empty); var eventArg = new RunStartedEventArgs(_service, request); ReportPortalAddin.OnBeforeRunStarted(null, eventArg); if (eventArg.LaunchReporter != null) { _launchReporter = eventArg.LaunchReporter; } if (!eventArg.Canceled) { Shared.Extensibility.Embedded.Analytics.AnalyticsReportEventsObserver.DefineConsumer("agent-dotnet-specflow"); _launchReporter = _launchReporter ?? new LaunchReporter(_service, config, null, Shared.Extensibility.ExtensionManager.Instance); _launchReporter.Start(request); ReportPortalAddin.OnAfterRunStarted(null, new RunStartedEventArgs(_service, request, _launchReporter)); } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } }
public void Handle(ScenarioContext scenarioContext) { var scenarioReporter = ReportPortalAddin.GetScenarioTestReporter(scenarioContext); var skippedStepReporter = scenarioReporter.StartChildTestReporter(new Client.Abstractions.Requests.StartTestItemRequest { Name = scenarioContext.StepContext.StepInfo.GetCaption(), StartTime = DateTime.UtcNow, Type = Client.Abstractions.Models.TestItemType.Step, HasStats = false }); skippedStepReporter.Finish(new Client.Abstractions.Requests.FinishTestItemRequest { EndTime = DateTime.UtcNow, Status = Client.Abstractions.Models.Status.Skipped }); }
public void BeforeStep() { try { ContextAwareLogHandler.ActiveStepContext = this.StepContext; var currentScenario = ReportPortalAddin.GetScenarioTestReporter(this.ScenarioContext); var stepInfoRequest = new StartTestItemRequest { Name = this.StepContext.StepInfo.GetCaption(), StartTime = DateTime.UtcNow, HasStats = false }; var eventArg = new StepStartedEventArgs(_service, stepInfoRequest, currentScenario, this.FeatureContext, this.ScenarioContext, this.StepContext); ReportPortalAddin.OnBeforeStepStarted(this, eventArg); if (!eventArg.Canceled) { var stepReporter = currentScenario.StartChildTestReporter(stepInfoRequest); ReportPortalAddin.SetStepTestReporter(this.StepContext, stepReporter); // step parameters var formattedParameters = this.StepContext.StepInfo.GetFormattedParameters(); if (!string.IsNullOrEmpty(formattedParameters)) { stepReporter.Log(new CreateLogItemRequest { Text = formattedParameters, Level = LogLevel.Info, Time = DateTime.UtcNow }); } ReportPortalAddin.OnAfterStepStarted(this, eventArg); } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } }
private static IConfiguration Initialize() { var args = new InitializingEventArgs(Plugin.Config); ReportPortalAddin.OnInitializing(typeof(ReportPortalHooks), args); var uri = Plugin.Config.GetValue <string>(ConfigurationPath.ServerUrl); var project = Plugin.Config.GetValue <string>(ConfigurationPath.ServerProject);; var uuid = Plugin.Config.GetValue <string>(ConfigurationPath.ServerAuthenticationUuid);; if (args.Service != null) { _service = args.Service as Service; } else { _service = new Service(new Uri(uri), project, uuid); } return(args.Config); }
public static void AfterTestRun() { if (Bridge.Context.LaunchReporter != null) { var request = new FinishLaunchRequest { EndTime = DateTime.UtcNow }; var eventArg = new RunFinishedEventArgs(Bridge.Service, request, Bridge.Context.LaunchReporter); ReportPortalAddin.OnBeforeRunFinished(null, eventArg); if (!eventArg.Canceled) { Bridge.Context.LaunchReporter.Finish(request); Bridge.Context.LaunchReporter.FinishTask.Wait(); ReportPortalAddin.OnAfterRunFinished(null, new RunFinishedEventArgs(Bridge.Service, request, Bridge.Context.LaunchReporter)); } } }
public static void AfterFeature(FeatureContext featureContext) { try { lock (LockHelper.GetLock(FeatureInfoEqualityComparer.GetFeatureInfoHashCode(featureContext.FeatureInfo))) { var currentFeature = ReportPortalAddin.GetFeatureTestReporter(featureContext); var remainingThreadCount = ReportPortalAddin.DecrementFeatureThreadCount(featureContext); if (currentFeature != null && currentFeature.FinishTask == null && remainingThreadCount == 0) { var request = new FinishTestItemRequest { EndTime = DateTime.UtcNow, Status = Status.Skipped }; var eventArg = new TestItemFinishedEventArgs(_service, request, currentFeature, featureContext, null); ReportPortalAddin.OnBeforeFeatureFinished(null, eventArg); if (!eventArg.Canceled) { currentFeature.Finish(request); ReportPortalAddin.OnAfterFeatureFinished(null, new TestItemFinishedEventArgs(_service, request, currentFeature, featureContext, null)); } ReportPortalAddin.RemoveFeatureTestReporter(featureContext, currentFeature); } } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } finally { ContextAwareLogHandler.ActiveFeatureContext = null; } }
public void BeforeStep() { var currentScenario = ReportPortalAddin.GetScenarioTestReporter(this.ScenarioContext); if (currentScenario != null) { var stepInfoRequest = new AddLogItemRequest { Level = LogLevel.Info, Time = DateTime.UtcNow, Text = this.StepContext.StepInfo.GetFullText() }; var eventArg = new StepStartedEventArgs(Bridge.Service, stepInfoRequest, null); ReportPortalAddin.OnBeforeStepStarted(this, eventArg); if (!eventArg.Canceled) { currentScenario.Log(stepInfoRequest); ReportPortalAddin.OnAfterStepStarted(this, eventArg); } } }
public static void BeforeFeature(FeatureContext featureContext) { if (Bridge.Context.LaunchReporter != null) { lock (LockHelper.GetLock(FeatureInfoEqualityComparer.GetFeatureInfoHashCode(featureContext.FeatureInfo))) { var currentFeature = ReportPortalAddin.GetFeatureTestReporter(featureContext); if (currentFeature == null || currentFeature.FinishTask != null) { var request = new StartTestItemRequest { Name = featureContext.FeatureInfo.Title, Description = featureContext.FeatureInfo.Description, StartTime = DateTime.UtcNow, Type = TestItemType.Suite, Tags = new List <string>(featureContext.FeatureInfo.Tags) }; var eventArg = new TestItemStartedEventArgs(Bridge.Service, request); ReportPortalAddin.OnBeforeFeatureStarted(null, eventArg); if (!eventArg.Canceled) { currentFeature = Bridge.Context.LaunchReporter.StartNewTestNode(request); ReportPortalAddin.SetFeatureTestReporter(featureContext, currentFeature); ReportPortalAddin.OnAfterFeatureStarted(null, new TestItemStartedEventArgs(Bridge.Service, request, currentFeature)); } } else { ReportPortalAddin.IncrementFeatureThreadCount(featureContext); } } } }
public void AfterScenario() { var currentScenario = ReportPortalAddin.GetScenarioTestReporter(this.ScenarioContext); if (currentScenario != null) { Issue issue = null; var status = Status.Passed; switch (this.ScenarioContext.ScenarioExecutionStatus) { case ScenarioExecutionStatus.TestError: status = Status.Failed; issue = new Issue { Type = WellKnownIssueType.ToInvestigate, Comment = this.ScenarioContext.TestError?.Message }; currentScenario.Log(new AddLogItemRequest { Level = LogLevel.Error, Time = DateTime.UtcNow, Text = this.ScenarioContext.TestError?.ToString() }); break; case ScenarioExecutionStatus.BindingError: status = Status.Failed; issue = new Issue { Type = WellKnownIssueType.AutomationBug, Comment = this.ScenarioContext.TestError?.Message }; currentScenario.Log(new AddLogItemRequest { Level = LogLevel.Error, Time = DateTime.UtcNow, Text = this.ScenarioContext.TestError?.Message }); break; case ScenarioExecutionStatus.UndefinedStep: status = Status.Failed; issue = new Issue { Type = WellKnownIssueType.AutomationBug, Comment = new MissingStepDefinitionException().Message }; currentScenario.Log(new AddLogItemRequest { Level = LogLevel.Error, Time = DateTime.UtcNow, Text = new MissingStepDefinitionException().Message }); break; case ScenarioExecutionStatus.StepDefinitionPending: status = Status.Failed; issue = new Issue { Type = WellKnownIssueType.ToInvestigate, Comment = "Pending" }; break; } var request = new FinishTestItemRequest { EndTime = DateTime.UtcNow.AddMilliseconds(1), Status = status, Issue = issue }; var eventArg = new TestItemFinishedEventArgs(Bridge.Service, request, currentScenario); ReportPortalAddin.OnBeforeScenarioFinished(this, eventArg); if (!eventArg.Canceled) { currentScenario.Finish(request); currentScenario.FinishTask.Wait(); ReportPortalAddin.OnAfterScenarioFinished(this, new TestItemFinishedEventArgs(Bridge.Service, request, currentScenario)); } } }
public void AfterScenario() { try { var currentScenario = ReportPortalAddin.GetScenarioTestReporter(this.ScenarioContext); if (currentScenario != null) { if (this.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.TestError) { currentScenario.Log(new CreateLogItemRequest { Level = LogLevel.Error, Time = DateTime.UtcNow, Text = this.ScenarioContext.TestError?.ToString() }); } else if (this.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.BindingError) { currentScenario.Log(new CreateLogItemRequest { Level = LogLevel.Error, Time = DateTime.UtcNow, Text = this.ScenarioContext.TestError?.Message }); } else if (this.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.UndefinedStep) { currentScenario.Log(new CreateLogItemRequest { Level = LogLevel.Error, Time = DateTime.UtcNow, Text = new MissingStepDefinitionException().Message }); } Issue issue = null; // determine scenario status var status = this.ScenarioContext.ScenarioExecutionStatus == ScenarioExecutionStatus.OK ? Status.Passed : Status.Failed; // handle well-known unit framework's ignore exceptions if (this.ScenarioContext.TestError != null) { var testErrorException = this.ScenarioContext.TestError.GetType(); if (testErrorException.FullName.Equals("NUnit.Framework.IgnoreException") || testErrorException.FullName.Equals("NUnit.Framework.InconclusiveException") || testErrorException.FullName.Equals("Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException") || testErrorException.FullName.Equals("Xunit.SkipException")) { status = Status.Skipped; issue = new Issue { Type = WellKnownIssueType.NotDefect, Comment = this.ScenarioContext.TestError.Message }; } } var request = new FinishTestItemRequest { EndTime = DateTime.UtcNow, Status = status, Issue = issue }; var eventArg = new TestItemFinishedEventArgs(_service, request, currentScenario, this.FeatureContext, this.ScenarioContext); ReportPortalAddin.OnBeforeScenarioFinished(this, eventArg); if (!eventArg.Canceled) { currentScenario.Finish(request); ReportPortalAddin.OnAfterScenarioFinished(this, new TestItemFinishedEventArgs(_service, request, currentScenario, this.FeatureContext, this.ScenarioContext)); ReportPortalAddin.RemoveScenarioTestReporter(this.ScenarioContext, currentScenario); } } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } finally { ContextAwareLogHandler.ActiveScenarioContext = null; } }
public void BeforeScenario() { try { ContextAwareLogHandler.ActiveScenarioContext = this.ScenarioContext; var currentFeature = ReportPortalAddin.GetFeatureTestReporter(this.FeatureContext); if (currentFeature != null) { var request = new StartTestItemRequest { Name = this.ScenarioContext.ScenarioInfo.Title, Description = this.ScenarioContext.ScenarioInfo.Description, StartTime = DateTime.UtcNow, Type = TestItemType.Step, Attributes = this.ScenarioContext.ScenarioInfo.Tags?.Select(t => new ItemAttributeConverter().ConvertFrom(t, (opts) => opts.UndefinedKey = "Tag")).ToList(), }; // fetch scenario parameters (from Examples block) var arguments = this.ScenarioContext.ScenarioInfo.Arguments; if (arguments != null && arguments.Count > 0) { request.Parameters = new List <KeyValuePair <string, string> >(); foreach (DictionaryEntry argument in arguments) { request.Parameters.Add(new KeyValuePair <string, string> ( argument.Key.ToString(), argument.Value.ToString() )); } // append scenario outline parameters to description var parametersInfo = new StringBuilder(); parametersInfo.Append("|"); foreach (var p in request.Parameters) { parametersInfo.Append(p.Key); parametersInfo.Append("|"); } parametersInfo.AppendLine(); parametersInfo.Append("|"); foreach (var p in request.Parameters) { parametersInfo.Append("---"); parametersInfo.Append("|"); } parametersInfo.AppendLine(); parametersInfo.Append("|"); foreach (var p in request.Parameters) { parametersInfo.Append("**"); parametersInfo.Append(p.Value); parametersInfo.Append("**"); parametersInfo.Append("|"); } if (string.IsNullOrEmpty(request.Description)) { request.Description = parametersInfo.ToString(); } else { request.Description = parametersInfo.ToString() + Environment.NewLine + Environment.NewLine + request.Description; } } var eventArg = new TestItemStartedEventArgs(_service, request, currentFeature, this.FeatureContext, this.ScenarioContext); ReportPortalAddin.OnBeforeScenarioStarted(this, eventArg); if (!eventArg.Canceled) { var currentScenario = currentFeature.StartChildTestReporter(request); ReportPortalAddin.SetScenarioTestReporter(this.ScenarioContext, currentScenario); ReportPortalAddin.OnAfterScenarioStarted(this, new TestItemStartedEventArgs(_service, request, currentFeature, this.FeatureContext, this.ScenarioContext)); } } } catch (Exception exp) { _traceLogger.Error(exp.ToString()); } }