question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Feature file and Feature name in Before hook

See original GitHub issue

I’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:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
zhtaoangcommented, Jan 26, 2017

There is a “scenarioId” in the scenario object, which contains both feature name and scenario name. Try using “scenario.getId()” to get them.

1reaction
tompahowardcommented, May 18, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found