liveBook · Manning

Tag expression

As explained in BDD in Action, Second Edition

A Cucumber tag expression is a boolean expression used to select scenarios or features based on their tags.

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

How BDD in Action, Second Edition covers it

How deep it goes
Defines single-tag and boolean combinations, then applies them to Java and TypeScript hook configuration.
Examples
Uses @web scenarios, ChromeDriver lifecycle hooks, and conditions combining @web, @smoketest, and @backend.
What it assumes
Assumes familiarity with Cucumber scenarios, tags, and lifecycle hooks.
What you can do after
Apply it via Cucumber hooks to limit browser setup and cleanup to matching scenarios.
How it connects
Connects tags with scenarios, features, hooks, browser testing, and automated acceptance tests.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of BDD in Action, Second Edition. The section links point to the parts of the book it draws on.