几天前我已经将Selenium库更新到最新的4.1.4。早先我使用的是旧版本,比如3.141.59,当我执行TestNG测试时,我只能从ITestListener, Reporter和TestNG中获得日志。
现在,当我执行测试时,我得到了一堆我不需要的日志。我在代码中没有设置任何与日志相关的内容。如何禁用该日志?
它看起来像:
[RemoteTestNG] detected TestNG version 7.4.0
08:58:45.409 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
08:58:45.416 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
08:58:45.416 [main] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4
08:58:45.420 [main] DEBUG io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@352ff4da
08:58:45.442 [main] DEBUG io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
08:58:45.442 [main] DEBUG io.netty.util.internal.PlatformDependent0 - Java version: 15
08:58:45.443 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
08:58:45.444 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
08:58:45.444 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
08:58:45.445 [main] DEBUG io.netty.util.internal.PlatformDependent0 - direct buffer constructor: unavailable: Reflective setAccessible(true) disabled
08:58:45.446 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
如果您使用logback进行日志记录,那么在src/main/resources
下创建logback.xml
配置文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOGS" value="./logs" />
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
%d{yyyy-MM-dd HH:mm.ss} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="Console" />
</root>
</configuration>
基本上将根级别设置为"info"就能解决问题。Selenium 4默认将根级别打印为"debug"