通SauceLabs的用户名/ ACCESSKEY到DriverOptions类

问题描述 投票:0回答:1

我想送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));

我上WebDriverExceptioninit一个RemoteWebDriver,说Misconfigured -- Sauce Labs Authentication Error. You used username 'None' and access key 'None' to authenticate。这是奇怪,因为

  1. 我还给我用所需的瓶盖,其分别为: 收到了下列所需的功能:{ 'browserName': '铬', 'browserVersion': '最新', 'goog:chromeOptions':{ '酱:选择':{ '快捷键':“XXXXXXXX-XXXXXXXX-XXXX -XXXX163edf42' , '名': 'DriverOptionsTest', 'seleniumVersion': '3.11.0', '用户名': 'kroe761'}}, 'platformName': '视窗10'}

我ACCESSKEY的最后几个数字是正确的,这是我的用户名,所以我清楚地发送正确的凭据

  1. 如果我删除了字典和直接传递用户名和ACCESSKEY到RemoteDriver URI(http://{SauceUsername}:{SauceAccessKey}@ondemand ...)它的工作原理,但我不能在任何其他酱选项通过。

谢谢!

c# selenium-webdriver saucelabs
1个回答
3
投票

使用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));
© www.soinside.com 2019 - 2024. All rights reserved.