WebDriver is a programmatic interface for controlling a real web browser, sending commands, and reading browser state. It exposes an HTTP interface, while Selenium supplies higher-level APIs for driver lifecycle management and page interaction. section 4.5
A Selenium-based WebDriver setup typically requires:
- A reachable test application and running web server, because the browser executes outside the test process. section 4.5
- A browser-specific driver service, such as ChromeDriverService, SafariDriverService, EdgeDriverService, or GeckoDriverService. section 4.5.1
- Browser lifecycle management, including startup, implicit waits, cookie cleanup when needed, and shutdown. section 4.5.1
- Headless browser options for CI environments without a display or for local runs that should not open a visible window. section 4.5.1
Headless Chrome setup
A test can start a ChromeDriver service before all tests, create a headless ChromeDriver with a one-second implicit wait, and call driver.quit() and driverService.stop() afterward. Selenium Manager can locate compatible browser and driver executables, download a missing driver, and report selected versions through logging.level.org.openqa.selenium=DEBUG. section 4.5.1
Listing 4.20 Selenium testing dependencies
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>
Use the dependency listing to add Selenium’s Java integration with test scope. section 4.5
