我正在尝试使用带有C#的Selenium WebDriver的W3C规范进行测试。 基于阅读W3C文档here,我认为这是正确的代码。
[Test]
public void SimpleSelenium4Example()
{
//TODO please supply your Sauce Labs user name in an environment variable
var sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);
//TODO please supply your own Sauce Labs access Key in an environment variable
var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User);
var options = new EdgeOptions()
{
BrowserVersion = "latest",
PlatformName = "Windows 10"
};
var sauceOptions = new JObject
{
["username"] = sauceUserName,
["accessKey"] = sauceAccessKey,
["name"] = TestContext.CurrentContext.Test.Name
};
options.AddAdditionalCapability("sauce:options", sauceOptions.ToString());
Driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), options.ToCapabilities(),
TimeSpan.FromSeconds(600));
Driver.Navigate().GoToUrl("https://www.google.com");
Assert.Pass();
}
我收到此错误 OpenQA.Selenium.WebDriverException:“意外的服务器错误。” 在实例化RemoteWebDriver时。
不确定是什么问题。任何帮助表示赞赏。
答案 0 :(得分:1)
.NET绑定适当地序列化了对象;根本不需要尝试使用Json.NET API(因为您使用JObject
意味着您是),并且可以在通过网络传输之前序列化JSON对象(使用ToString()
)。不成功。
[Test]
public void SimpleSelenium4Example()
{
//TODO please supply your Sauce Labs user name in an environment variable
var sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User);
//TODO please supply your own Sauce Labs access Key in an environment variable
var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User);
var options = new EdgeOptions()
{
BrowserVersion = "latest",
PlatformName = "Windows 10"
};
var sauceOptions = new Dictionary<string, object>();
sauceOptions["username"] = sauceUserName;
sauceOptions["accessKey"] = sauceAccessKey;
sauceOptions["name"] = TestContext.CurrentContext.Test.Name;
options.AddAdditionalCapability("sauce:options", sauceOptions);
Driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), options.ToCapabilities(),
TimeSpan.FromSeconds(600));
Driver.Navigate().GoToUrl("https://www.google.com");
Assert.Pass();
}