flutter_gherkin icon indicating copy to clipboard operation
flutter_gherkin copied to clipboard

[Enhancement ] Access to feature files information from hooks

Open youssef-t opened this issue 3 years ago • 5 comments

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,

youssef-t avatar Jul 04 '22 11:07 youssef-t

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

jonsamwell avatar Jul 06 '22 05:07 jonsamwell

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.

youssef-t avatar Jul 06 '22 15:07 youssef-t

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

jonsamwell avatar Jul 08 '22 05:07 jonsamwell

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.

AFASbart avatar Dec 07 '22 13:12 AFASbart

@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.

youssef-t avatar Dec 15 '22 12:12 youssef-t