CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-seleniumhq-selenium--selenium-chrome-driver

Selenium Chrome WebDriver implementation for automating Chrome browsers using the WebDriver protocol

Pending
Overview
Eval results
Files

service-management.mddocs/

Service Management

ChromeDriver server lifecycle management with port configuration, logging options, process control, and builder pattern for creating configured service instances in distributed testing environments.

Capabilities

ChromeDriverService Class

Manages the lifecycle of ChromeDriver server processes with configuration for executables, ports, logging, and security settings.

/**
 * Manages the life and death of a ChromeDriver server.
 * Extends DriverService to provide Chrome-specific server management.
 */
public class ChromeDriverService extends DriverService {
    
    /**
     * System property that defines the location of the chromedriver executable.
     */
    public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
    
    /**
     * System property that defines the location of the log file.
     */
    public static final String CHROME_DRIVER_LOG_PROPERTY = "webdriver.chrome.logfile";
    
    /**
     * Boolean system property that defines whether chromedriver should start with verbose logging.
     */
    public static final String CHROME_DRIVER_VERBOSE_LOG_PROPERTY = "webdriver.chrome.verboseLogging";
    
    /**
     * Boolean system property that defines whether chromedriver should start in silent mode.
     */
    public static final String CHROME_DRIVER_SILENT_OUTPUT_PROPERTY = "webdriver.chrome.silentOutput";
    
    /**
     * System property that defines comma-separated list of remote IPv4 addresses
     * which are allowed to connect to ChromeDriver.
     */
    public static final String CHROME_DRIVER_WHITELISTED_IPS_PROPERTY = "webdriver.chrome.whitelistedIps";
    
    /**
     * Creates a ChromeDriverService with specified configuration.
     * @param executable The chromedriver executable file
     * @param port Which port to start the ChromeDriver on
     * @param args The arguments to the launched server
     * @param environment The environment for the launched server
     * @throws IOException If an I/O error occurs
     */
    public ChromeDriverService(
        File executable,
        int port,
        ImmutableList<String> args,
        ImmutableMap<String, String> environment) throws IOException;
}

Default Service Creation

Create ChromeDriverService instances with default configuration using system properties.

/**
 * Configures and returns a new ChromeDriverService using the default configuration.
 * Uses the chromedriver executable identified by the CHROME_DRIVER_EXE_PROPERTY system property.
 * Each service created by this method will be configured to use a free port on the current system.
 * @return A new ChromeDriverService using the default configuration
 */
public static ChromeDriverService createDefaultService();

Usage Example:

import org.openqa.selenium.chrome.ChromeDriverService;

// Set system property for chromedriver location
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

// Create default service - will find free port automatically
ChromeDriverService service = ChromeDriverService.createDefaultService();

// Start the service
service.start();

// Use with RemoteWebDriver for better resource management
WebDriver driver = new RemoteWebDriver(service.getUrl(), new ChromeOptions());

// Clean up
driver.quit();
service.stop();

Service Builder

Builder pattern for creating customized ChromeDriverService instances with specific configurations.

/**
 * Builder used to configure new ChromeDriverService instances.
 * Provides fluent API for service configuration.
 */
public static class Builder extends DriverService.Builder<ChromeDriverService, ChromeDriverService.Builder> {
    
    /**
     * Scores the given capabilities to determine if this service supports them.
     * Higher scores indicate better support.
     * @param capabilities The capabilities to score
     * @return Score indicating support level (0 = no support, higher = better support)
     */
    public int score(Capabilities capabilities);
    
    /**
     * Sets which driver executable the builder will use.
     * @param file The chromedriver executable to use
     * @return A self reference for method chaining
     */
    public Builder usingDriverExecutable(File file);
    
    /**
     * Sets which port the driver server should be started on.
     * @param port The port to use; must be non-negative
     * @return A self reference for method chaining
     */
    public Builder usingPort(int port);
    
    /**
     * Configures the driver server to start on any available port.
     * @return A self reference for method chaining
     */
    public Builder usingAnyFreePort();
    
    /**
     * Configures the driver server to write log to the given file.
     * @param logFile The file to write logs to
     * @return A self reference for method chaining
     */
    public Builder withLogFile(File logFile);
    
    /**
     * Defines the environment variables for the launched driver server.
     * @param environment A map of environment variables to launch the server with
     * @return A self reference for method chaining
     */
    public Builder withEnvironment(Map<String, String> environment);
    
    /**
     * Configures the driver server verbosity.
     * @param verbose True for verbose output, false otherwise
     * @return A self reference for method chaining
     */
    public Builder withVerbose(boolean verbose);
    
    /**
     * Configures the driver server for silent output.
     * @param silent True for silent output, false otherwise  
     * @return A self reference for method chaining
     */
    public Builder withSilent(boolean silent);
    
    /**
     * Configures the comma-separated list of remote IPv4 addresses which are allowed
     * to connect to the driver server.
     * @param whitelistedIps Comma-separated list of remote IPv4 addresses
     * @return A self reference for method chaining
     */
    public Builder withWhitelistedIps(String whitelistedIps);
}

Usage Examples:

import org.openqa.selenium.chrome.ChromeDriverService;
import java.io.File;

// Basic builder usage
ChromeDriverService service = new ChromeDriverService.Builder()
    .usingDriverExecutable(new File("/path/to/chromedriver"))
    .usingAnyFreePort()
    .build();

// Advanced configuration
ChromeDriverService service = new ChromeDriverService.Builder()
    .usingDriverExecutable(new File("/usr/local/bin/chromedriver"))
    .usingPort(4444)  
    .withVerbose(true)
    .withLogFile(new File("/tmp/chromedriver.log"))
    .withWhitelistedIps("127.0.0.1,192.168.1.100")
    .build();

