需要授权 RemoteSessionSettings Browserstack

Authorization required RemoteSessionSettings Browserstack

我正在用 RemoteSessionSettings 替换 DesiredCapabilities,但 BrowserStack 似乎无法验证我的身份。

我怎样才能仍然使用RemoteSessionSettings以便我仍然可以在 BrowserStack 中执行并行测试?

下面是我的示例代码:

var capSettings = new RemoteSessionSettings();
capSettings.AddMetadataSetting("browserstack.user", ConfigurationManager.AppSettings.Get("user"));
capSettings.AddMetadataSetting("browserstack.key", ConfigurationManager.AppSettings.Get("key"));

capSettings.AddMetadataSetting("browser", "chrome");
capSettings.AddMetadataSetting("os", "Windows");
capSettings.AddMetadataSetting("os_version", "10");
capSettings.AddMetadataSetting("name", TestName);

driver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"), capSettings);

非常感谢您的帮助!

使用 AddMetadataSetting 方法将属性放在新会话命令负载的错误部分,以便 BrowserStack 正常工作。你想要的是类似下面的东西:

Dictionary<string, object> browserStackOptions = new Dictionary<string, object>();
browserStackOptions.Add("userName", ConfigurationManager.AppSettings.Get("user"));
browserStackOptions.Add("accessKey", ConfigurationManager.AppSettings.Get("key"));

browserStackOptions.Add("os", "Windows");
browserStackOptions.Add("osVersion", "10");
browserStackOptions.Add("sessionName", TestName);

ChromeOptions options = new ChromeOptions();

// N.B., the below line of code is specific to
// the 4.0 alpha of the .NET bindings. To
// use a 3.x version, use:
// options.AddAdditionalCapability("bstack:options", browserStackOptions, true);
options.AddAdditionalOption("bstack:options", browserStackOptions);

// If you truly need RemoteSessionSettings,
// you can do the following:
// RemoteSessionSettings settings = new RemoteSessionSettings(null, options);
// IWebDriver driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), settings);
IWebDriver driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), options);

RemoteSessionSettings class 当要添加的功能在主要功能对象之外时,或者如果您试图传递多个特定于浏览器的选项 classes可能匹配会话的多个浏览器中的任何一个。