我正在尝试使用Chrome和ModHeader扩展程序在selenium网格上运行测试。
扩展程序使用Florent B在chrome modify headers in selenium java, i am able to add extension .crx through script
中提供的解决方案在本地加载但是我无法找出网格节点上没有加载扩展名的原因。运行以下代码时,实际上浏览器甚至无法打开。
你能帮帮忙吗?以下代码供您参考。此致 PRATIK
private static RemoteWebDriver UseSeleniumGrid()
{
var path =
Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName +
"\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\idgpnmonknjnojddfkpgkljpfnnfcklj\\extension_2_1_1.crx";
var options = new ChromeOptions();
options.AddExtension(Path.GetFullPath(path));
var capability = new DesiredCapabilities();
capability.SetCapability(ChromeOptions.Capability, options);
capability.SetCapability("browserName", "chrome");
return new CorrelatedDriver(
new Uri("http://localhost:4444/wd/hub"), capability, RemoteTimeout);
}
答案 0 :(得分:0)
管理以找到解决方案。
错误出现在行中:
var capability = new DesiredCapabilities();
capability.SetCapability(ChromeOptions.Capability, options);
根据https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/7043,在SeleniumDriver升级后无法以编程方式设置Chrome选项。解决方案是将选项转换为所需的功能。
以下工作代码:
private static RemoteWebDriver UseSeleniumGrid()
{
var path =
Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).FullName +
"\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\idgpnmonknjnojddfkpgkljpfnnfcklj\\extension_2_1_1.crx";
var options = new ChromeOptions();
options.AddExtension(Path.GetFullPath(path));
var capability = options.ToCapabilities() as DesiredCapabilities;
capability.SetCapability("browserName", "chrome");
return new CorrelatedDriver(
new Uri("http://localhost:4444/wd/hub"), capability, RemoteTimeout);
}