From 7a00d135065ea67bdd4b15592221b3cfa2cf5447 Mon Sep 17 00:00:00 2001 From: Martin Pekurny Date: Mon, 23 Sep 2024 13:50:36 -0400 Subject: [PATCH] Calling Capture method with stream id for datastore setup Signed-off-by: Martin Pekurny --- src/Executors/ExecutionOrchestrator.cs | 20 +++++++++++++------- src/Gauge.Dotnet.csproj | 2 +- src/Wrappers/IReflectionWrapper.cs | 21 ++++++++++----------- src/Wrappers/ReflectionWrapper.cs | 5 +++++ src/dotnet.json | 2 +- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/Executors/ExecutionOrchestrator.cs b/src/Executors/ExecutionOrchestrator.cs index 3c19ed5b..1ab0b571 100644 --- a/src/Executors/ExecutionOrchestrator.cs +++ b/src/Executors/ExecutionOrchestrator.cs @@ -44,7 +44,7 @@ public async Task 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() @@ -81,10 +81,10 @@ public async Task 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 { @@ -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; @@ -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) { @@ -140,9 +140,15 @@ private string TryScreenCapture() BindingFlags.Static | BindingFlags.Public) as IEnumerable).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); } diff --git a/src/Gauge.Dotnet.csproj b/src/Gauge.Dotnet.csproj index fc013a3e..761c9f56 100644 --- a/src/Gauge.Dotnet.csproj +++ b/src/Gauge.Dotnet.csproj @@ -6,7 +6,7 @@ enable Runner.NetCore30 The Gauge Team - 0.7.0 + 0.7.1 ThoughtWorks Inc. Gauge C# runner for Gauge. https://gauge.org diff --git a/src/Wrappers/IReflectionWrapper.cs b/src/Wrappers/IReflectionWrapper.cs index af45cb52..34787530 100644 --- a/src/Wrappers/IReflectionWrapper.cs +++ b/src/Wrappers/IReflectionWrapper.cs @@ -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); } \ No newline at end of file diff --git a/src/Wrappers/ReflectionWrapper.cs b/src/Wrappers/ReflectionWrapper.cs index eaf9dc74..b0ea21a6 100644 --- a/src/Wrappers/ReflectionWrapper.cs +++ b/src/Wrappers/ReflectionWrapper.cs @@ -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(); diff --git a/src/dotnet.json b/src/dotnet.json index bb9fdff7..a68be892 100644 --- a/src/dotnet.json +++ b/src/dotnet.json @@ -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": [