Selenium 4.7.2 升级log处理方式
https://github.com/SeleniumHQ/selenium
官方升级说明中提示了改变了日志方式了
v4.7.2
======
* Grid: Support file downloads on the node (#11277)
* Change chromium service names from whitelisted to allowed (#11409)
* Avoid closing CDP connection in browser implementation since that logic now sits in RemoteWebDriver (Fixes #11401)
* Fix bug where failing Selenium Manager method results in wrong error
* Allow changing chromium driver log timestamp formatting
* Allow ignoring chromedriver build checks using service builders
* Add support for appendLog to msedgedriver service
* Fix msedgedriver log level logic
* Allow setting chromedriver log level from system properties
* Fix chromedriver log level logic
* Remove deprecated Firefox capabilities
* Removing a few bits more of the magic that moves JWP to W3C
* Removing deprecated SUPPORTS_ALERTS and SUPPORTS_SQL_DATABASE caps
* Removing deprecated OVERLAPPING_CHECK_DISABLED cap
* Removing deprecated LOGGING_PREFS cap
* Removing deprecated HAS_TOUCHSCREEN cap
* Removing deprecated HAS_NATIVE_EVENTS cap
* Removing deprecated ENABLE_PROFILING_CAPABILITY cap
* Removing deprecated ACCEPT_SSL_CERTS cap
Selenium 4.7.2 ChromeDriverService 源代码
package org.openqa.selenium.chrome; import com.google.auto.service.AutoService; import java.io.File; import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.Browser; import org.openqa.selenium.remote.service.DriverService; public class ChromeDriverService extends DriverService { public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver"; public static final String CHROME_DRIVER_READABLE_TIMESTAMP = "webdriver.chrome.readableTimestamp"; public static final String CHROME_DRIVER_LOG_PROPERTY = "webdriver.chrome.logfile"; public static final String CHROME_DRIVER_LOG_LEVEL_PROPERTY = "webdriver.chrome.loglevel"; public static final String CHROME_DRIVER_APPEND_LOG_PROPERTY = "webdriver.chrome.appendLog"; public static final String CHROME_DRIVER_VERBOSE_LOG_PROPERTY = "webdriver.chrome.verboseLogging"; public static final String CHROME_DRIVER_SILENT_OUTPUT_PROPERTY = "webdriver.chrome.silentOutput"; public static final String CHROME_DRIVER_ALLOWED_IPS_PROPERTY = "webdriver.chrome.withAllowedIps"; /** @deprecated */ @Deprecated public static final String CHROME_DRIVER_WHITELISTED_IPS_PROPERTY = "webdriver.chrome.whitelistedIps"; public static final String CHROME_DRIVER_DISABLE_BUILD_CHECK = "webdriver.chrome.disableBuildCheck"; public ChromeDriverService(File executable, int port, List<String> args, Map<String, String> environment) throws IOException { super(executable, port, DEFAULT_TIMEOUT, Collections.unmodifiableList(new ArrayList(args)), Collections.unmodifiableMap(new HashMap(environment))); } public ChromeDriverService(File executable, int port, Duration timeout, List<String> args, Map<String, String> environment) throws IOException { super(executable, port, timeout, Collections.unmodifiableList(new ArrayList(args)), Collections.unmodifiableMap(new HashMap(environment))); } public static ChromeDriverService createDefaultService() { return (ChromeDriverService)(new ChromeDriverService.Builder()).build(); } public static ChromeDriverService createServiceWithConfig(ChromeOptions options) { return (ChromeDriverService)(new ChromeDriverService.Builder()).withLogLevel(options.getLogLevel()).build(); } @AutoService({org.openqa.selenium.remote.service.DriverService.Builder.class}) public static class Builder extends org.openqa.selenium.remote.service.DriverService.Builder<ChromeDriverService, ChromeDriverService.Builder> { private boolean disableBuildCheck = Boolean.getBoolean("webdriver.chrome.disableBuildCheck"); private boolean readableTimestamp = Boolean.getBoolean("webdriver.chrome.readableTimestamp"); private boolean appendLog = Boolean.getBoolean("webdriver.chrome.appendLog"); private boolean verbose = Boolean.getBoolean("webdriver.chrome.verboseLogging"); private boolean silent = Boolean.getBoolean("webdriver.chrome.silentOutput"); private String allowedListIps = System.getProperty("webdriver.chrome.withAllowedIps", System.getProperty("webdriver.chrome.whitelistedIps")); private ChromeDriverLogLevel logLevel = ChromeDriverLogLevel.fromString(System.getProperty("webdriver.chrome.loglevel")); public Builder() { } public int score(Capabilities capabilities) { int score = 0; if (Browser.CHROME.is(capabilities.getBrowserName())) { ++score; } if (capabilities.getCapability("goog:chromeOptions") != null) { ++score; } return score; } public ChromeDriverService.Builder withAppendLog(boolean appendLog) { this.appendLog = appendLog; return this; } public ChromeDriverService.Builder withBuildCheckDisabled(boolean noBuildCheck) { this.disableBuildCheck = noBuildCheck; return this; } public ChromeDriverService.Builder withVerbose(boolean verbose) { if (verbose) { this.logLevel = ChromeDriverLogLevel.ALL; } this.verbose = false; return this; } public ChromeDriverService.Builder withLogLevel(ChromeDriverLogLevel logLevel) { this.verbose = false; this.silent = false; this.logLevel = logLevel; return this; } public ChromeDriverService.Builder withSilent(boolean silent) { if (silent) { this.logLevel = ChromeDriverLogLevel.OFF; } this.silent = false; return this; } /** @deprecated */ @Deprecated public ChromeDriverService.Builder withWhitelistedIps(String allowedListIps) { this.allowedListIps = allowedListIps; return this; } public ChromeDriverService.Builder withReadableTimestamp(Boolean readableTimestamp) { this.readableTimestamp = readableTimestamp; return this; } protected File findDefaultExecutable() { return ChromeDriverService.findExecutable("chromedriver", "webdriver.chrome.driver", "https://chromedriver.chromium.org/", "https://chromedriver.chromium.org/downloads"); } protected List<String> createArgs() { if (this.getLogFile() == null) { String logFilePath = System.getProperty("webdriver.chrome.logfile"); if (logFilePath != null) { this.withLogFile(new File(logFilePath)); } } if (this.verbose) { this.withVerbose(true); } if (this.silent) { this.withSilent(true); } List<String> args = new ArrayList(); args.add(String.format("--port=%d", this.getPort())); if (this.getLogFile() != null) { args.add(String.format("--log-path=%s", this.getLogFile().getAbsolutePath())); if (this.readableTimestamp) { args.add("--readable-timestamp"); } } if (this.appendLog) { args.add("--append-log"); } if (this.logLevel != null) { args.add(String.format("--log-level=%s", this.logLevel.toString().toUpperCase())); } if (this.allowedListIps != null) { args.add(String.format("--allowed-ips=%s", this.allowedListIps)); } if (this.disableBuildCheck) { args.add("--disable-build-check"); } return Collections.unmodifiableList(args); } protected ChromeDriverService createDriverService(File exe, int port, Duration timeout, List<String> args, Map<String, String> environment) { try { return new ChromeDriverService(exe, port, timeout, args, environment); } catch (IOException var7) { throw new WebDriverException(var7); } } } }
Selenium 4.7.1 ChromeDriverService 源代码
package org.openqa.selenium.chrome; import com.google.auto.service.AutoService; import java.io.File; import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.Browser; import org.openqa.selenium.remote.service.DriverService; public class ChromeDriverService extends DriverService { public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver"; public static final String CHROME_DRIVER_LOG_PROPERTY = "webdriver.chrome.logfile"; public static final String CHROME_DRIVER_APPEND_LOG_PROPERTY = "webdriver.chrome.appendLog"; public static final String CHROME_DRIVER_VERBOSE_LOG_PROPERTY = "webdriver.chrome.verboseLogging"; public static final String CHROME_DRIVER_SILENT_OUTPUT_PROPERTY = "webdriver.chrome.silentOutput"; public static final String CHROME_DRIVER_WHITELISTED_IPS_PROPERTY = "webdriver.chrome.whitelistedIps"; public static final String CHROME_DRIVER_DISABLE_BUILD_CHECK = "webdriver.chrome.disableBuildCheck"; public ChromeDriverService(File executable, int port, List<String> args, Map<String, String> environment) throws IOException { super(executable, port, DEFAULT_TIMEOUT, args, environment); } public ChromeDriverService(File executable, int port, Duration timeout, List<String> args, Map<String, String> environment) throws IOException { super(executable, port, timeout, args, environment); } public static ChromeDriverService createDefaultService() { return (ChromeDriverService)(new ChromeDriverService.Builder()).build(); } public static ChromeDriverService createServiceWithConfig(ChromeOptions options) { return (ChromeDriverService)(new ChromeDriverService.Builder()).withLogLevel(options.getLogLevel()).build(); } @AutoService({org.openqa.selenium.remote.service.DriverService.Builder.class}) public static class Builder extends org.openqa.selenium.remote.service.DriverService.Builder<ChromeDriverService, ChromeDriverService.Builder> { private final boolean disableBuildCheck = Boolean.getBoolean("webdriver.chrome.disableBuildCheck"); private boolean appendLog = Boolean.getBoolean("webdriver.chrome.appendLog"); private boolean verbose = Boolean.getBoolean("webdriver.chrome.verboseLogging"); private boolean silent = Boolean.getBoolean("webdriver.chrome.silentOutput"); private String whitelistedIps = System.getProperty("webdriver.chrome.whitelistedIps"); private ChromeDriverLogLevel logLevel = null; public Builder() { } public int score(Capabilities capabilities) { int score = 0; if (Browser.CHROME.is(capabilities.getBrowserName())) { ++score; } if (capabilities.getCapability("goog:chromeOptions") != null) { ++score; } return score; } public ChromeDriverService.Builder withAppendLog(boolean appendLog) { this.appendLog = appendLog; return this; } public ChromeDriverService.Builder withVerbose(boolean verbose) { this.verbose = verbose; return this; } public ChromeDriverService.Builder withLogLevel(ChromeDriverLogLevel logLevel) { this.logLevel = logLevel; return this; } public ChromeDriverService.Builder withSilent(boolean silent) { this.silent = silent; return this; } public ChromeDriverService.Builder withWhitelistedIps(String whitelistedIps) { this.whitelistedIps = whitelistedIps; return this; } protected File findDefaultExecutable() { return ChromeDriverService.findExecutable("chromedriver", "webdriver.chrome.driver", "https://chromedriver.chromium.org/", "https://chromedriver.chromium.org/downloads"); } protected List<String> createArgs() { if (this.getLogFile() == null) { String logFilePath = System.getProperty("webdriver.chrome.logfile"); if (logFilePath != null) { this.withLogFile(new File(logFilePath)); } } if (this.logLevel != null) { this.withLogLevel(this.logLevel); this.withVerbose(false); } if (this.verbose) { this.withLogLevel(ChromeDriverLogLevel.ALL); } List<String> args = new ArrayList(); args.add(String.format("--port=%d", this.getPort())); if (this.getLogFile() != null) { args.add(String.format("--log-path=%s", this.getLogFile().getAbsolutePath())); } if (this.appendLog) { args.add("--append-log"); } if (this.logLevel != null) { args.add(String.format("--log-level=%s", this.logLevel.toString().toUpperCase())); } if (this.silent) { args.add("--silent"); } if (this.whitelistedIps != null) { args.add(String.format("--whitelisted-ips=%s", this.whitelistedIps)); } if (this.disableBuildCheck) { args.add("--disable-build-check"); } return Collections.unmodifiableList(args); } protected ChromeDriverService createDriverService(File exe, int port, Duration timeout, List<String> args, Map<String, String> environment) { try { return new ChromeDriverService(exe, port, timeout, args, environment); } catch (IOException var7) { throw new WebDriverException(var7); } } } }