在我的自动测试中,chrome创建了很多日志。我尝试了很多方法,没有任何帮助。我目前有这个:
System.setProperty("webdriver.chrome.silentOutput", "true");
ChromeOptions options = new ChromeOptions();
options.addArguments(
"--disable-logging",
"--log-level=OFF",
"--silent"
);
System.setProperty(browsers.getConfigInfo(),browsers.getDriverPath());
WebDriver driver = new ChromeDriver(options);
但仍然看到这个:
10:59:11.456 [Forwarding isElementDisplayed on session b316a03b20f1dc9b067b1f59ad01c1ed to remote] DEBUG org.apache.http.headers - http-outgoing-0 >> Cache-Control: no-cache
10:59:11.456 [Forwarding isElementDisplayed on session b316a03b20f1dc9b067b1f59ad01c1ed to remote] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: localhost:18288
10:59:11.456 [Forwarding isElementDisplayed on session b316a03b20f1dc9b067b1f59ad01c1ed to remote] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
10:59:11.456 [Forwarding isElementDisplayed on session b316a03b20f1dc9b067b1f59ad01c1ed to remote] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.5 (java 1.5)
10:59:11.456 [Forwarding isElementDisplayed on session b316a03b20f1dc9b067b1f59ad01c1ed to remote] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
任何想法; /
答案 0 :(得分:0)
要禁止与 Chrome 和ChromeDriver相关的日志,您可以使用以下解决方案:
代码块:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
System.setProperty("webdriver.chrome.logfile", "C:\\Utility\\BrowserLogs\\ChromeDriver_logs.log");
System.setProperty("webdriver.chrome.verboseLogging", "true");
ChromeOptions options = new ChromeOptions();
options.setCapability(LogType.BROWSER, Level.ALL);
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.seleniumhq.org/");
driver.quit();
控制台输出(包括最小的日志集):
Starting ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185}) on port 9989
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Feb 06, 2020 3:45:25 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C