Selenium Web Driver:提取的Chrome浏览器日志不完整。

3

我正在使用Selenium为Vaadin应用编写浏览器测试。在Chrome浏览器的开发工具中,控制台显示了不同日志级别(TRACE、SEVERE、WARNING)的日志。以下代码设置了我的测试驱动程序:

@RunOnHub
public abstract class SmokeTestCase extends ParallelTest {
    ...
        final ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setHeadless(false);
        final LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        chromeOptions.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
        setDriver(new ChromeDriver(chromeOptions));
    ...

我的 Vaadin 应用程序以 DEV 模式运行。使用以下代码,我正在尝试通过测试驱动程序检索所有浏览器日志:

final LogEntries entries = this.driver.manage().logs().get(LogType.BROWSER);
for (LogEntry entry: entries) {
  System.out.println(entry);
  final String line = String.format("[%s] - %s - %s", entry.getLevel().getName(), entry.getTimestamp(), entry.getMessage());
  if (entry.getLevel() == Level.SEVERE) {
    System.err.println(line);
  } else {
    System.out.println(line);
  }
}

很遗憾,我只能接收到WARNING和SEVERE类型的日志,INFO和TRACE类型的日志无法获取。我是不是做错了什么?
我的方法类似于这个链接中的方法:如何使用Selenium获取Chrome浏览器控制台日志[INFO]条目 我们还尝试启用和请求DRIVER或CLIENT类型的日志 - 但它们是空的。
Chrome Driver日志文件:
[1563798293,491][INFO]: [9a5a5e7219d7e4e784ad1ccf205a31df] COMMAND GetLog {
   "type": "browser"
}
[1563798293,491][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=2292) 143AE946F7F1974C2722E6519DB6CBA5 {
   "expression": "1",
   "returnByValue": true
}
[1563798293,491][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=2292) 143AE946F7F1974C2722E6519DB6CBA5 {
   "result": {
      "description": "1",
      "type": "number",
      "value": 1
   }
}
[1563798293,491][INFO]: [9a5a5e7219d7e4e784ad1ccf205a31df] RESPONSE GetLog [ {
   "level": "SEVERE",
   "message": "http://.../APP/connector/0/443/icon/save-document_24.png - Failed to load resource: the server responded with a status of 410 ()",
   "source": "network",
   "timestamp": 1563798292695.0
}, {
   "level": "SEVERE",
   "message": "http://.../APP/connector/0/444/icon/container_3_24.png - Failed to load resource: the server responded with a status of 410 ()",
   "source": "network",
   "timestamp": 1563798292695.0
}, {
   "level": "WARNING",
   "message": "http://.../VAADIN/vaadinPush.js?v=8.7.2 0:40212 \"Websocket closed, reason: Normal closure; the connection successfully completed whatever purpose for which it was created. - w...",
   "source": "console-api",
   "timestamp": 1563798292711.0
}, {
   "level": "SEVERE",
   "message": "http://.../APP/connector/0/448/icon/save-document_24.png - Failed to load resource: the server responded with a status of 410 ()",
   "source": "network",
   "timestamp": 1563798292711.0
}, {
   "level": "WARNING",
   "message": "http://.../VAADIN/vaadinPush.js?v=8.7.2 0 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more...",
   "source": "deprecation",
   "timestamp": 1563798292776.0
} ]
1个回答

9
自从ChromeDriver 75.0.3770.8版本起,CapabilityType.LOGGING_PREFS已被弃用,请使用goog:loggingPrefs代替。

1
你是英雄! - PAX
1
在使用83版本时,goog:loggingPrefs是最佳选择。 - Ali Niaki

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接