A Cucumber tag expression is a boolean expression that selects scenarios or features by their tags. A hook can match one tag, such as @web, or combine tags with and and not. section 8.5.2
Use tag expressions to control scenario-specific test setup and cleanup:
- Run browser-opening and browser-closing hooks only for scenarios tagged @web. section 8.5.2
- Combine conditions such as @web and @smoketest or @web and not @backend. section 8.5.2
A web-only hook
Tag a scenario with @web, then configure @Before("@web") to create a ChromeDriver and @After("@web") to close it. Non-web scenarios avoid that browser setup. section 8.5.2
Listing 8.21 Hook methods that only run for specific scenarios
WebDriver driver;
@Before("@web")
public void prepareDriver() { #1
driver = new ChromeDriver();
}
@After("@web") #2
public void closeBrowser() {
driver.quit();
}
Shows tag expressions attached directly to Cucumber lifecycle hooks. section 8.5.2
