首页 > 解决方案 > 需要授权 RemoteSessionSettings Browserstack

问题描述

我正在替换DesiredCapabilitiesRemoteSessionSettings但似乎 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);

非常感谢您的帮助!

标签: c#seleniumselenium-webdriverbrowserstack

解决方案


使用该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要添加的功能在主要功能对象之外时,或者如果您尝试传递多个特定于浏览器的选项类以可能匹配会话的多个浏览器中的任何一个,则该类很有用。


推荐阅读