Skip to content

Enabling Performance Log for Chrome

Jakub Raczek edited this page Dec 17, 2018 · 6 revisions

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()
        {
            this.DriverContext.IsTestFailed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed || !this.driverContext.VerifyMessages.Count.Equals(0);
            this.SaveTestDetailsIfTestFailed(this.driverContext);
            this.LogTest.LogTestEnding(this.driverContext);
            this.LogTest.LogTestEnding(this.driverContext);
            var logs = this.driverContext.Driver.Manage().Logs;
            var perfLogs = logs.GetLog("performance");
            foreach (var perfLog in perfLogs)
            {
                Logger.Info(perfLog.ToString);
            }
            if (this.IsVerifyFailedAndClearMessages(this.driverContext) && TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed)
            {
                Assert.Fail();
            }
        }

more details here.

Clone this wiki locally