Search code examples
javacucumbercucumber-jvmcucumber-java

How to hook Cucumber-Java life cycle


I need a way to execute some code before each cucumber scenarios start and know which scenario is about to start, to make the executed code specific to this scenario.

I have try to override the Cucumber runner to create a hook without success.
Do you have any solution for me ?


Solution

  • Anything you write inside @Before is executed before every Scenario. Then, you could get especific scenario info using getName() for instance.

    @Before
    public void before(Scenario scenario) {
        String scenarioName = scenario.getName();
    }
    

    Take a look to this example I've made and see working Hooks.