Closed zephirus closed 1 month ago
What sort of code would you need to run? If it is for reporting purposes you might be interested in using the plugin system.
I have N scenarios in my feature files. Currently, I have an additional scenario at the end of each feature that is all the same in every feature (most of them) and must run ONLY at the end of the feature file.
It sounds like your scenarios are not independent. Cucumber is designed with the assumption that all scenarios are independent. This is generally a good practice when testing. So making it easier to work with dependent scenarios is not something we would like spend time on supporting.
But you can turn your dependent scenarios into a single scenario and then use the regular after scenario hook. There are a few ways to do that
Note: I'm making some assumptions about your situation here. But dependent scenarios and low level steps are frequently used together.
Putting all scenarios in a single one is not a good solution. It makes organization worst. It seems to me that @AfterFeature is really super usefull.
A single hig level scenario doesn't really affect organisation. Assuming you organize the code that executes the high level steps cleanly.
But this is going a bit beyond a feature request.
Wait. My scenarios can run independently. But I don't want to run a certain code after each one, only after the last one. Why do I need to put it there explicitly when I have hundreds of features and that code is the same? That is the purpose of After and Before right?
But I don't want to run a certain code after each one, only after the last one.
Why not? And why specifically run at the end of feature file? And not say after every 10 scenarios from any feature? It shouldn't really matter if the scenarios are independent right?
From an implementation perspective, Cucumber doesn't execute features. Only pickles (scenario's and examples) are executed. Additionally it wouldn't quite work when executing in parallel. Feature hooks for different features would interleave in the same context.
Ok I understand that. The purpose is to all be independent. I don't want to change that.
🤔 What's the problem you're trying to solve?
I think this is something that would give extra power to Cucumber. In my personal case, I need to run some code only after each feature ends all scenarios, both passed or failed.
✨ What's your proposed solution?
My proposal is to have these two hooks in alignment with what already exists for the Before and After and BeforeStep and AfterStep.
⛏ Have you considered any alternatives or workarounds?
I tried to get the number of scenarios in my feature file at the beginning and then use that information to use the already available @After and then run my code but that is also that I can't do. I didn't found any way to get the number of scenarios in a feature file.
📚 Any additional context?
No response