jonsamwell / flutter_gherkin

A Gherkin parsers and runner for Dart and Flutter which is very similar to cucumber
MIT License
206 stars 112 forks source link

[Enhancement ] Access to feature files information from hooks #242

Open youssef-t opened 2 years ago

youssef-t commented 2 years ago

Hi,

I think that it would be helpful to have access to the information (mainly the file path) of the feature file that is being tested at runtime from hooks. For now, it's only accessible from the "Reporter" class.

For example, having this functionnality would help a lot to load some configuration file that is associated with certain features, and a tag would be used to indicate that there is a configuration to be loaded before or after the feature.

This issue concerns the access to this variable: https://github.com/jonsamwell/flutter_gherkin/blob/7ee9f801d1ddd201a95d46fa6130a86ab209ebb0/lib/src/flutter/runners/gherkin_integration_test_runner.dart#L132

Thank you,

jonsamwell commented 2 years ago

Yep agree with this. I should have some time next week to look at this, alternatively feel free to do a pr

youssef-t commented 2 years ago

I could not find a proper solution without making changes that would impact the current implementation of hooks. I think that making a big change only for this simple feature is not worth it.

I think that a work-around to get the feature file path at runtime (for the package users) is to define a custom "Reporter" that implements "FeatureReporter". This reporter sets a variable containing the path of the feature file. Then, the hooks can access to this variable if they need to. I have to admit that this work-around is not the cleanest one.

I would love to hear your opinion about this.

jonsamwell commented 2 years ago

Let me have a think about this. I am not adverse to altering the hooks if it provides useful information.

AFASbart commented 1 year ago

This information you want about a feature file, could maybe be set in a global variable in the Reporter class? Then you can access it whenever you want, I feel that could be a very clean solution.

youssef-t commented 1 year ago

@AFASbart That's exactly what I have been doing. This work-around works fine unless the first scenario is ignored because of a tag exepression. The issue #278 explains the root cause of the problem.

The method onBeforeRunFeature of the Reporter class is the only method that can be used in order to set the global variable about the feature file path before for the hooks.

The method onStarted is not suitable because it's run after calling the hooks that are run before the scenario. https://github.com/jonsamwell/flutter_gherkin/blob/7c8be5f60e987e858d36502cc97af9a4ec7a5c66/lib/src/flutter/runners/gherkin_integration_test_runner.dart#L213

In my opinion, there is three solutions for the issue: 1- The most extreme one: altering the hooks by having another parameter of type RunnableDebugInformation like some methods of the Reporter class. 2- Fixing the issue #278. 3- Calling the reporters before the hooks in the method runScenario : https://github.com/jonsamwell/flutter_gherkin/blob/7c8be5f60e987e858d36502cc97af9a4ec7a5c66/lib/src/flutter/runners/gherkin_integration_test_runner.dart#L168

The third solution is the simplest one as it will allow us to set a global variable about the feature file path before calling the hooks of any scenario without worrying about the issue #278.