【发布时间】:2017-05-03 16:16:33
【问题描述】:
我有一个使用 Selenium.WebDriver v3.4.0 的示例 UI 测试项目。
当我对本地驱动程序运行测试时,一切正常,但我想使用 Selenium Grid 2 让事情正常运行。
当我尝试实例化一个新的 RemoteWebDriver 时,我得到了一个几乎没有细节的异常。
Driver = new RemoteWebDriver(new Uri(GridUrl), Capabilities);
注意:GridUrl 是“http://localhost:4444/wd/hub”
使用 StackTrace 引发 System.InvalidOperationException,如下所示:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
at xxxx.Ui.Tests.SeleniumTests.TestInitialize() in C:\Users\xxxx\Documents\Visual Studio 2015\Projects\xxxx.Ui.Tests\xxxx.Tests\PersonTests.cs:line 38
集线器配置
我有 v3.4.0 的集线器在本地运行,配置如下:
{
"port": 4444,
"newSessionWaitTimeout": -1,
"servlets" : [],
"withoutServlets": [],
"custom": {},
"capabilityMatcher":"org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"throwOnCapabilityNotPresent": true,
"cleanUpCycle": 5000,
"role": "hub",
"debug": false,
"browserTimeout": 0,
"timeout": 1800
}
中心开始于:
java -jar selenium-server-standalone-3.4.0.jar -role hub
节点配置
我尝试了许多节点(chromedriver.exe、IEDriverServer.exe 和 geckodrvier.exe)。这些都不适用于 RemoteWebDriver。它们都位于已添加到我的系统 PATH 变量中的目录中。
Chrome 配置
{
"capabilities":
[
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
}
],
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5556,
"register": true,
"registerCycle": 5000,
"hub": "http://localhost:4444",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
节点开始于:
java -jar selenium-server-standalone-3.4.0.jar -role node -nodeConfig chromeNodeConfig.json
除了浏览器名称和端口不同之外,其他节点配置基本相同。
我无法从异常中得到很多。这是我拥有的驱动程序的版本问题吗?我尝试自定义我的 DesiredCapabilities 以确保我匹配节点配置中的那些。所有这些看起来都很好。
更新
根据要求,我将添加更多关于我如何尝试启动浏览器的详细信息。没有一个浏览器与 RemoteWebDriver 一起使用,而它们与本地驱动程序一起使用。显示 Chrome 示例 - 每个之间的唯一区别在于我传递给基类构造函数的功能。
在我的测试课中
[TestClass]
public class PersonTests : PersonTestBase
{
public PersonTests()
: base(DesiredCapabilities.Chrome())
{
}
[TestCategory("Chrome")]
[TestMethod]
public void Chrome_ShouldCreatePlacement()
{
this.ShouldCreatePerson();
}
}
在我的基类中,我正在执行以下操作
public abstract class PersonTestBase
{
protected IWebDriver Driver;
protected ICapabilities Capabilities;
protected string TargetUrl;
protected string GridUrl;
protected PersonTests(ICapabilities capabilities)
{
this.Capabilities = capabilities;
}
[TestInitialize]
public void TestInitialize()
{
TargetUrl = "http://urlOfMyWebsite";
GridUrl = "http://localhost:4444/wd/hub"
Driver = new RemoteWebDriver(new Uri(GridUrl), Capabilities);
}
[TestCleanup]
public void TestCleanup()
{
Driver.Quit();
}
protected void ShouldCreatePerson()
{
Driver.Navigate().GoToUrl(TargetUrl);
//rest of test code ommitted
}
}
【问题讨论】:
-
可能要检查任务管理器并确保您没有一堆仍在运行的流氓浏览器驱动程序实例。在本地调试时可能会发生这种情况。这给我们带来了许多问题。
-
感谢您的建议。我明天去看看!
-
您要启动什么浏览器?你能提供更多关于你是如何做到这一点的代码吗?
-
我已按要求添加了更新。 @GrayDwarf - 感谢您的建议。我有许多 ChromeDriver 进程正在运行,但重新启动了我的机器并重新运行了测试,但仍然是同样的异常。
标签: c# selenium selenium-grid remotewebdriver