我正在努力获取网络开发人员日志以进行性能测试。下面是我正在使用的代码,这是我遇到的错误。我有些困惑,不能完全确定为什么我无法初始化我的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;
}
问题不一样,LoggingPreferences和DesiredCapibiliies在3.141.0中已弃用
答案 0 :(得分:0)
您需要启用性能日志记录。
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
答案 1 :(得分:0)
不确定是否可以找到任何解决方案。到目前为止,我正在使用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驱动程序提取性能日志的解决方案