c# - 需要授权 RemoteSessionSettings Browserstack
问题描述
我正在替换DesiredCapabilities
,RemoteSessionSettings
但似乎 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
要添加的功能在主要功能对象之外时,或者如果您尝试传递多个特定于浏览器的选项类以可能匹配会话的多个浏览器中的任何一个,则该类很有用。
推荐阅读
- reactjs - react - material-ui单选按钮的勾选逻辑
- javascript - 如何在 div 内动态创建元素?
- mongodb - Mongodb:按自定义表达式排序
- javascript - history.push() 重定向 url 但组件不呈现(reactjs 应用程序)
- python - 上下文感知修改 - 熊猫
- linux - Apache2 没有启动,我使用的是 Ubuntu 16.04
- terminal - 如何让鱼吞下?或者至少从程序中脱离出来
- data-science - 这种称为 sqrt(max(x+1) - x) 的转换是什么?
- linux - 如何更改文本 Amazon Linux AMI 测试页
- sql-server - 从 Azure Blob 存储批量插入时出现 ERRORFILE 问题