diff --git a/src/ReportPortal.GaugePlugin/Extensions/StepNameExtensions.cs b/src/ReportPortal.GaugePlugin/Extensions/StepNameExtensions.cs index 9252d33..0d501a1 100644 --- a/src/ReportPortal.GaugePlugin/Extensions/StepNameExtensions.cs +++ b/src/ReportPortal.GaugePlugin/Extensions/StepNameExtensions.cs @@ -1,32 +1,28 @@ using Gauge.Messages; -using System.Text; namespace ReportPortal.GaugePlugin.Extensions { internal static class StepNameExtensions { - public static string GetStepName(this ProtoStep step) + public static string GetStepName(this ExecuteStepRequest step) { - if (step.Fragments is not null) + if (step.Parameters is not null) { - var stepNameBuilder = new StringBuilder(); + var stepName = step.ParsedStepText; - foreach (var fragment in step.Fragments) + foreach (var parameter in step.Parameters) { - if (fragment.FragmentType == Fragment.Types.FragmentType.Text) - { - stepNameBuilder.Append(fragment.Text); - } - else if (fragment.FragmentType == Fragment.Types.FragmentType.Parameter) - { - stepNameBuilder.AppendFormat("`{0}`", fragment.Parameter.Value); - } + var startIndex = stepName.IndexOf("{}"); + + stepName = stepName.Remove(startIndex, 2).Insert(startIndex, $"`{parameter.Value}`"); } - return stepNameBuilder.ToString(); + return stepName; + } + else + { + return step.ActualStepText; } - - return step.ActualText; } } } diff --git a/src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs b/src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs new file mode 100644 index 0000000..bbee03e --- /dev/null +++ b/src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs @@ -0,0 +1,69 @@ +using Gauge.Messages; +using ReportPortal.Client.Abstractions.Models; +using ReportPortal.Client.Abstractions.Requests; +using ReportPortal.GaugePlugin.Extensions; +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.TryGetValue(scenarioKey, out var concepts) ? concepts.Last() : _scenarios[scenarioKey]; + + var conceptReporter = parentReporter.StartChildTestReporter(new StartTestItemRequest + { + Name = request.CurrentExecutionInfo.CurrentStep.Step.GetStepName(), + StartTime = DateTime.UtcNow, + HasStats = false + }); + + if (concepts is not null) + { + 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 c297f1f..e3fd120 100644 --- a/src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs +++ b/src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs @@ -21,9 +21,11 @@ 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 stepName = stepResult.ProtoItem.Step.GetStepName(); + var parentReporter = _scenarioConcepts.TryGetValue(scenarioKey, out System.Collections.Generic.List concept) ? concept.Last() : _scenarios[scenarioKey]; + + var stepName = request.CurrentExecutionInfo.CurrentStep.Step.GetStepName(); #region step parameter if (stepResult.ProtoItem.Step.Fragments != null) @@ -35,7 +37,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) {