我一直试图禁用调试消息控制台,但无论我做什么,它仍然显示在控制台上。我需要找到一种方法来禁用HTTP请求和响应的控制台上的持续日志记录。代码使用:
System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.SEVERE);
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", downloadPath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(ChromeOptions.CAPABILITY, options);
// options.setCapability(ChromeOptions.CAPABILITY, options);
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
options.addArguments("--disable-logging");
options.addArguments("--log-level=3");
options.addArguments("--silent");
options.setCapability( "goog:loggingPrefs", logPrefs );
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
options.setAcceptInsecureCerts(true);
System.out.println("Launching Google Chrome Browser");
//ChromeDriverManager.getInstance(CHROME).setup();
WebDriverManager.chromedriver().setup();
// options.merge(cap);
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(TimeOut,TimeUnit.SECONDS);
driver.manage().window().maximize();
在控制台上
Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
POST /session HTTP/1.1
User-Agent: selenium/4.0.0 (java windows)
Content-Length: 1259
Content-Type: application/json; charset=utf-8
host: localhost:61670
accept: */*
Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
cache-control: no-cache
content-length: 788
[AsyncHttpClient-1-2] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Adding key: http://localhost:61670 for channel [id: 0xaa9e94af, L:/127.0.0.1:63133 - R:localhost/127.0.0.1:61670]
[AsyncHttpClient-1-3] DEBUG org.asynchttpclient.netty.channel.NettyConnectListener - Using new Channel '[id: 0x60845110, L:/127.0.0.1:63145 - R:localhost/127.0.0.1:63134]' for 'GET' to '/json/version'
[AsyncHttpClient-1-3] DEBUG org.asynchttpclient.netty.handler.HttpHandler -
Request DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE)
GET /json/version HTTP/1.1
User-Agent: selenium/4.0.0 (java windows)
host: localhost:63134
accept: */*
Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
content-length: 424
我需要找到一种在执行过程中删除调试消息的方法,Selenium 4.0上会出现这种情况
2条答案
按热度按时间1qczuiv01#
解决方案-空配置要修复此问题,请创建一个空配置文件logback-test.xml,并将其保存在$project/src/test/resources下
$项目/源代码/测试/资源/回登录-测试.xml
访问以下网站了解更多参考https://mkyong.com/logging/logback-disable-logging-in-unit-test/
v7pvogib2#
只需更改日志记录级别:
致:
或者比
SEVERE
低的某个电平。参见https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html