我正在寻找一种获取 Selenium 性能日志的方法。我遇到了一种使用下面的代码获取日志条目的方法:
val loggingPrefs = LoggingPreferences()
loggingPrefs.enable(LogType.PERFORMANCE, Level.ALL)
val capabilities = DesiredCapabilities.chrome()
capabilities.setCapability("goog:loggingPrefs", loggingPrefs)
driver = RemoteWebDriver(driverService.url, capabilities)
...
val logEntries = driver.manage().logs().get(LogType.PERFORMANCE)
driver.close()
driver.quit()
logEntries.forEach {
print(it.message)
}
但我正在寻找一种实时获取这些日志的方法,例如流或某些回调方法,以便我可以在另一个线程或协程上实时处理它。我将不胜感激任何帮助。谢谢
最佳答案
你可以这样做:
@Test
public void logTest() {
new Thread(() -> {
while(true){
System.out.println("Logs from separate thread: " + driver.manage().logs().get(LogType.PERFORMANCE).getAll());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
System.out.println("Main thread is now sleeping");
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
关于java - 实时获取 Selenium 性能日志(Java、Kotlin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61528377/