Skip to content

Commit

Permalink
Concepts reporting as nested steps (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko authored Feb 2, 2024
1 parent a5b43bd commit 1f9e3e6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 21 deletions.
28 changes: 12 additions & 16 deletions src/ReportPortal.GaugePlugin/Extensions/StepNameExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
69 changes: 69 additions & 0 deletions src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Assuming scenario might have only on running concept.
/// </summary>
private readonly ConcurrentDictionary<ScenarioKey, List<ITestReporter>> _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);
}
}
}
}
8 changes: 5 additions & 3 deletions src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITestReporter> concept) ? concept.Last() : _scenarios[scenarioKey];

var stepName = request.CurrentExecutionInfo.CurrentStep.Step.GetStepName();

#region step parameter
if (stepResult.ProtoItem.Step.Fragments != null)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public override Task<Empty> NotifyConceptExecutionStarting(ConceptExecutionStart
TraceLogger.Info($"{nameof(NotifyConceptExecutionStarting)} received");
TraceLogger.Verbose(request.ToString());

// do nothing for now
_sender.StartConcept(request);
}
catch (Exception exp)
{
Expand All @@ -163,7 +163,7 @@ public override Task<Empty> NotifyConceptExecutionEnding(ConceptExecutionEndingR
TraceLogger.Info($"{nameof(NotifyConceptExecutionEnding)} received");
TraceLogger.Verbose(request.ToString());

// do nothing for now
_sender.FinishConcept(request);
}
catch (Exception exp)
{
Expand Down

0 comments on commit 1f9e3e6

Please sign in to comment.