System.InvalidOperationException:无法找到转发新会话的错误:Capabilities {browserName: chrome, marionette: false} [英] System.InvalidOperationException : Error forwarding the new session cannot find : Capabilities {browserName: chrome, marionette: false}
问题描述
我正在尝试使用 Grid
运行我的 Selenium
C# 自动化测试.
当我运行测试时出现错误:
I am trying to run my Selenium
C# automated test using Grid
.
When i run the test I get the error:
Message: System.InvalidOperationException : Error forwarding the new session cannot find : Capabilities {browserName: chrome, marionette: false, platform: WINDOWS}
我在以下目录中有 chromedriver.exe
:
F:\Selenium Projects\C#\Grid practice\automation\
我已将环境变量的路径从系统、控制面板设置为路径:
I have set the path for Environment Variables from System, Control Panel to the path:
F:\Selenium Projects\C#\Grid practice\automation\
我的代码片段是:
My code snippet is:
public class Browsers : DriverClass
{
public IWebDriver LaunchBrowser(string browser)
{
switch (browser)
{
case "chrome":
GoToChromeBrowser("chrome");
break;
case "firefox":
GoToFirefoxBrowser();
break;
case "ie":
GoToIeBrowser();
break;
case "edge":
GoToEdgeBrowser();
break;
case "remote":
GoToRemoteBrowser();
break;
default:
throw new Exception("did not find browser type selected");
}
return Driver;
}
}
方法GoToChromeBrowser()
:
public void GoToChromeBrowser(string BrowserType)
{
switch (BrowserType)
{
case "firefox":
Driver = new FirefoxDriver();
break;
case "chrome":
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability(CapabilityType.BrowserName, "chrome");
cap.SetCapability("marionette", false);
cap.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
Driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), cap);
break;
}
}
要启动集线器,我使用 CMD 中的命令:
To start the Hub I use the command in CMD:
java -jar F:\Selenium\Server\selenium-server-standalone-3.11.0.jar -role hub
要注册节点,我使用以下命令:
To register the node I use the command:
java -jar selenium-server-standalone-3.11.0.jar -role node -hub http://localhost:4444/grid/register -browser "browserName=chrome version=ANY, maxInstances=5, platform=WINDOWS" -port 5566
集线器已正常启动并且节点已注册.没有错误.
为什么我在 Visual Studio 中运行测试时会收到错误消息?
我错过了什么或做错了什么?
The hub has started fine and the node is registered. No errors there.
Why am I getting the error when I run my test in Visual Studio?
What am i missing or doing wrong?
推荐答案
此错误信息...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
...表示 ChromeDriver 无法启动/生成新的 WebClient,即 Chrome 浏览器 会话.
...implies that the ChromeDriver was unable to initiate/spawn a new WebClient i.e. Chrome Browser session.
您的主要问题是 ChromeDriver 存在未定义的功能,如下所示:
Your main issue is the presence of undefined capability for ChromeDriver as follows :
- 您已使用 "marionette", false 调用了
SetCapability()
,但 ChromeDriver 不支持任何此类功能,例如 牵线木偶. - marionette 功能由 GeckoDriver 使用,当您使用 selenium-server-standalone-3.11.0.jar 时,您必须强制使用 GeckoDriver,默认情况下将
marionette
设置为 true.如果您将marionette
强行设置为false,GeckoDriver 将抛出一个异常. 正如@NareshChaurasia 指出的,当您启动 Selenium Hub 节点 时,您必须按如下方式传递 ChromeDriver 的绝对路径:
- You have invoked
SetCapability()
with "marionette", false, but ChromeDriver doesn't supports any such capability as marionette. - The capability marionette is used by GeckoDriver and as you are using selenium-server-standalone-3.11.0.jar you have to mandatorily use GeckoDriver which by default sets
marionette
as true. If you forcefully setmarionette
as false, GeckoDriver will throw an exception. As @NareshChaurasia pointed out while you initiate the Selenium Hub Node you have to pass the absolute path of the ChromeDriver as follows :
java -Dwebdriver.chrome.driver=F:/Selenium Projects/C#/Grid practice/automation/chromedriver.exe -jar selenium-server-standalone-3.11.0.jar -role node -hub http://192.168.0.100:4444/grid/register
这篇关于System.InvalidOperationException:无法找到转发新会话的错误:Capabilities {browserName: chrome, marionette: false}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!