Skip to content

Commit cc2b37a

Browse files
authored
Merge branch 'trunk' into py_sm_log
2 parents 4258aa0 + 66e51be commit cc2b37a

10 files changed

Lines changed: 646 additions & 304 deletions

File tree

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 110 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ public class ChromeDriverService extends DriverService {
5555
public static final String CHROME_DRIVER_READABLE_TIMESTAMP = "webdriver.chrome.readableTimestamp";
5656

5757
/**
58-
* System property that defines the default location where ChromeDriver output is logged.
58+
* System property that defines the location of the file where ChromeDriver should write log
59+
* messages to.
5960
*/
6061
public static final String CHROME_DRIVER_LOG_PROPERTY = "webdriver.chrome.logfile";
6162

6263
/**
63-
* System property that defines the log level when ChromeDriver output is logged.
64+
* System property that defines the {@link ChromiumDriverLogLevel} for ChromeDriver logs.
6465
*/
6566
public static final String CHROME_DRIVER_LOG_LEVEL_PROPERTY = "webdriver.chrome.loglevel";
6667

@@ -70,34 +71,35 @@ public class ChromeDriverService extends DriverService {
7071
public static final String CHROME_DRIVER_APPEND_LOG_PROPERTY = "webdriver.chrome.appendLog";
7172

7273
/**
73-
* Boolean system property that defines whether the ChromeDriver executable should be started
74-
* with verbose logging.
74+
* Boolean system property that defines whether the ChromeDriver executable should be started with
75+
* verbose logging.
7576
*/
7677
public static final String CHROME_DRIVER_VERBOSE_LOG_PROPERTY = "webdriver.chrome.verboseLogging";
7778

7879
/**
79-
* Boolean system property that defines whether the ChromeDriver executable should be started
80-
* in silent mode.
80+
* Boolean system property that defines whether the ChromeDriver executable should be started in
81+
* silent mode.
8182
*/
8283
public static final String CHROME_DRIVER_SILENT_OUTPUT_PROPERTY = "webdriver.chrome.silentOutput";
8384

8485
/**
85-
* System property that defines comma-separated list of remote IPv4 addresses which are
86-
* allowed to connect to ChromeDriver.
86+
* System property that defines comma-separated list of remote IPv4 addresses which are allowed to
87+
* connect to ChromeDriver.
8788
*/
8889
public static final String CHROME_DRIVER_ALLOWED_IPS_PROPERTY = "webdriver.chrome.withAllowedIps";
8990

9091
/**
91-
* System property that defines comma-separated list of remote IPv4 addresses which are
92-
* allowed to connect to ChromeDriver.
92+
* System property that defines comma-separated list of remote IPv4 addresses which are allowed to
93+
* connect to ChromeDriver.
94+
*
9395
* @deprecated use {@link #CHROME_DRIVER_ALLOWED_IPS_PROPERTY}
9496
*/
9597
@Deprecated
9698
public static final String CHROME_DRIVER_WHITELISTED_IPS_PROPERTY = "webdriver.chrome.whitelistedIps";
9799

98100
/**
99-
* System property that defines whether the ChromeDriver executable should check for build
100-
* version compatibility between ChromeDriver and the browser.
101+
* System property that defines whether the ChromeDriver executable should check for build version
102+
* compatibility between ChromeDriver and the browser.
101103
*/
102104
public static final String CHROME_DRIVER_DISABLE_BUILD_CHECK = "webdriver.chrome.disableBuildCheck";
103105

@@ -107,13 +109,15 @@ public class ChromeDriverService extends DriverService {
107109
* @param args The arguments to the launched server.
108110
* @param environment The environment for the launched server.
109111
* @throws IOException If an I/O error occurs.
112+
* @deprecated use {@link ChromeDriverService#ChromeDriverService(File, int, Duration, List, Map)}
110113
*/
114+
@Deprecated
111115
public ChromeDriverService(
112116
File executable,
113117
int port,
114118
List<String> args,
115119
Map<String, String> environment) throws IOException {
116-
super(executable, port, DEFAULT_TIMEOUT,
120+
this(executable, port, DEFAULT_TIMEOUT,
117121
unmodifiableList(new ArrayList<>(args)),
118122
unmodifiableMap(new HashMap<>(environment)));
119123
}
@@ -127,11 +131,11 @@ public ChromeDriverService(
127131
* @throws IOException If an I/O error occurs.
128132
*/
129133
public ChromeDriverService(
130-
File executable,
131-
int port,
132-
Duration timeout,
133-
List<String> args,
134-
Map<String, String> environment) throws IOException {
134+
File executable,
135+
int port,
136+
Duration timeout,
137+
List<String> args,
138+
Map<String, String> environment) throws IOException {
135139
super(executable, port, timeout,
136140
unmodifiableList(new ArrayList<>(args)),
137141
unmodifiableMap(new HashMap<>(environment)));
@@ -154,7 +158,8 @@ public Capabilities getDefaultDriverOptions() {
154158
* Configures and returns a new {@link ChromeDriverService} using the default configuration. In
155159
* this configuration, the service will use the ChromeDriver executable identified by
156160
* {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService, Capabilities)}.
157-
* Each service created by this method will be configured to use a free port on the current system.
161+
* Each service created by this method will be configured to use a free port on the current
162+
* system.
158163
*
159164
* @return A new ChromeDriverService using the default configuration.
160165
*/
@@ -166,7 +171,8 @@ public static ChromeDriverService createDefaultService() {
166171
* Configures and returns a new {@link ChromeDriverService} using the supplied configuration. In
167172
* this configuration, the service will use the ChromeDriver executable identified by
168173
* {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService, Capabilities)}.
169-
* Each service created by this method will be configured to use a free port on the current system.
174+
* Each service created by this method will be configured to use a free port on the current
175+
* system.
170176
*
171177
* @return A new ChromeDriverService using the supplied configuration from {@link ChromeOptions}.
172178
* @deprecated Use {@link Builder#withLogLevel(ChromiumDriverLogLevel)} }
@@ -175,15 +181,15 @@ public static ChromeDriverService createDefaultService() {
175181
public static ChromeDriverService createServiceWithConfig(ChromeOptions options) {
176182
ChromeDriverLogLevel oldLevel = options.getLogLevel();
177183
ChromiumDriverLogLevel level = (oldLevel == null) ? null :
178-
ChromiumDriverLogLevel.fromString(oldLevel.toString());
184+
ChromiumDriverLogLevel.fromString(oldLevel.toString());
179185
return new Builder()
180186
.withLogLevel(level)
181187
.build();
182188
}
183189

184190
/**
185-
* Checks if the browser driver binary is already present. Grid uses this method to show
186-
* the available browsers and drivers, hence its visibility.
191+
* Checks if the ChromeDriver binary is already present. Grid uses this method to show the
192+
* available browsers and drivers, hence its visibility.
187193
*
188194
* @return Whether the browser driver path was found.
189195
*/
@@ -198,16 +204,13 @@ static boolean isPresent() {
198204
public static class Builder extends DriverService.Builder<
199205
ChromeDriverService, ChromeDriverService.Builder> {
200206

201-
private boolean disableBuildCheck = Boolean.getBoolean(CHROME_DRIVER_DISABLE_BUILD_CHECK);
202-
private boolean readableTimestamp = Boolean.getBoolean(CHROME_DRIVER_READABLE_TIMESTAMP);
203-
private boolean appendLog = Boolean.getBoolean(CHROME_DRIVER_APPEND_LOG_PROPERTY);
204-
private boolean verbose = Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY);
205-
private boolean silent = Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY);
206-
private String allowedListIps = System.getProperty(CHROME_DRIVER_ALLOWED_IPS_PROPERTY,
207-
System.getProperty(
208-
CHROME_DRIVER_WHITELISTED_IPS_PROPERTY));
209-
private ChromiumDriverLogLevel logLevel = ChromiumDriverLogLevel
210-
.fromString(System.getProperty(CHROME_DRIVER_LOG_LEVEL_PROPERTY));
207+
private Boolean disableBuildCheck;
208+
private Boolean readableTimestamp;
209+
private Boolean appendLog;
210+
private Boolean verbose;
211+
private Boolean silent;
212+
private String allowedListIps;
213+
private ChromiumDriverLogLevel logLevel;
211214

212215
@Override
213216
public int score(Capabilities capabilities) {
@@ -246,21 +249,6 @@ public Builder withBuildCheckDisabled(boolean noBuildCheck) {
246249
return this;
247250
}
248251

249-
/**
250-
* Configures the driver server verbosity.
251-
*
252-
* @param verbose Log all output for true, no changes made if false.
253-
* @return A self reference.
254-
*/
255-
@SuppressWarnings("UnusedReturnValue")
256-
public Builder withVerbose(boolean verbose) {
257-
if (verbose) {
258-
this.logLevel = ChromiumDriverLogLevel.ALL;
259-
}
260-
this.verbose = false;
261-
return this;
262-
}
263-
264252
/**
265253
* Configures the driver server verbosity.
266254
*
@@ -270,20 +258,22 @@ public Builder withVerbose(boolean verbose) {
270258
*/
271259
@Deprecated
272260
public Builder withLogLevel(ChromeDriverLogLevel logLevel) {
273-
this.verbose = false;
274-
this.silent = false;
275261
this.logLevel = ChromiumDriverLogLevel.fromString(logLevel.toString());
262+
this.silent = false;
263+
this.verbose = false;
276264
return this;
277265
}
278266

279267
/**
280-
* Configures the driver server verbosity.
268+
* Configures the driver server log level.
281269
*
282270
* @param logLevel {@link ChromiumDriverLogLevel} for desired log level output.
283271
* @return A self reference.
284272
*/
285273
public Builder withLogLevel(ChromiumDriverLogLevel logLevel) {
286274
this.logLevel = logLevel;
275+
this.silent = false;
276+
this.verbose = false;
287277
return this;
288278
}
289279

@@ -302,8 +292,22 @@ public Builder withSilent(boolean silent) {
302292
}
303293

304294
/**
305-
* Configures the comma-separated list of remote IPv4 addresses which are allowed to connect
306-
* to the driver server.
295+
* Configures the driver server verbosity.
296+
*
297+
* @param verbose Log all output for true, no changes made if false.
298+
* @return A self reference.
299+
*/
300+
public Builder withVerbose(boolean verbose) {
301+
if (verbose) {
302+
this.logLevel = ChromiumDriverLogLevel.ALL;
303+
}
304+
this.verbose = false;
305+
return this;
306+
}
307+
308+
/**
309+
* Configures the comma-separated list of remote IPv4 addresses which are allowed to connect to
310+
* the driver server.
307311
*
308312
* @param allowedListIps Comma-separated list of remote IPv4 addresses.
309313
* @return A self reference.
@@ -316,8 +320,8 @@ public Builder withWhitelistedIps(String allowedListIps) {
316320
}
317321

318322
/**
319-
* Configures the comma-separated list of remote IPv4 addresses which are allowed to connect
320-
* to the driver server.
323+
* Configures the comma-separated list of remote IPv4 addresses which are allowed to connect to
324+
* the driver server.
321325
*
322326
* @param allowedListIps Comma-separated list of remote IPv4 addresses.
323327
* @return A self reference.
@@ -339,42 +343,69 @@ public Builder withReadableTimestamp(Boolean readableTimestamp) {
339343
}
340344

341345
@Override
342-
protected List<String> createArgs() {
346+
protected void loadSystemProperties() {
343347
if (getLogFile() == null) {
344348
String logFilePath = System.getProperty(CHROME_DRIVER_LOG_PROPERTY);
345349
if (logFilePath != null) {
346350
withLogFile(new File(logFilePath));
347351
}
348352
}
349-
350-
// If set in properties and not overwritten by method
351-
if (verbose) {
352-
withVerbose(true);
353+
if (disableBuildCheck == null) {
354+
this.disableBuildCheck = Boolean.getBoolean(CHROME_DRIVER_DISABLE_BUILD_CHECK);
353355
}
354-
if (silent) {
355-
withSilent(true);
356+
if (readableTimestamp == null) {
357+
this.readableTimestamp = Boolean.getBoolean(CHROME_DRIVER_READABLE_TIMESTAMP);
356358
}
359+
if (appendLog == null) {
360+
this.appendLog = Boolean.getBoolean(CHROME_DRIVER_APPEND_LOG_PROPERTY);
361+
}
362+
if (verbose == null && Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY)) {
363+
withVerbose(Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY));
364+
}
365+
if (silent == null && Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY)) {
366+
withSilent(Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY));
367+
}
368+
if (allowedListIps == null) {
369+
this.allowedListIps = System.getProperty(CHROME_DRIVER_ALLOWED_IPS_PROPERTY,
370+
System.getProperty(CHROME_DRIVER_WHITELISTED_IPS_PROPERTY));
371+
}
372+
if (logLevel == null && System.getProperty(CHROME_DRIVER_LOG_LEVEL_PROPERTY) != null) {
373+
String level = System.getProperty(CHROME_DRIVER_LOG_LEVEL_PROPERTY);
374+
withLogLevel(ChromiumDriverLogLevel.fromString(level));
375+
}
376+
}
357377

378+
@Override
379+
protected List<String> createArgs() {
358380
List<String> args = new ArrayList<>();
359-
360381
args.add(String.format("--port=%d", getPort()));
361-
if (getLogFile() != null) {
382+
383+
// Readable timestamp and append logs only work if a file is specified
384+
// Can only get readable logs via arguments; otherwise send service output as directed
385+
if (getLogFile() != null && (readableTimestamp || appendLog)) {
362386
args.add(String.format("--log-path=%s", getLogFile().getAbsolutePath()));
363-
// This flag only works when logged to file
364-
if (readableTimestamp) {
387+
if (readableTimestamp != null && readableTimestamp.equals(Boolean.TRUE)) {
365388
args.add("--readable-timestamp");
366389
}
390+
if (appendLog != null && appendLog.equals(Boolean.TRUE)) {
391+
args.add("--append-log");
392+
}
393+
withLogFile(null); // Do not overwrite in sendOutputTo()
367394
}
368-
if (appendLog) {
369-
args.add("--append-log");
370-
}
395+
371396
if (logLevel != null) {
372397
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase()));
373398
}
399+
// if (silent != null && silent.equals(Boolean.TRUE)) {
400+
// args.add("--silent");
401+
// }
402+
// if (verbose != null && verbose.equals(Boolean.TRUE)) {
403+
// args.add("--verbose");
404+
// }
374405
if (allowedListIps != null) {
375406
args.add(String.format("--allowed-ips=%s", allowedListIps));
376407
}
377-
if (disableBuildCheck) {
408+
if (disableBuildCheck != null && disableBuildCheck.equals(Boolean.TRUE)) {
378409
args.add("--disable-build-check");
379410
}
380411

@@ -383,13 +414,16 @@ protected List<String> createArgs() {
383414

384415
@Override
385416
protected ChromeDriverService createDriverService(
386-
File exe,
387-
int port,
388-
Duration timeout,
389-
List<String> args,
390-
Map<String, String> environment) {
417+
File exe,
418+
int port,
419+
Duration timeout,
420+
List<String> args,
421+
Map<String, String> environment) {
391422
try {
392-
return new ChromeDriverService(exe, port, timeout, args, environment);
423+
ChromeDriverService service = new ChromeDriverService(exe, port, timeout, args,
424+
environment);
425+
service.sendOutputTo(getLogOutput(CHROME_DRIVER_LOG_PROPERTY));
426+
return service;
393427
} catch (IOException e) {
394428
throw new WebDriverException(e);
395429
}

0 commit comments

Comments
 (0)