Selenium RemoteWebDriver c# – System.InvalidOperationException
我有一个使用Selenium.WebDriver的v3.4.0的示例UI测试项目。
当我针对本地驱动程序运行测试时,一切正常,但我想使用Selenium Grid 2来完成工作。
一旦我尝试实例化一个新的RemoteWebDriver,我就会得到一个细节很少的exception。
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 }
Hub始于:
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
除了不同的浏览器名称和端口之外,其他节点配置大致相同。
启动所有节点后,控制台如下所示:
我无法从exception中获得太多。 这是我的驱动程序的版本问题吗? 我已经尝试自定义DesiredCapabilities以确保我匹配节点配置中的那些。 所有这一切看起来都很好。
更新
根据要求,我正在添加一些关于我如何尝试启动浏览器的细节。 没有一个浏览器使用RemoteWebDriver,而它们使用本地驱动程序。 显示Chrome示例 – 每个之间的区别仅在于我传递给基类构造函数的function。
在我的测试课上
[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 } }
降级到3.3.0,直到此问题得到解决,并且可以使用新版本的Selenium Standalone Server(推荐的解决方案)
要么
- 下载解决方案
- 评论这一行
- 构建dotnet语言绑定
- 在根目录中打开命令窗口
- 运行
go //dotnet:release
- 并引用{root} / build / dotnet / dist中构建的二进制文件
注意:此解决方法不能解决任何问题! 它忽略了导致失败的selenium网格代码。
另请注意:请注意升级到Selenium 3.4可能还需要升级Web驱动程序
V3.5.1修复了此问题。
使用NuGET管理器和您的selenium-standalone jar升级您的Selenium NuGET包。
由斯蒂芬建议降级至3.3.0可能导致已知问题 。 尝试降级到v3.3.1。
你可以从这里获得v3.3.1: http ://selenium-release.storage.googleapis.com/index.html?path = 3.3 /