首页 > 解决方案 > 为什么在 selenium 网格中使用 chrome remotewebdriver 时无法捕获网络日志?

问题描述

你好 Stackoverflow 社区,

我想在使用 Selenium Grid 的 Web 自动化测试时捕获网络流量(实际上,我正在使用 VM 来部署 selenium 网格架构(集线器和节点))。下面是我用来获取网络日志的代码:

ChromeOptions chromeOptions = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
chromeOptions.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
chromeOptions.setCapability("platform", platform);
chromeOptions.addArguments(
                    "--headless",
                    "--verbose",
                    "--disable-web-security",
                    "--allow-insecure-localhost",
                    "--ignore-certificate-errors",
                    "--allow-running-insecure-content",
                    "--no-sandbox",
                    "--disable-popup-blocking",
                    "--disable-dev-shm-usage",
                    "--ignore-certificate-errors",
                    "--silent"
            );
this.driver = new RemoteWebDriver(new URL("http://172.20.10.10:4444/wd/hub"), chromeOptions);
this.driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
this.driver.manage().window().maximize();
this.driver.get(website);

List<LogEntry> entries = driver.manage().logs().get(LogType.PERFORMANCE).getAll();
System.out.println(entries.size() + " " + LogType.PERFORMANCE + " log entries found");
for (LogEntry entry : entries) {
    System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
}

但我得到这个错误:

Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument: log type 'performance' not found
  (Session info: headless chrome=78.0.3904.108)
System info: host: 'themadmalik', ip: '***.***.***.***', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.2'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.108, chrome: {chromedriverVersion: 78.0.3904.105 (60e2d8774a81..., userDataDir: /tmp/.com.google.Chrome.tNFy6o}, goog:chromeOptions: {debuggerAddress: localhost:45465}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 06521c2b5573343d789ba1302c4...}

有人知道我该如何解决这个问题?

谢谢!

标签: javaselenium-chromedriverselenium-gridgoogle-chrome-headlessnetwork-traffic

解决方案


推荐阅读