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.
Syntax
You need to use static in method name unlike other hooks.
BeforeAll
import io.cucumber.java.BeforeAll;
@BeforeAll
public static void beforeAll() {
// Runs before all scenarios
}
After All
import io.cucumber.java.AfterAll;
@AfterAll
public static void afterAll() {
// Runs after all scenarios
}