Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ChromeDriver Unable to add Performance Logging in Selenium Java

I have looked at the web search results and answers on stackoverflow on this topic but I couldn't find anyone having same issue. Following is code to enable performance logging that I am using:

    ChromeOptions options = new ChromeOptions();

    // options.addArguments("--headless");
    options.addArguments("--remote-debugging-port=9222");
    options.addArguments("--no-sandbox");
    options.addArguments("--disable-application-cache");
    options.addArguments("--disable-notifications");
    options.addArguments("--disable-dev-shm-usage");
    options.addArguments("--disable-extensions");
    options.addArguments("--test-type");
    options.addArguments("start-maximized");
    options.addArguments("disable-infobars");
    //options.addArguments("user-data-dir=C:\\apps\\selenium\\chrome\\data");
    options.setExperimentalOption("useAutomationExtension", false);
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));

    // add Network logging
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    Map<String, Object> perfLogPrefs = new HashMap<String, Object>();
    perfLogPrefs.put("enableNetwork", true);
    perfLogPrefs.put("traceCategories", "devtools.network");
    options.setExperimentalOption("perfLoggingPrefs", perfLogPrefs);

    webDriver = new ChromeDriver(options);

    webDriver.manage().deleteAllCookies();
    webDriver.manage().window().maximize();

When executed, it gives following error:

    Starting ChromeDriver 80.0.3987.16 (320f6526c1632ad4f205ebce69b99a062ed78647-refs/branch-heads/3987@{#185}) on port 27252
    Only local connections are allowed.
    Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
org.openqa.selenium.InvalidArgumentException: invalid argument: entry 0 of 'firstMatch' is invalid
from invalid argument: perfLoggingPrefs specified, but performance logging was not enabled
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03

What am I missing in above? The code examples use ChromeDriver(Capabilities) but that is deprecated. Is there some other setting that I need to enable before adding performance logging?

Thanks

like image 825
sohail Avatar asked Aug 07 '26 22:08

sohail


1 Answers

I was able to find the answer on at SeleniumHQ issues. Essentially, CapabilityType.LOGGING_PREFS is broken in this version of ChromeDriver. I changed the line

options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

to

options.setCapability("goog:loggingPrefs", logPrefs);

the preference name was changed to goog:loggingPrefs to be W3C compliant. I was able to collect network logs after this change.

like image 176
sohail Avatar answered Aug 09 '26 12:08

sohail