Get Feature file and Feature name in Before hook
See original GitHub issueI’d like to be able the obtain the feature file name and Feature name in the @Before
hook for logging purposes.
Something like the existing Scenario
object:
@Before("@Before")
public void beforeScenario(Feature feature, Scenario scenario) {
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:7 (1 by maintainers)
Top Results From Across the Web
how to get current Cucumber feature file name at runtime ...
As a workaround add the feature file name as a tag to the feature file with some kind of identifier. Then you can...
Read more >What are Cucumber Hooks And How to Use ... - Tools QA
Unlike TestNG Annotations, cucumber supports only two hooks (Before & After) which works at the start and the end of the test scenario....
Read more >[Cucumber JVM] need feature and scenario name at run time
When I try using Before hooks with both Scenario and Feature, it throws an error 'Hooks must declare 0 or 1 arguments' How...
Read more >[Cucumber] [Cucumber JVM] how to extract feature and ...
import cucumber.api.java.Before; @Before public void before(Scenario s) { ... get the Feature name in the Before Hook to set the BatchInfo object in...
Read more >Run Cucumber tests | IntelliJ IDEA Documentation - JetBrains
In the Project tool window ( Alt+1 ), right-click a feature file and select Run Feature <name>. Run all feature files in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a “scenarioId” in the scenario object, which contains both feature name and scenario name. Try using “scenario.getId()” to get them.
Sorry to resurrect this, but
scenario.getId()
does provides a sanitised version of the feature name, not the actual feature name. For instance, For a feature called “TestCase0.0 Basic” and a scenario “Basic”,scenario.getId()
provides “testcase0.0-basic;basic” not “TestCase0.0 Basic;Basic”However
scenario.getName()
does correctly return “Basic”This issue has been tagged “Won’t Fix”. If possible, it would be great to get a explanation so we can understand why getting the Feature name would be a bad thing to do.