【发布时间】:2020-11-12 19:24:42
【问题描述】:
背景 - 试图让 ChromeDriver 进行日志记录,以便我可以开始使用 Lighthouse。
我正在尝试获取与 this 等效的 C# Selenium.Webdriver
DesiredCapabilities cap = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
cap.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
Map<String, Object> perfLogPrefs = new HashMap<String, Object>();
perfLogPrefs.put("traceCategories", "browser,devtools.timeline,devtools"); // comma-separated trace categories
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("perfLoggingPrefs", perfLogPrefs);
caps.setCapability(ChromeOptions.CAPABILITY, options);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), cap);
我想不出正确的组合。任何人都知道正确的食谱是什么,或者有一个例子,或两者兼而有之?
我的尝试
var chromeOptions = new Dictionary<string, object>();
List<string> args = new List<string>();
foreach (string ma in myArgs) //yes, myArgs is created beforehand
args.Add(ma);
chromeOptions.Add("args", args);
var options = new Dictionary<string, object>();
var loggingPrefs = new Dictionary<string, object>();
loggingPrefs.Add("PERFORMANCE", "ALL" );
var perfLoggingPrefs = new Dictionary<string, object>();
perfLoggingPrefs.Add("enableNetwork", true);
perfLoggingPrefs.Add("enablePage", true);
perfLoggingPrefs.Add("traceCategories", "toplevel,disabled-by-default-devtools.timeline.frame,blink.console,disabled-by-default-devtools.timeline,benchmark");
options.Add("chromeOptions", chromeOptions);
options.Add("loggingPrefs", loggingPrefs);
options.Add("perfLoggingPrefs", perfLoggingPrefs);
var capabilities = new DesiredCapabilities(options);
Driver = new RemoteWebDriver(new Uri("http://localhost:9515"), capabilities);
结果:没有记录
【问题讨论】:
标签: c# logging selenium-webdriver selenium-chromedriver