0
# Service Management
1
2
ChromeDriverService provides comprehensive lifecycle management for the ChromeDriver executable, including configuration options for logging, security, and build compatibility.
3
4
## Service Creation
5
6
### Create Default Service
7
8
Create a ChromeDriverService with default configuration.
9
10
```java { .api }
11
public static ChromeDriverService createDefaultService();
12
```
13
14
**Returns:** ChromeDriverService - Service instance configured with default settings
15
16
**Usage Example:**
17
```java
18
import org.openqa.selenium.chrome.ChromeDriverService;
19
20
// Create default service
21
ChromeDriverService service = ChromeDriverService.createDefaultService();
22
23
// Use with driver
24
ChromeDriver driver = new ChromeDriver(service);
25
```
26
27
### Service Builder
28
29
Use the Builder pattern for advanced service configuration.
30
31
```java { .api }
32
public static class Builder extends DriverService.Builder<ChromeDriverService, ChromeDriverService.Builder> {
33
public Builder withAppendLog(boolean appendLog);
34
public Builder withBuildCheckDisabled(boolean noBuildCheck);
35
public Builder withLogLevel(ChromiumDriverLogLevel logLevel);
36
public Builder withSilent(boolean silent);
37
public Builder withVerbose(boolean verbose);
38
public Builder withAllowedListIps(String allowedListIps);
39
public Builder withReadableTimestamp(Boolean readableTimestamp);
40
public int score(Capabilities capabilities);
41
}
42
```
43
44
**Usage Example:**
45
```java
46
import org.openqa.selenium.chrome.ChromeDriverService;
47
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
48
import java.io.File;
49
50
ChromeDriverService service = new ChromeDriverService.Builder()
51
.usingDriverExecutable(new File("/path/to/chromedriver"))
52
.usingAnyFreePort()
53
.withLogLevel(ChromiumDriverLogLevel.INFO)
54
.withVerbose(false)
55
.withAppendLog(true)
56
.withLogFile(new File("/tmp/chromedriver.log"))
57
.build();
58
```
59
60
## Service Configuration
61
62
### System Properties
63
64
ChromeDriverService supports various system properties for configuration:
65
66
```java { .api }
67
public static final String CHROME_DRIVER_NAME = "chromedriver";
68
public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
69
public static final String CHROME_DRIVER_LOG_PROPERTY = "webdriver.chrome.logfile";
70
public static final String CHROME_DRIVER_LOG_LEVEL_PROPERTY = "webdriver.chrome.loglevel";
71
public static final String CHROME_DRIVER_VERBOSE_LOG_PROPERTY = "webdriver.chrome.verboseLogging";
72
public static final String CHROME_DRIVER_SILENT_OUTPUT_PROPERTY = "webdriver.chrome.silentOutput";
73
public static final String CHROME_DRIVER_APPEND_LOG_PROPERTY = "webdriver.chrome.appendLog";
74
public static final String CHROME_DRIVER_ALLOWED_IPS_PROPERTY = "webdriver.chrome.withAllowedIps";
75
public static final String CHROME_DRIVER_DISABLE_BUILD_CHECK = "webdriver.chrome.disableBuildCheck";
76
public static final String CHROME_DRIVER_READABLE_TIMESTAMP = "webdriver.chrome.readableTimestamp";
77
```
78
79
**System Property Usage:**
80
```java
81
// Set system properties before creating service
82
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
83
System.setProperty("webdriver.chrome.logfile", "/tmp/chromedriver.log");
84
System.setProperty("webdriver.chrome.loglevel", "INFO");
85
86
ChromeDriverService service = ChromeDriverService.createDefaultService();
87
```
88
89
## Logging Configuration
90
91
### Log Level Configuration
92
93
Set the logging level for ChromeDriver output.
94
95
```java { .api }
96
public Builder withLogLevel(ChromiumDriverLogLevel logLevel);
97
```
98
99
**Parameters:**
100
- `logLevel` (ChromiumDriverLogLevel): Desired log level (ALL, INFO, DEBUG, WARNING, SEVERE, OFF)
101
102
**Returns:** Builder - Builder instance for method chaining
103
104
**Usage Example:**
105
```java
106
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
107
108
ChromeDriverService service = new ChromeDriverService.Builder()
109
.withLogLevel(ChromiumDriverLogLevel.DEBUG)
110
.build();
111
```
112
113
### Verbose Logging
114
115
Enable verbose logging for detailed output.
116
117
```java { .api }
118
public Builder withVerbose(boolean verbose);
119
```
120
121
**Parameters:**
122
- `verbose` (boolean): Enable verbose logging if true
123
124
**Returns:** Builder - Builder instance for method chaining
125
126
### Silent Mode
127
128
Configure the service to run in silent mode with minimal output.
129
130
```java { .api }
131
public Builder withSilent(boolean silent);
132
```
133
134
**Parameters:**
135
- `silent` (boolean): Enable silent mode if true
136
137
**Returns:** Builder - Builder instance for method chaining
138
139
### Log File Management
140
141
Configure log file appending behavior.
142
143
```java { .api }
144
public Builder withAppendLog(boolean appendLog);
145
```
146
147
**Parameters:**
148
- `appendLog` (boolean): Append to existing log file if true, overwrite if false
149
150
**Returns:** Builder - Builder instance for method chaining
151
152
### Readable Timestamps
153
154
Configure timestamp formatting in log output.
155
156
```java { .api }
157
public Builder withReadableTimestamp(Boolean readableTimestamp);
158
```
159
160
**Parameters:**
161
- `readableTimestamp` (Boolean): Use human-readable timestamps if true
162
163
**Returns:** Builder - Builder instance for method chaining
164
165
## Security Configuration
166
167
### Allowed IP Addresses
168
169
Configure which IP addresses are allowed to connect to the ChromeDriver service.
170
171
```java { .api }
172
public Builder withAllowedListIps(String allowedListIps);
173
```
174
175
**Parameters:**
176
- `allowedListIps` (String): Comma-separated list of allowed IPv4 addresses
177
178
**Returns:** Builder - Builder instance for method chaining
179
180
**Usage Example:**
181
```java
182
ChromeDriverService service = new ChromeDriverService.Builder()
183
.withAllowedListIps("127.0.0.1,192.168.1.100")
184
.build();
185
```
186
187
## Compatibility Configuration
188
189
### Build Check Configuration
190
191
Disable version compatibility checking between ChromeDriver and Chrome browser.
192
193
```java { .api }
194
public Builder withBuildCheckDisabled(boolean noBuildCheck);
195
```
196
197
**Parameters:**
198
- `noBuildCheck` (boolean): Disable build compatibility check if true
199
200
**Returns:** Builder - Builder instance for method chaining
201
202
**Usage Example:**
203
```java
204
ChromeDriverService service = new ChromeDriverService.Builder()
205
.withBuildCheckDisabled(true) // Allow potentially incompatible versions
206
.build();
207
```
208
209
## Service Information
210
211
### Driver Name
212
213
Get the name of the driver executable.
214
215
```java { .api }
216
public String getDriverName();
217
```
218
219
**Returns:** String - Driver executable name ("chromedriver")
220
221
### Driver Property
222
223
Get the system property name for the driver executable path.
224
225
```java { .api }
226
public String getDriverProperty();
227
```
228
229
**Returns:** String - System property name ("webdriver.chrome.driver")
230
231
### Default Driver Options
232
233
Get the default capabilities for this driver service.
234
235
```java { .api }
236
public Capabilities getDefaultDriverOptions();
237
```
238
239
**Returns:** Capabilities - Default ChromeOptions instance
240
241
## Complete Configuration Example
242
243
```java
244
import org.openqa.selenium.chrome.ChromeDriverService;
245
import org.openqa.selenium.chrome.ChromeDriver;
246
import org.openqa.selenium.chrome.ChromeOptions;
247
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
248
import java.io.File;
249
import java.time.Duration;
250
251
// Configure comprehensive service
252
ChromeDriverService service = new ChromeDriverService.Builder()
253
.usingDriverExecutable(new File("/path/to/chromedriver"))
254
.usingPort(9515)
255
.withTimeout(Duration.ofSeconds(30))
256
.withLogFile(new File("/tmp/chromedriver.log"))
257
.withLogLevel(ChromiumDriverLogLevel.INFO)
258
.withAppendLog(true)
259
.withReadableTimestamp(true)
260
.withAllowedListIps("127.0.0.1,10.0.0.0/8")
261
.withBuildCheckDisabled(false)
262
.build();
263
264
// Use configured service
265
ChromeOptions options = new ChromeOptions();
266
ChromeDriver driver = new ChromeDriver(service, options);
267
268
// Ensure cleanup
269
try {
270
driver.get("https://example.com");
271
// Test operations...
272
} finally {
273
driver.quit();
274
}
275
```
276
277
## Error Handling
278
279
Service-related exceptions that may occur:
280
281
- `WebDriverException` - General service startup/shutdown issues
282
- `IOException` - File system problems with logs or executable
283
- `IllegalArgumentException` - Invalid configuration parameters
284
- `IllegalStateException` - Service already started/stopped
285
286
Common troubleshooting:
287
- Verify ChromeDriver executable exists and is executable
288
- Check port availability and network connectivity
289
- Ensure log file directory is writable
290
- Validate IP address format for allowed lists