Skip to content

Enabling Performance Log for Chrome

bialkos edited this page Mar 15, 2021 · 6 revisions

Note: this function is temporarily not working due to an issue within Selenium: https://github.com/SeleniumHQ/selenium/issues/7335

Performance logging is NOT enabled by default. So when creating a new session, you have to enable it in ProjectTestBase class.

public ProjectTestBase()
        {
            this.driverContext.DriverOptionsSet += this.DriverContext_DriverOptionsSet;
        }
...

        private void DriverContext_DriverOptionsSet(object sender, DriverOptionsSetEventArgs args)
        {
            if (args == null || args.DriverOptions == null)
            {
                throw new ArgumentNullException();
            }

            args.DriverOptions.SetLoggingPreference("performance", OpenQA.Selenium.LogLevel.All);
            args.DriverOptions.SetLoggingPreference(LogType.Browser, OpenQA.Selenium.LogLevel.All);
        }

and collect them after test

        [TearDown]
        public void AfterTest()
        {
            var logs = this.driverContext.Driver.Manage().Logs;
            var perfLogs = logs.GetLog("performance");
            foreach (var perfLog in perfLogs)
            {
                Logger.Info(perfLog.ToString);
            }
        }

more details here.

Clone this wiki locally