I'm working with Selenium (4.0-rc1) in C# and want to use SauceLabs, to use this service I need to pass a custom capability.
In the examples, it shows adding a capability ("string","string") to the collection and it would appear that in the Java code this is the correct way but in the C# Selenium implementation this interface ICapabilities is read-only.
The Interface ICapabilities would seem to be the right way with DriverOptions.ToCapabilities() and I have implemented a custom ICapabilities, but this generates a null reference. Looking within the remote driver the code seems to immediately cast ICapabilities to an internal interface IHasCapabilitiesDictionary[1] which I can not implement which I assume is causing my custom ICapabilities to throw the null reference.
I must have missed something simple here as it seems such a common requirement - how do I add custom capabilities to the ICapabilities collection.
Edit
One other note I have tried the deprecated DriverOptions.AddAdditionaCapability(name,value) even though it is obsolete just to see if it worked but it throws an error Cannot Parse Capability, as it does not recognise the custom Capability as one which the MSEdge Options class recognises.
Thanks in advance.
Here's a working W3C test on Sauce
[TestMethod]
public void EdgeW3C()
{
//TODO please set your Sauce Labs username/access key in an environment variable
_sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME");
// Do NOT use EnvironmentVariableTarget as it won't work in CI
_sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY");
_sauceOptions = new Dictionary<string, object>
{
["username"] = _sauceUserName,
["accessKey"] = _sauceAccessKey,
["name"] = TestContext.TestName
};
var browserOptions = new EdgeOptions
{
BrowserVersion = "latest",
PlatformName = "Windows 10"
//AcceptInsecureCertificates = true //Insecure Certs are Not supported by Edge
};
browserOptions.AddAdditionalOption("sauce:options", _sauceOptions);
_driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"), browserOptions.ToCapabilities(),
TimeSpan.FromSeconds(30));
_driver.Navigate().GoToUrl("https://www.saucedemo.com");
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(6));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("#user-name")));
}
You can pull down this repo and give it a try