Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Capture method with stream id for datastore setup #236

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Executors/ExecutionOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<ProtoExecutionResult> ExecuteStep(GaugeMethod method, int stre
var stopwatch = Stopwatch.StartNew();

var executionResult = await _stepExecutor.Execute(method, streamId, args);
return BuildResult(stopwatch, executionResult);
return BuildResult(stopwatch, executionResult, streamId);
}

public void ClearCache()
Expand Down Expand Up @@ -81,10 +81,10 @@ public async Task<ProtoExecutionResult> ExecuteHooks(string hookType, HooksStrat
{
var stopwatch = Stopwatch.StartNew();
var executionResult = await _hookExecutor.Execute(hookType, strategy, applicableTags, streamId, info);
return BuildResult(stopwatch, executionResult);
return BuildResult(stopwatch, executionResult, streamId);
}

private ProtoExecutionResult BuildResult(Stopwatch stopwatch, ExecutionResult executionResult)
private ProtoExecutionResult BuildResult(Stopwatch stopwatch, ExecutionResult executionResult, int streamId)
{
var result = new ProtoExecutionResult
{
Expand Down Expand Up @@ -112,7 +112,7 @@ private ProtoExecutionResult BuildResult(Stopwatch stopwatch, ExecutionResult ex
result.Failed = true;
if (_config.ScreenshotOnFailure())
{
var screenshotFile = TryScreenCapture();
var screenshotFile = TryScreenCapture(streamId);
if (!string.IsNullOrEmpty(screenshotFile))
{
result.FailureScreenshotFile = screenshotFile;
Expand All @@ -124,11 +124,11 @@ private ProtoExecutionResult BuildResult(Stopwatch stopwatch, ExecutionResult ex
return result;
}

private string TryScreenCapture()
private string TryScreenCapture(int streamId)
{
try
{
InvokeScreenshotCapture();
InvokeScreenshotCapture(streamId);
}
catch (Exception ex)
{
Expand All @@ -140,9 +140,15 @@ private string TryScreenCapture()
BindingFlags.Static | BindingFlags.Public) as IEnumerable<string>).FirstOrDefault();
}

private void InvokeScreenshotCapture()
private void InvokeScreenshotCapture(int streamId)
{
var gaugeScreenshotsType = _assemblyLoader.GetLibType(LibType.GaugeScreenshots);
var methodInfo = _reflectionWrapper.GetMethod(gaugeScreenshotsType, "CaptureByStream", BindingFlags.Static | BindingFlags.Public);
if (methodInfo != null)
{
_reflectionWrapper.Invoke(methodInfo, null, streamId);
return;
}
_reflectionWrapper.InvokeMethod(gaugeScreenshotsType, null, "Capture",
BindingFlags.Static | BindingFlags.Public);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Gauge.Dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<PackageId>Runner.NetCore30</PackageId>
<Authors>The Gauge Team</Authors>
<Version>0.7.0</Version>
<Version>0.7.1</Version>
<Company>ThoughtWorks Inc.</Company>
<Product>Gauge</Product>
<Description>C# runner for Gauge. https://gauge.org</Description>
Expand Down
21 changes: 10 additions & 11 deletions src/Wrappers/IReflectionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
*----------------------------------------------------------------*/


using System;
using System.Reflection;

namespace Gauge.Dotnet.Wrappers
namespace Gauge.Dotnet.Wrappers;

public interface IReflectionWrapper
{
public interface IReflectionWrapper
{
MethodInfo GetMethod(Type type, string methodName);
MethodInfo[] GetMethods(Type type);
object Invoke(MethodInfo method, object obj, params object[] args);
MethodInfo GetMethod(Type type, string methodName);
MethodInfo GetMethod(Type type, string methodName, BindingFlags bindAttrs);
MethodInfo[] GetMethods(Type type);
object Invoke(MethodInfo method, object obj, params object[] args);

object InvokeMethod(Type type, object instance, string methodName, BindingFlags bindAttrs,
params object[] args);
object InvokeMethod(Type type, object instance, string methodName, BindingFlags bindAttrs,
params object[] args);

object InvokeMethod(Type type, object instance, string methodName, params object[] args);
}
object InvokeMethod(Type type, object instance, string methodName, params object[] args);
}
5 changes: 5 additions & 0 deletions src/Wrappers/ReflectionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public MethodInfo GetMethod(Type type, string methodName)
return type.GetMethod(methodName);
}

public MethodInfo GetMethod(Type type, string methodName, BindingFlags bindAttrs)
{
return type.GetMethod(methodName, bindAttrs);
}

public MethodInfo[] GetMethods(Type type)
{
return type.GetMethods();
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "dotnet",
"version": "0.7.0",
"version": "0.7.1",
"description": "C# support for gauge + .NET 6.0/7.0/8.0",
"run": {
"windows": [
Expand Down