json: cannot unmarshal array into Go struct field Caps.capabilities.firstMatch.selenoid:options.enableVNC of type bool
After upgrading from 4.19.0 to 4.20.0 I observe such error: " json: cannot unmarshal array into Go struct field Caps.capabilities.firstMatch.selenoid:options.enableVNC of type bool"
I use selenoid to run the tests written in C#.
it seems related to changing NewtonSoft.Json library to System.Text.Json in Selenium package
settings.json file:
{ "environment": "Local", "browserName": "chrome", "isRemote": true, "remoteConnectionUrl": "http://localhost:4444/wd/hub", "isElementHighlightEnabled": true, "driverSettings": { "chrome": { "capabilities": { "selenoid:options": { "enableVNC": true, "enableVideo": true, "enableLogs": true }, "unhandledPromptBehavior": "ignore" }, "options": { "intl.accept_languages": "en", "safebrowsing.enabled": true, "profile.default_content_settings.popups": 0, "disable-popup-blocking": true, "download.prompt_for_download": false, "download.default_directory": "", "acceptInsecureCerts": true, "download.extensions_to_open": "application/octet-stream" }, "startArguments": [ "window-size=1920,1080", "--no-sandbox", "--disable-infobars", "--disable-notifications", "--disable-popup-blocking", "--disable-gpu", "--ignore-certificate-errors", "--disable-search-engine-choice-screen" ], "pageLoadStrategy": "Normal" } }, "timeouts": { "timeoutImplicit": 0, "timeoutCondition": 30, "timeoutScript": 30, "timeoutPageLoad": 60, "timeoutPollingInterval": 300, "timeoutCommand": 60 }, "retry": { "number": 2, "pollingInterval": 300 }, "logger": { "language": "en", "logPageSource": true }, "elementCache": { "isEnabled": false } }
Hello @Valeriy2013 ! Could you please try if the error is the same when you use pure Selenium e.g. starting a driver when passing ChromeOptions to it directly in your code? If it is a Selenium issue, there is not much we can do about it; I have found something related: https://github.com/SeleniumHQ/selenium/issues/14725 It might be fixed and included into one of the nearest releases. There was an issue with Selenoid config in the past: https://github.com/aerokube/selenoid/issues/554 but it seems to be unrelated to yours. One suggestion: have you tried to pass a single option, e.g. "selenoid:options": { "enableVNC": true} , is the result the same?
Hello!
I'm coming in from the selenium issue that was linked. Sorry, it seems completely unrelated (I'm basically certain it is, but I can't really tell what the bug is here so I can't be definitive).
Hello @mialeska Thank you for your response. I checked with pure selenium and it works. Here is the example I used: `using System; using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Remote;
namespace Tests.Playground { public class SeleniumTests { private IWebDriver driver;
[Test]
public void GoogleSearch()
{
// Navigate to Google
this.driver.Navigate().GoToUrl("https://www.google.com");
// Find the search box using its name attribute
IWebElement searchBox = this.driver.FindElement(By.Name("q"));
// Enter text into the search box
searchBox.SendKeys("Selenium C# example");
// Submit the search form
searchBox.Submit();
// Wait for results
Thread.Sleep(2000); // Use WebDriverWait for better approach
// Verify that the title contains the search term
Assert.That(this.driver.Title.Contains("Selenium C# example", StringComparison.OrdinalIgnoreCase));
}
[SetUp]
public void Setup()
{
// Set capabilities for Selenoid
var options = new ChromeOptions();
options.BrowserVersion = "128.0"; // Ensure it matches your Selenoid config
options.AddAdditionalOption("selenoid:options", new { enableVNC = true, enableVideo = false });
// Initialize Remote WebDriver
this.driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options);
}
[TearDown]
public void Teardown()
{
// Close the browser
this.driver.Quit();
}
}
}`
Also I checked passing the single argument in settings.json file - it didn't help. I tried to debug and see that it throws here:
'((System.Collections.Generic.IDictionary<string, Newtonsoft.Json.Linq.JToken>)(new System.Collections.Generic.IDictionaryDebugView<string, object>(((OpenQA.Selenium.Remote.ReadOnlyDesiredCapabilities)capabilities).CapabilitiesDictionary).Items[2]).Value).Values' threw an exception of type 'System.NotImplementedException'
error CS1503: Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string, T>' to 'System.Collections.Generic.IDictionary<string, object>'
I can reproduce the issue with raw selenium:
var options = new ChromeOptions();
options.AddAdditionalOption("selenoid:options", new { enableVNC = true, enableVideo = false });
var driver = new ChromeDriver(options);
I will log a bug on the Selenium repo.
The fix on the Selenium side has been merged and will be part of the next release.
I'm not familiar with this project, like I said I came in here when my issue was linked. As such, I don't know if the Selenium bug fix addresses this issue. If you're particularly adventurous, the fix is in Selenium's nightly release (instructions in the repo) and you can try it out using that .dll. Otherwise, we'll wait for the next release to see if this bug is truly fixed.
@Valeriy2013 I've updated Aquality.Selenium with the latest selenium version (4.27.0) which should include the fix mentioned by Michael above. Please check if it is working for you now. If not, it will need to wait until we implement https://github.com/aquality-automation/aquality-selenium-core-dotnet/issues/122
@Valeriy2013 I've updated Aquality.Selenium with the latest selenium version (4.27.0) which should include the fix mentioned by Michael above. Please check if it is working for you now. If not, it will need to wait until we implement aquality-automation/aquality-selenium-core-dotnet#122
Hi @mialeska. In version 4.22.1 still see the issue: 2024/11/29 18:56:42 [7] [BAD_JSON_FORMAT] [json: cannot unmarshal array into Go struct field Caps.capabilities.firstMatch.selenoid:options of type session.Caps]
2024-11-29 18:56:41 INFO - Setting WebDriver from selenium grid hub 2024-11-29 18:56:41 DEBUG - Got browser profile options from settings file: intl.accept_languages: en, safebrowsing.enabled: true, profile.default_content_settings.popups: 0, disable-popup-blocking: true, download.prompt_for_download: false, download.default_directory: , acceptInsecureCerts: true, download.extensions_to_open: application/octet-stream 2024-11-29 18:56:41 DEBUG - Got browser capabilities from settings file: selenoid:options: { "enableVNC": true, "enableVideo": false, "enableLogs": false } 2024-11-29 18:56:41 DEBUG - Got browser start arguments from settings file: window-size=1920,1080 --no-sandbox --disable-popup-blocking --disable-gpu --ignore-certificate-errors **2024-11-29 18:56:41 FATAL - Driver setting from Selenium Grid hub was failed**
Will wait for migration to System.Text.Json
Thanks
Hi @mialeska. This one was fixed and can be closed. Switch to System.Text.Json in latest version resolved the problem. Thanks
fixed in #275