liveBook · Manning

Headless mode

As explained in Testing Spring Boot Applications

Headless mode is browser execution without displaying a graphical user interface.

Headless mode runs a browser without displaying its graphical user interface. Selenium uses it to execute browser tests without opening visible windows, which suits continuous integration environments without displays and avoids local focus interruptions. section 4.5.1

Use ChromeOptions to add the "--headless" argument when constructing a ChromeDriver. Remove the option during debugging to watch Selenium interact with the browser in real time. section 4.5.1

Listing 4.21 Selenium test setup
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class SeleniumTests {

  @LocalServerPort int port;
  static ChromeDriverService driverService;
  static WebDriver driver;
  private String baseUrl;

  @BeforeAll
  static void startChromeBrowser() throws Exception {
    driverService = ChromeDriverService.createDefaultService(); #1
    driverService.start(); #1

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless");
    driver = new ChromeDriver(driverService, options); #2
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1)); #3
  }

  @AfterAll
  static void stopChromeBrowser() {
    driver.quit(); #4
    driverService.stop(); #4
  }

}

Shows the complete Selenium setup: creating the driver service, enabling headless Chrome, configuring an implicit wait, and shutting down both resources. section 4.5.1

How Testing Spring Boot Applications covers it

How deep it goes
Explains the option’s behavior, debugging trade-off, and ChromeDriver configuration, but does not descend into browser internals.
Examples
Uses a ChromeOptions configuration that adds "--headless" before constructing ChromeDriver in a Selenium test.
What it assumes
Assumes familiarity with Selenium WebDriver, ChromeDriver, and browser test setup.
What you can do after
Operate/configure Selenium tests to launch Chrome without a graphical interface and switch to visible execution for debugging.
How it connects
Connects headless mode with Selenium, ChromeDriver, ChromeOptions, continuous integration, and browser debugging.

Also explained in

Compare how 2 books explain headless mode →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.