Selenium RemoteWebDriver C#-System.InvalidOperationException [英] Selenium RemoteWebDriver c# - System.InvalidOperationException
问题描述
我有一个使用Selenium.WebDriver v3.4.0的示例UI测试项目.
I have a sample UI test project using v3.4.0 of Selenium.WebDriver.
当我对本地驱动程序运行测试时,一切都很好,但是我想使用Selenium Grid 2使其正常工作.
Everything works fine when I run the tests against a local driver but I want to get things working using Selenium Grid 2.
当我尝试实例化一个新的RemoteWebDriver时,我得到的异常很少.
As soon as I try to instantiate a new RemoteWebDriver I get an exception with little detail.
Driver = new RemoteWebDriver(new Uri(GridUrl), Capabilities);
注意:GridUrl是" http://localhost:4444/wd/hub "
Note: GridUrl is "http://localhost:4444/wd/hub"
使用StackTrace引发System.InvalidOperationException,如下所示:
Throws a System.InvalidOperationException with StackTrace as follows:
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:
Hub configuration
I have v3.4.0 of the hub running locally with the following configuration:
{
"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
java -jar selenium-server-standalone-3.4.0.jar -role hub
这已经可以了,看起来正在运行.
This has come up OK and looks to be running.
我尝试了许多节点(chromedriver.exe,IEDriverServer.exe和geckodrvier.exe).这些都不能与RemoteWebDriver一起使用.所有这些都位于已添加到我的系统PATH变量的目录中.
I have tried a number of nodes (chromedriver.exe, IEDriverServer.exe and geckodrvier.exe). None of these work with the RemoteWebDriver. All of them are in a directory that has been added to my system PATH variable.
{
"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节点-nodeConfig chromeNodeConfig.json
java -jar selenium-server-standalone-3.4.0.jar -role node -nodeConfig chromeNodeConfig.json
除了不同的浏览器名称和端口外,其他节点配置基本相同.
The other node configs are largely the same except for the different browser names and ports.
一旦启动所有节点,控制台将如下所示:
Once all nodes are started, the console looks as follows:
我无法从异常中得到很多.这是我的驱动程序的版本问题吗?我尝试自定义DesiredCapabilities以确保与节点配置中的匹配.所有这些看起来都很好.
I'm not able to get much from the exception. Is it a versioning issue of the drivers I have? I have tried customising my DesiredCapabilities to ensure I'm matching those in the node config. All of that looks fine.
根据要求,我将添加更多有关如何启动浏览器的详细信息.没有一个浏览器可以与RemoteWebDriver一起使用,而可以与本地驱动程序一起使用.显示Chrome的示例-彼此之间唯一的区别在于我要传递给基类构造函数的功能.
As requested I'm adding a bit more detail as to how I'm trying to launch a browser. None of the browsers work with the RemoteWebDriver whereas they do with the local drivers. Showing the Chrome example - only difference between each is regarding the Capabilities that I'm passing in to the base class constructor.
在我的测试课中
[TestClass]
public class PersonTests : PersonTestBase
{
public PersonTests()
: base(DesiredCapabilities.Chrome())
{
}
[TestCategory("Chrome")]
[TestMethod]
public void Chrome_ShouldCreatePlacement()
{
this.ShouldCreatePerson();
}
}
在我的基础课上,我正在做以下事情
In my base class I am doing the following
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(推荐解决方案)
Downgrade to 3.3.0 until this issue gets resolved and a new release of Selenium Standalone Server is available (Recommended solution)
或
- 下载解决方案
- 评论这行
- 构建dotnet语言绑定
- 在根目录中打开命令窗口
- 运行
go //dotnet:release
- 并参考{root}/build/dotnet/dist 中内置的二进制文件
- Download the Solution
- Comment this line
- Build dotnet language bindings
- Open command window in root directory
- Run
go //dotnet:release
- And reference the binaries built in {root}/build/dotnet/dist
注意:此替代方法不能不修复任何问题!它忽略了导致故障的硒网格代码.
Note: This workaround does NOT fix anything! It ignores the piece of selenium grid code that causes failure.
另一个注意事项:请注意,升级到Selenium 3.4可能还需要升级webdrivers.
Another note: Be aware that upgrading to Selenium 3.4 may require upgrading webdrivers as well
这篇关于Selenium RemoteWebDriver C#-System.InvalidOperationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!