From 4c2f216cf1386daa3f5d40dfeeaae173cd88adc5 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko Date: Thu, 1 Feb 2024 23:06:17 +0300 Subject: [PATCH] Report concepts as nested steps --- .../Results/Sender.Concepts.cs | 68 +++++++++++++++++++ .../Results/Sender.Steps.cs | 6 +- .../Services/ReportMessagesHandler.cs | 4 +- 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs diff --git a/src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs b/src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs new file mode 100644 index 0000000..beb58a6 --- /dev/null +++ b/src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs @@ -0,0 +1,68 @@ +using Gauge.Messages; +using ReportPortal.Client.Abstractions.Models; +using ReportPortal.Client.Abstractions.Requests; +using ReportPortal.Shared.Reporter; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; + +namespace ReportPortal.GaugePlugin.Results +{ + partial class Sender + { + /// + /// Assuming scenario might have only on running concept. + /// + private readonly ConcurrentDictionary> _scenarioConcepts = new(); + + public void StartConcept(ConceptExecutionStartingRequest request) + { + var scenarioKey = GetScenarioKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario); + + var parentReporter = _scenarioConcepts.ContainsKey(scenarioKey) ? _scenarioConcepts[scenarioKey].Last() : _scenarios[scenarioKey]; + + var conceptReporter = parentReporter.StartChildTestReporter(new StartTestItemRequest + { + Name = request.CurrentExecutionInfo.CurrentStep.Step.ParsedStepText, + StartTime = DateTime.UtcNow, + HasStats = false + }); + + if (_scenarioConcepts.TryGetValue(scenarioKey, out List concepts)) + { + concepts.Add(conceptReporter); + } + else + { + _scenarioConcepts[scenarioKey] = [conceptReporter]; + } + } + + public void FinishConcept(ConceptExecutionEndingRequest request) + { + var scenarioKey = GetScenarioKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario); + + var conceptReporter = _scenarioConcepts[scenarioKey].Last(); + + var status = request.CurrentExecutionInfo.CurrentScenario.IsFailed ? Status.Failed : Status.Passed; + + conceptReporter.Finish(new FinishTestItemRequest + { + Status = status, + EndTime = DateTime.UtcNow + }); + + var concepts = _scenarioConcepts[scenarioKey]; + + if (concepts.Count == 1) + { + _scenarioConcepts.Remove(scenarioKey, out _); + } + else + { + concepts.Remove(conceptReporter); + } + } + } +} diff --git a/src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs b/src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs index 9afd8b0..e1968cd 100644 --- a/src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs +++ b/src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs @@ -20,7 +20,9 @@ public void StartStep(StepExecutionStartingRequest request) var key = GetStepKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario, request.CurrentExecutionInfo.CurrentStep); TraceLogger.Verbose($"Starting step with key: {key}"); - var scenarioReporter = _scenarios[GetScenarioKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario)]; + var scenarioKey = GetScenarioKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario); + + var parentReporter = _scenarioConcepts.ContainsKey(scenarioKey) ? _scenarioConcepts[scenarioKey].Last() : _scenarios[scenarioKey]; var stepName = stepResult.ProtoItem.Step.ActualText; @@ -34,7 +36,7 @@ public void StartStep(StepExecutionStartingRequest request) } #endregion - var stepReporter = scenarioReporter.StartChildTestReporter(new StartTestItemRequest + var stepReporter = parentReporter.StartChildTestReporter(new StartTestItemRequest { Type = TestItemType.Step, StartTime = DateTime.UtcNow, diff --git a/src/ReportPortal.GaugePlugin/Services/ReportMessagesHandler.cs b/src/ReportPortal.GaugePlugin/Services/ReportMessagesHandler.cs index 250acee..9dfc89a 100644 --- a/src/ReportPortal.GaugePlugin/Services/ReportMessagesHandler.cs +++ b/src/ReportPortal.GaugePlugin/Services/ReportMessagesHandler.cs @@ -146,7 +146,7 @@ public override Task NotifyConceptExecutionStarting(ConceptExecutionStart TraceLogger.Info($"{nameof(NotifyConceptExecutionStarting)} received"); TraceLogger.Verbose(request.ToString()); - // do nothing for now + _sender.StartConcept(request); } catch (Exception exp) { @@ -163,7 +163,7 @@ public override Task NotifyConceptExecutionEnding(ConceptExecutionEndingR TraceLogger.Info($"{nameof(NotifyConceptExecutionEnding)} received"); TraceLogger.Verbose(request.ToString()); - // do nothing for now + _sender.FinishConcept(request); } catch (Exception exp) {