Cucumber Before All and After All Hooks

Profile picture for user devraj

In Cucumber version 7.0.0, Before All and After All, Hooks are implemented. BeforeAll run before any scenario is run, and AfterAll run after all scenarios have been executed.

@BeforeAll and @AfterAll hooks are similar to @BeforeSuite and @AfterSuite annotations of TestNG. You can use these global hooks where global setup or cleanup is required. For example, setting up environment variables, database or reporter configuration, and cleanup.


You need to use static in method name unlike other hooks.



public static void beforeAll() {
    // Runs before all scenarios

After All


public static void afterAll() {
    // Runs after all scenarios

Video Tutorial: Cucumber BeforeAll AfterAll Hooks