0

如何使用代码中的自定义 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 网格使用我的自定义配置文件。

4

1 回答 1

1

找到解决方案:

 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;
于 2013-05-02T12:14:40.743 回答