-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Description
Description
After updating Selenium.WebDriver from 4.38.0 to 4.39.0 in my .NET 8 ASP.NET Core web app's UI tests, I experience JSON parsing, with Sytem.Text.Json, starting to fail both in my app in various places (independent of Selenium), and in Selenium itself (when taking screenshots). The errors hint on the JSON files being corrupted, or that the app is not reading the JSON files it should (and could read without issues with 4.38.0). E.g.
OrchardCore.Setup.Services.SetupService: Unable to import a recipe during setup.System.Text.Json.JsonReaderException: '0x00' is an invalid start of a property name. Expected a '"'. LineNumber: 0 | BytePositionInLine: 1.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedArrayPoolBytes, PooledByteBufferWriter extraPooledByteBufferWriter)
at System.Text.Json.JsonDocument.ParseAsyncCore(Stream utf8Json, JsonDocumentOptions options, CancellationToken cancellationToken)
at OrchardCore.Recipes.Services.RecipeExecutor.ExecuteAsync(String executionId, RecipeDescriptor recipeDescriptor, IDictionary`2 environment, CancellationToken cancellationToken)
This isn't Selenium code, so I have no idea why it's affected (it does run in the same process, though, so things like static member values are shared).
But I also sometimes get JSON exceptions from Selenium itself:
System.Text.Json.JsonReaderException: 'm' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: 0 | BytePositionInLine: 147346.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
at System.Text.Json.JsonDocument.ParseUnrented(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, JsonTokenType tokenType)
at System.Text.Json.JsonDocument.ParseValue(ReadOnlyMemory`1 json, JsonDocumentOptions options)
at OpenQA.Selenium.Response.FromJson(String value)
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(HttpResponseInfo responseInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.ExecuteAsync(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.ExecuteAsync(Command commandToExecute)
at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.WebDriver.GetScreenshot()
at Lombiq.Tests.UI.Extensions.ScreenshotUITestContextExtensions.TakeScreenshot(UITestContext context) in
Note that this doesn't seem to happen on my Windows 11 desktop, but does when the UI tests are executed from GitHub Actions, both under Ubuntu 24.04 and Windows Server 2025. Also note that this is "random": while it does reliably fail all my CI test runs, it doesn't always happen at the same place (though that might be an artifact of different runs completing tests in slightly different order due to some jitter in speed).
Some other user on Slack has a screenshot image loading issue, what I think is actually the same problem, just manifesting at a later stage.
I first brought this up on Slack but was told to come here.
Reproducible Code
// I don't have a proper one. The below code does NOT produce the error on my Windows 11 desktop
// (what doesn't exhibit it anyway, see above). I'm still trying to figure out how to reduce the massive
// framework, that uses frameworks behind the scenes, to a relevant code snippet.
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
var chromeOptions = new ChromeOptions();
chromeOptions.BrowserVersion = "143.0.7499.169";
chromeOptions.AddArgument("--headless");
using var driver = new ChromeDriver(chromeOptions);
try
{
driver.Navigate().GoToUrl("https://example.com");
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
var screenshotPath = Path.Combine(Directory.GetCurrentDirectory(), "screenshot.png");
screenshot.SaveAsFile(screenshotPath);
Console.WriteLine($"Screenshot saved to: {screenshotPath}");
}
finally
{
driver.Quit();
}
Console.WriteLine("Done!");ℹ️ Last known working version: 4.38.0