gpt4 book ai didi

java - 如何抑制 Selenium 日志

转载 作者:行者123 更新时间:2023-12-01 18:34:14 28 4
gpt4 key购买 nike

在我的自动测试中,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

任何想法;/

最佳答案

抑制ChromeChromeDriver相关日志可以使用以下解决方案:

  • 代码块:

    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

关于java - 如何抑制 Selenium 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60092356/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com