Getting filtered scenarios at runtime #2263
-
How can I get a list of running scenarios (after filtering, for example, by tags) at runtime? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
It depends. How are you running Cucumber? And what do you mean by running? Do you mean a list of scenarios that will be executed prior to execution? Or some sort of progress bar that shows you which scenarios are being executed right now? |
Beta Was this translation helpful? Give feedback.
-
I'm running Cucumber as a JUnit 5 suite. I need to add some logic to @BefallAll based on which directory the scenarios are run from. |
Beta Was this translation helpful? Give feedback.
-
The problem is that I have one suite for all tests, among which there may be those that need additional logic in @BeforeAll. As far as I know we have a feature file parser or something like that available. |
Beta Was this translation helpful? Give feedback.
There is an implicit assumption in Maven/Gradle, JUnit and Cucumber that tests are independent. If you stay within that tool chain, what you're looking to do isn't really possible.
However, if you don't mind launching your tests from a
main
method instead, you could use JUnits Launcher API.https://docs.junit.org/current/user-guide/#launcher-api
Prior to execution, the launcher API can provide a test plan. You can inspect that test plan and work out the requirements for your setup. Once you've completed the setup you can ask JUnit to execute the test plan. Cucumber provides tags and file names to JUnit so you can make decisions based of those.
You'd run all this from a main method which y…