Chrome DesiredCapabilities C#
Meta -
OS:
Development : Windows 10
OS Browser : Not relevant (same issue with Win10, Ubuntu 17.04)
Selenium Version:
Selenium 3.6.0, C#
Browser:
Chrome
Browser Version:
Not relevant (tried with Chrome 48, Chrome 62)
Expected Behavior -
I'm using Selenium Grid to pick a browser with C#. I have an issue when i try this code :
var options = new ChromeOptions();
options.AddArgument("headless");
options.AddArgument("disable-gpu");
options.AddAdditionalCapability(CapabilityType.Platform, "LINUX");
options.AddAdditionalCapability(CapabilityType.Version, "62.0.3202.62");
var blabla = new RemoteWebDriver(new Uri(new Uri(Environment.GetEnvironmentVariable("SeleniumHubUrl") ?? "http://seleniux:4444"), "wd/hub"), options);
The structure of my options object seems to be correctly constructed.
The error I get is :
System.InvalidOperationException : unknown error: cannot parse capability: goog:chromeOptions from unknown error: unrecognized chrome option: platform (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
To have a good behaviour, I must write some ugly code :
var options = new ChromeOptions();
options.AddArgument("headless");
options.AddArgument("disable-gpu");
DesiredCapabilities cap = new DesiredCapabilities();
cap = options.ToCapabilities() as DesiredCapabilities;
cap.SetCapability(CapabilityType.Platform, PlatformType.Linux.ToString().ToUpper());
cap.SetCapability(CapabilityType.Version, "62.0.3202.62");
var blabla = new RemoteWebDriver(new Uri(new Uri(Environment.GetEnvironmentVariable("SeleniumHubUrl") ?? "http://seleniux:4444"), "wd/hub"), cap);
Here, the structure of the cap variable look like the structure of the previous but the part goog:chromeOptions is really odd... But this version works...
Am I missing something with the first code I tried to write ?
Actual Behavior -
Clean code doesn't work, but ugly yes
Steps to reproduce -
I also tried this version but doesn't work either :
var options = new ChromeOptions();
options.AddArgument("headless");
options.AddArgument("disable-gpu");
var cap = new DesiredCapabilities("chrome", "62.0.3202.62", new Platform(PlatformType.Linux));
cap.SetCapability(ChromeOptions.Capability, options);
var blabla = new RemoteWebDriver(new Uri(new Uri(Environment.GetEnvironmentVariable("SeleniumHubUrl") ?? "http://seleniux:4444"), "wd/hub"), cap);
What happens if you use the following code (note the additional argument on AddAdditionaCapability):
var options = new ChromeOptions();
options.AddArgument("headless");
options.AddArgument("disable-gpu");
options.AddAdditionalCapability(CapabilityType.Platform, "LINUX", true);
options.AddAdditionalCapability(CapabilityType.Version, "62.0.3202.62", true);
var blabla = new RemoteWebDriver(new Uri(new Uri(Environment.GetEnvironmentVariable("SeleniumHubUrl") ?? "http://seleniux:4444"), "wd/hub"), options);
It's a kind of magic !!!
Problem solved, I will look at the object generated to see what's the real difference.
Thanks a lot @jimevans !
That’s working as designed then.