// For CI/CD environments
ChromeDriverService service = new ChromeDriverService.Builder()
    .usingAnyFreePort()
    .withSilent(true)
    .withLogFile(new File("./logs/chromedriver.log"))
    .build();

service.start();

Logging Configuration

Configure ChromeDriver server logging behavior for debugging and monitoring.

System Properties:

// Set chromedriver executable location
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

// Set log file location
System.setProperty("webdriver.chrome.logfile", "/path/to/chromedriver.log");

// Enable verbose logging
System.setProperty("webdriver.chrome.verboseLogging", "true");

// Enable silent mode (minimal output)
System.setProperty("webdriver.chrome.silentOutput", "true");

// Set whitelisted IPs for remote connections
System.setProperty("webdriver.chrome.whitelistedIps", "127.0.0.1,192.168.1.0/24");

Builder Configuration:

ChromeDriverService service = new ChromeDriverService.Builder()
    .withVerbose(true)          // Enable verbose logging
    .withSilent(false)          // Disable silent mode  
    .withLogFile(new File("/tmp/chromedriver.log"))  // Set log file
    .build();

Security Configuration

Configure IP whitelisting for secure remote connections to ChromeDriver server.

Usage Example:

// Allow specific IPs to connect
ChromeDriverService service = new ChromeDriverService.Builder()
    .withWhitelistedIps("127.0.0.1,192.168.1.100,10.0.0.0/8")
    .usingPort(4444)
    .build();

// Start service
service.start();
System.out.println("ChromeDriver server URL: " + service.getUrl());

// Service will only accept connections from whitelisted IPs

Service Lifecycle Management

Manage ChromeDriver server startup, shutdown, and resource cleanup.

Complete Example:

import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.io.IOException;

public class ChromeServiceExample {
    private ChromeDriverService service;
    
    public void setupService() throws IOException {
        // Create and configure service
        service = new ChromeDriverService.Builder()
            .usingDriverExecutable(new File("/usr/local/bin/chromedriver"))
            .usingAnyFreePort()
            .withVerbose(true)
            .withLogFile(new File("./chromedriver.log"))
            .build();
            
        // Start the service
        service.start();
        System.out.println("ChromeDriver started on: " + service.getUrl());
    }
    
    public WebDriver createDriver() {
        // Create driver connected to running service
        ChromeOptions options = new ChromeOptions();
        options.setHeadless(true);
        
        return new RemoteWebDriver(service.getUrl(), options);
    }
    
    public void teardownService() {
        // Stop the service and clean up resources
        if (service != null && service.isRunning()) {
            service.stop();
            System.out.println("ChromeDriver service stopped");
        }
    }
}

// Usage in test framework
ChromeServiceExample example = new ChromeServiceExample();
example.setupService();

WebDriver driver = example.createDriver();
driver.get("https://example.com");
System.out.println("Page title: " + driver.getTitle());

driver.quit();
example.teardownService();

Distributed Testing Setup

Configure ChromeDriverService for Selenium Grid and distributed testing environments.

Hub Registration Example:

// Start ChromeDriver service for Grid registration
ChromeDriverService service = new ChromeDriverService.Builder()
    .usingDriverExecutable(new File("/opt/chromedriver"))
    .usingPort(5555)
    .withWhitelistedIps("0.0.0.0/0")  // Allow all IPs for Grid
    .withVerbose(false)
    .build();

service.start();

// Service can now be registered with Selenium Grid hub
// Grid will route Chrome test requests to this service

Environment Variables Integration

Integrate with environment-based configuration for container deployments.

Usage Example:

public class EnvironmentAwareService {
    public static ChromeDriverService createFromEnvironment() {
        ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
        
        // Use environment variables if available
        String driverPath = System.getenv("CHROME_DRIVER_PATH");
        if (driverPath != null) {
            builder.usingDriverExecutable(new File(driverPath));
        }
        
        String port = System.getenv("CHROME_DRIVER_PORT");
        if (port != null) {
            builder.usingPort(Integer.parseInt(port));
        } else {
            builder.usingAnyFreePort();
        }
        
        // Configure based on environment
        String verbose = System.getenv("CHROME_DRIVER_VERBOSE");
        if ("true".equals(verbose)) {
            builder.withVerbose(true);
        }
        
        String whitelistedIps = System.getenv("CHROME_DRIVER_WHITELIST");
        if (whitelistedIps != null) {
            builder.withWhitelistedIps(whitelistedIps);
        }
        
        return builder.build();
    }
}

Types

// Guava collections used in service configuration
class ImmutableList<T> {
    public static <T> ImmutableList<T> of(T... elements);
    public static <T> Builder<T> builder();
}

class ImmutableMap<K, V> {
    public static <K, V> ImmutableMap<K, V> of();
    public static <K, V> Builder<K, V> builder();
}

// Base service class
abstract class DriverService {
    public abstract void start() throws IOException;
    public abstract void stop();
    public abstract boolean isRunning();
    public abstract URL getUrl();
    
    public static abstract class Builder<DS extends DriverService, B extends Builder<?, ?>> {
        public B usingDriverExecutable(File file);
        public B usingAnyFreePort();
        public B usingPort(int port);
        public B withLogFile(File logFile);
        public B withEnvironment(Map<String, String> environment);
        public abstract DS build();
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-chrome-driver

docs

browser-configuration.md

driver-information.md

index.md

service-management.md

webdriver-implementation.md

tile.json