-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Concepts reporting as nested steps (#64)
- Loading branch information
1 parent
a5b43bd
commit 1f9e3e6
Showing
4 changed files
with
88 additions
and
21 deletions.
There are no files selected for viewing
28 changes: 12 additions & 16 deletions
28
src/ReportPortal.GaugePlugin/Extensions/StepNameExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters