Search code examples
javacucumberbddcucumber-jvm

Cucumber JVM - get reference to all scenarios


is there possibility to get reference to ALL scenarios in Cucumber JVM?

Problem: I need to pragmatically count some statistics about scenarios (failed, total count, etc)

For failed, I could create @After hook, and bump variable that holds number of failed scenarios:

@After(order = 1)
public void onScenarioFinished(Scenario scenario)
{
    if (scenario.isFailed())
    {
        failedScenarios++;
    }
} 

But is there possibility to access all 'Scenario' objects that cucumber loaded?


Solution

  • Solved it by creating @Before hook, that adds scenario reference to the list.

    This way I have reference to all scenarios that were started.

    List<Scenario> scenarios = new ArrayList();
    
    @Before(order = 0)
    public void onScenarioStarted(Scenario scenario)
    {
        scenarios.add(Scenario);
    }