使用自定义firefox配置文件运行Selenium grid 2

本文关键字:Selenium grid 运行 配置文件 自定义 firefox | 更新日期: 2023-09-27 18:11:52

如何从代码中使用自定义firefox配置文件运行Selenium grid 2。

这是我现在的代码:

 DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
            capabilities.SetCapability(CapabilityType.AcceptSslCertificates, true);
            capabilities.SetCapability(CapabilityType.HasNativeEvents, false);
            capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
            capabilities.IsJavaScriptEnabled = true;               
            Uri url = new Uri("http://localhost:4444/wd/hub");
            RemoteWebDriver driver = new RemoteWebDriver(url, capabilities);
            return driver;

我唯一剩下的就是强制Selenium grid使用我的自定义配置文件

使用自定义firefox配置文件运行Selenium grid 2

找到解决方案:

 var firefoxProfile = new FirefoxProfile();
// configure firefoxProfile ...
DesiredCapabilities capabilities = DesiredCapabilities.Firefox();
            capabilities.SetCapability(CapabilityType.AcceptSslCertificates, true);
            capabilities.SetCapability(CapabilityType.HasNativeEvents, false);
            capabilities.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
            capabilities.IsJavaScriptEnabled = true;                
            capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, firefoxProfile.ToBase64String());
            Uri url = new Uri("http://localhost:4444/wd/hub");
            RemoteWebDriver driver = new RemoteWebDriver(url, capabilities);
            return driver;