getgauge / gauge-dotnet

C# runner for gauge + DotNet standard 6.0-8.0
Apache License 2.0
27 stars 21 forks source link

Add error message/stacktrace to context? #190

Open jensakejohansson opened 2 years ago

jensakejohansson commented 2 years ago

Hi!

I'm able to check if a test is failing in the AfterScenario-hook by the CurrentScenario.IsFailing property. Is it possible to also expose the stacktrace/error message/exception in the context object? The stacktrace is logged by Gauge to file/stdout, but I'd like to be able to fetch it at "teardown" to have more freedom & control since the logging basically happens after I've "lost control" of the execution.

Typically I want to be able to easily send the error/stacktrace-message together with screenshot, scenarioname etc to 3rd-party tools during a test run. We also want to be able to write it to our "own" logfiles. I have no deeper understanding of the Gauge-impl and when the different properties actually receives their values, but after a brief look at the gauge-dotnet source it seems like it could be added as information to hook-context easily? It's just not included at the moment. In my opionen the context should be populated with as much runtime information as possible :)

sriv commented 2 years ago

Hi, thanks for the feedback. I agree that the context could be enriched further.

but after a brief look at the gauge-dotnet source it seems like it could be added as information to hook-context easily?

This is not a change in gauge-dotnet alone, since the ExecutionContext is also populated by gauge. gauge-dotnet receives the context from gauge.

The lifecycle is roughly BeforeScenario -> Scenario -> AfterScenario. gauge-dotnet does not maintain the state, since gauge is the one orchestrating this. So, when a scenario fails, the stacktrace needs to be sent back to gauge, which then sends it over to the hooks.

This is not a complicated change, but will require changing both gauge and gauge-dotnet as well as the contract (proto files).

jensakejohansson commented 2 years ago

I see. Would it be possible to ask you to create an appropriate change request on Gauge - you know what to technically ask for - so that you (or some other maintainer of the C#-parts) later can added it to C#? I would be very greatful!

It thought of trying to do a hack and add it myself, but since it seems like changes are needed in Gauge (which is written in Go of which I have no experience), Gauge-DotNet, Gauge-CSharp-Lib (I suppose), so it will probably take me a long time to understand how all this comes together and I'd have to maintain my own code/fork of all this which also is not very appealing...