Skip to content

Commit

Permalink
Support ChromeDriver "append log" flag in Java
Browse files Browse the repository at this point in the history
ChromeDriver has a command line option to append to existing log file
instead of overwriting it. Update Java API to support it.
  • Loading branch information
JohnChen0 authored and shs96c committed May 14, 2019
1 parent ff9de44 commit 94af952
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class ChromeDriverService extends DriverService {
*/
public final static String CHROME_DRIVER_LOG_PROPERTY = "webdriver.chrome.logfile";

/**
* Boolean system property that defines whether chromedriver should append to existing log file.
*/
public static final String CHROME_DRIVER_APPEND_LOG_PROPERTY =
"webdriver.chrome.appendLog";

/**
* Boolean system property that defines whether the chromedriver executable should be started
* with verbose logging.
Expand Down Expand Up @@ -101,6 +107,7 @@ public static ChromeDriverService createDefaultService() {
public static class Builder extends DriverService.Builder<
ChromeDriverService, ChromeDriverService.Builder> {

private boolean appendLog = Boolean.getBoolean(CHROME_DRIVER_APPEND_LOG_PROPERTY);
private boolean verbose = Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY);
private boolean silent = Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY);
private String whitelistedIps = System.getProperty(CHROME_DRIVER_WHITELISTED_IPS_PROPERTY);
Expand All @@ -120,6 +127,17 @@ public int score(Capabilities capabilities) {
return score;
}

/**
* Configures the driver server appending to log file.
*
* @param verbose True for appending to log file, false otherwise.
* @return A self reference.
*/
public Builder withAppendLog(boolean appendLog) {
this.appendLog = appendLog;
return this;
}

/**
* Configures the driver server verbosity.
*
Expand Down Expand Up @@ -176,6 +194,9 @@ protected ImmutableList<String> createArgs() {
if (getLogFile() != null) {
argsBuilder.add(String.format("--log-path=%s", getLogFile().getAbsolutePath()));
}
if (appendLog) {
argsBuilder.add("--append-log");
}
if (verbose) {
argsBuilder.add("--verbose");
}
Expand Down

0 comments on commit 94af952

Please sign in to comment.