我想送Selenium测试使用DriverOptions
类saucelabs。据this链接,你需要一个酱:选件配置,并根据this发布字典就行了。这里是我的设置:
DriverOptions options = new ChromeOptions
{
PlatformName = "Windows 10",
BrowserVersion = "latest"
};
IDictionary<string, string> sauceOptions = new Dictionary<string, string>
{
{ "username", SauceUsername },
{ "accessKey", SauceAccessKey },
{ "name", TestContext.TestName },
{ "seleniumVersion", "3.11.0" }
};
options.AddAdditionalCapability("sauce:options", sauceOptions);
_driver = new RemoteWebDriver(new Uri("http://@ondemand.saucelabs.com:80/wd/hub"),
options.ToCapabilities(), TimeSpan.FromSeconds(600));
我上WebDriverException
init一个RemoteWebDriver
,说Misconfigured -- Sauce Labs Authentication Error. You used username 'None' and access key 'None' to authenticate
。这是奇怪,因为
我ACCESSKEY的最后几个数字是正确的,这是我的用户名,所以我清楚地发送正确的凭据
http://{SauceUsername}:{SauceAccessKey}@ondemand
...)它的工作原理,但我不能在任何其他酱选项通过。谢谢!
使用AddAdditionalCapability
重载,有三个参数,而不是两个。这告诉ChromeOptions
实例添加字典的JSON有效载荷的顶层,而不是作为goog:chromeOptions
财产的一部分。这里是什么样子:
// Note, you must use the specific class here, rather than the
// base class, as the base class does not have the proper method
// overload. Also, the UseSpecCompliantProtocol property is required.
ChromeOptions options = new ChromeOptions
{
PlatformName = "Windows 10",
BrowserVersion = "latest",
UseSpecCompliantProtocol = true
};
Dictionary<string, object> sauceOptions = new Dictionary<string, object>
{
{ "username", SauceUsername },
{ "accessKey", SauceAccessKey },
{ "name", TestContext.TestName },
{ "seleniumVersion", "3.11.0" }
};
options.AddAdditionalCapability("sauce:options", sauceOptions, true);
_driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"),
options.ToCapabilities(), TimeSpan.FromSeconds(600));