簡體   English   中英

如何在C#中為Chlenium Grid 2的Chrome添加配置文件首選項?

[英]How can I add profile preferences to Chrome for Selenium Grid 2 in C#?

這是我為Chrome進行本地自動測試運行和TeamCity(CI)添加配置文件首選項的方法:

Capabilities = DesiredCapabilities.Chrome();

var chromeOptions = new ChromeOptionsWithPrefs();
chromeOptions.AddUserProfilePreference("download.default_directory", DownloadPath);
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");

return new ChromeDriver(chromeDriverPath, chromeOptions);

但是當我創建新的“RemoteWebDriver”時,我必須向它發送一個中心URL和“功能”,這樣我就可以將配置文件首選項發送到Firefox(到RemoteWebDriver):

var profile = new FirefoxProfile();

Capabilities = DesiredCapabilities.Firefox();

profile.SetPreference("browser.helperApps.alwaysAsk.force", false); 
profile.SetPreference("browser.download.useDownloadDir", true);
profile.SetPreference("browser.download.folderList", 2);
profile.SetPreference("browser.download.dir", DownloadPath);
profile.SetPreference("browser.helperApps.neverAsk.saveToDisk",
   "application/zip, application/octet-stream");

Capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());

return Capabilities;

有人可以幫助我,我需要像Chrome一樣對Chrome做同樣的事情。 基本上我需要的是,我可以更改下載文件的默認路徑。

您需要執行以下操作:

var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("download.default_directory", DownloadPath);
chromeOptions.AddUserProfilePreference("intl.accept_languages", "nl");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");

IWebDriver driver = new RemoteWebDriver(new Uri("http://path/to/selenium/server"), chromeOptions.ToCapabilities());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM