问题
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}
I have chromedriver.exe
in the following directory:
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;
}
}
The method 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;
}
}
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
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?
回答1:
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
...implies that the ChromeDriver was unable to initiate/spawn a new WebClient i.e. Chrome Browser session.
Your main issue is the presence of undefined capability for ChromeDriver as follows :
- 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
回答2:
Try this. Specify the location of driver while starting your node.
java -Dwebdriver.chrome.driver=D:/nchaurasia/Automation-Architect/connect2tech.in-SeleniumWebDriver3.x_2/driver/chromedriver.exe -jar selenium-server-standalone-3.9.1.jar -role node -hub http://192.168.137.1:4444/grid/register/
来源:https://stackoverflow.com/questions/50108337/system-invalidoperationexception-error-forwarding-the-new-session-cannot-find