Selenium.Webdriver 3.141.0获取Chrome Developer工具中的网络日志



我正在努力获取网络开发人员日志以进行性能测试。以下是我正在使用的代码,这是我遇到的错误。我有点卡住,并且不完全确定为什么我无法初始化我的ChromeDriver。您如何正确检索网络devtools登录以进行性能?

OpenQA.Selenium.WebDriverException: 'invalid argument: entry 0 of 'firstMatch' is invalid from invalid argument: perfLoggingPrefs specified, but performance logging was not enabled'

public Driver(ChromeDriverModel chromeDriverModel)
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            enablePerformanceMonitor = chromeDriverModel.enablePerformanceMonitoring;
            if (enablePerformanceMonitor)
                chromeOptions = _ChromePerformanceOptions();
            if (!string.IsNullOrWhiteSpace(chromeDriverModel.ChromeDriverLocation))
            {
                if (enablePerformanceMonitor)
                    _webDriver = new ChromeDriver(chromeDriverModel.ChromeDriverLocation, chromeOptions);
                else
                    _webDriver = new ChromeDriver(chromeDriverModel.ChromeDriverLocation);
            }
            else
            {
                if (enablePerformanceMonitor)
                    _webDriver = new ChromeDriver(chromeOptions);
                else
                    _webDriver = new ChromeDriver();
            }
        }

private ChromeOptions _ChromePerformanceOptions()
        {
            var option = new ChromeOptions();
            var perfLogPrefs = new ChromePerformanceLoggingPreferences();
            perfLogPrefs.AddTracingCategories(new string[] { "devtools.network", "devtools.timeline" });
            option.PerformanceLoggingPreferences = perfLogPrefs;
            option.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true);
            option.SetLoggingPreference("performance", LogLevel.All);
            return option;
        }

问题不是相同的,LoggingPreference和所需的capibiliies已在3.141.0

中被弃用

您需要启用性能记录。

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);

不确定您是否能够找到任何解决方案。截至目前,我正在使用Selenium Webdriver v3.141和Selenium.Chrome.Webdriver v2.35,我可以获取性能日志。

ChromeOptions options = new ChromeOptions();
var perfLogPrefs = new ChromePerformanceLoggingPreferences();
options.PerformanceLoggingPreferences = perfLogPrefs;
options.SetLoggingPreference("performance", LogLevel.All);
//Write code to launch driver and application url
//prints the logs
for (int i = 0; i < logs.Count; i++)
{
    Console.WriteLine(logs[i].Message);
}

注意:我仍然无法使用最新的Selenium Chrome Driver

找到解决方案来提取性能日志

相关内容

  • 没有找到相关文章

最新更新