Skip to content

Commit

Permalink
Report concepts as nested steps
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Feb 1, 2024
1 parent 537c4b6 commit 4c2f216
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
68 changes: 68 additions & 0 deletions src/ReportPortal.GaugePlugin/Results/Sender.Concepts.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <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.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<ITestReporter> 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);
}
}
}
}
6 changes: 4 additions & 2 deletions src/ReportPortal.GaugePlugin/Results/Sender.Steps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
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 4c2f216

Please sign in to comment.