From 27cdb890b5cf533df62d6e104549f4a844b477de Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 8 Mar 2025 00:30:07 -0500 Subject: [PATCH 01/11] [dotnet] Address AOT warnings in BiDi --- dotnet/src/webdriver/BiDi/Communication/Broker.cs | 1 - .../Converters/Enumerable/GetClientWindowsResultConverter.cs | 3 +++ .../Json/Converters/Enumerable/GetCookiesResultConverter.cs | 3 +++ .../Json/Converters/Enumerable/GetRealmsResultConverter.cs | 3 +++ .../Converters/Enumerable/GetUserContextsResultConverter.cs | 3 +++ .../Json/Converters/Enumerable/InputSourceActionsConverter.cs | 3 +++ .../Json/Converters/Enumerable/LocateNodesResultConverter.cs | 3 +++ .../Communication/Json/Converters/InputOriginConverter.cs | 3 +++ .../Json/Converters/Polymorphic/EvaluateResultConverter.cs | 3 +++ .../Json/Converters/Polymorphic/LogEntryConverter.cs | 3 +++ .../Json/Converters/Polymorphic/MessageConverter.cs | 3 +++ .../Json/Converters/Polymorphic/RealmInfoConverter.cs | 3 +++ .../Json/Converters/Polymorphic/RemoteValueConverter.cs | 3 +++ dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs | 1 + .../BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs | 1 + .../webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs | 1 + .../webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs | 2 ++ .../webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs | 2 ++ .../BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs | 1 + dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs | 1 + dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs | 2 ++ .../src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs | 4 +++- dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs | 1 + dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs | 3 +++ .../webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs | 4 +++- dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs | 3 +++ dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs | 1 + dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs | 3 +++ .../src/webdriver/BiDi/Modules/Script/SerializationOptions.cs | 3 +++ dotnet/src/webdriver/Chromium/ChromiumDriver.cs | 2 ++ dotnet/src/webdriver/Command.cs | 3 ++- 32 files changed, 73 insertions(+), 4 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index de7fd33a35180..7d3bf7e9424cd 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -82,7 +82,6 @@ internal Broker(BiDi bidi, ITransport transport) new PrintPageRangeConverter(), new InputOriginConverter(), new SubscriptionConverter(), - new JsonStringEnumConverter(JsonNamingPolicy.CamelCase), // https://github.com/dotnet/runtime/issues/72604 new Json.Converters.Polymorphic.MessageConverter(), diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs index e3bee0238a8e1..7d7934d7c6672 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs @@ -20,11 +20,14 @@ using OpenQA.Selenium.BiDi.Modules.Browser; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetClientWindowsResultConverter : JsonConverter { public override GetClientWindowsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs index 48c4fcd83f75d..0a8dc399aa12c 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs @@ -20,11 +20,14 @@ using OpenQA.Selenium.BiDi.Modules.Storage; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetCookiesResultConverter : JsonConverter { public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs index 069628d4f0776..efa03daabc144 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs @@ -20,11 +20,14 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetRealmsResultConverter : JsonConverter { public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs index 02b22c2e82a02..dc6f4683018e6 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs @@ -20,11 +20,14 @@ using OpenQA.Selenium.BiDi.Modules.Browser; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetUserContextsResultConverter : JsonConverter { public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs index f66ff5e9c6ed9..559a3a874c83f 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -19,12 +19,15 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class InputSourceActionsConverter : JsonConverter { public override SourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs index 027575d31acf1..48815dd268b6f 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs @@ -21,11 +21,14 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class LocateNodesResultConverter : JsonConverter { public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs index 997fc7b5a6d43..3089fc231d6d2 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs @@ -19,11 +19,14 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class InputOriginConverter : JsonConverter { public override Origin Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs index 0aa560798cf87..2f6e33ff0a3cf 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs @@ -19,11 +19,14 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] // https://github.com/dotnet/runtime/issues/72604 internal class EvaluateResultConverter : JsonConverter { diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs index e573ea57df0fe..6ff059d004650 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs @@ -19,12 +19,15 @@ using OpenQA.Selenium.BiDi.Modules.Log; using System; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class LogEntryConverter : JsonConverter { public override Modules.Log.Entry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/MessageConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/MessageConverter.cs index 8e10f9b0565d9..63d514b8d4909 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/MessageConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/MessageConverter.cs @@ -18,12 +18,15 @@ // using System; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class MessageConverter : JsonConverter { public override Message? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs index a916fd3734d5a..740cf9c215a7e 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs @@ -19,12 +19,15 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class RealmInfoConverter : JsonConverter { public override RealmInfo? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs index 88539ce7b55fd..6ae304506e2c7 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs @@ -19,12 +19,15 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 +[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] +[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class RemoteValueConverter : JsonConverter { public override RemoteValue? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs index c5f123048e983..bce50a6fd9edf 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs @@ -23,6 +23,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Browser; public record ClientWindowInfo([property: JsonPropertyName("active")] bool IsActive, ClientWindow ClientWindow, ClientWindowState State, int Height, int Width, int X, int Y); +[JsonConverter(typeof(JsonStringEnumConverter))] public enum ClientWindowState { Fullscreen, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 328644b8ed82b..9fc270293b0b1 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -36,6 +36,7 @@ public record CaptureScreenshotOptions : CommandOptions public ClipRectangle? Clip { get; set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum Origin { Viewport, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs index ade319e27390c..892ba4d01fc05 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -35,6 +36,7 @@ public record CreateOptions : CommandOptions public Browser.UserContext? UserContext { get; set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum ContextType { Tab, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index d026bc9933034..77a5b91a25169 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -51,6 +51,7 @@ public record InnerText(string Value) : Locator public record XPath(string Value) : Locator; } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum MatchType { Full, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs index 87a2e295c8c8c..7400d653df6a4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -31,6 +32,7 @@ public record NavigateOptions : CommandOptions public ReadinessState? Wait { get; set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum ReadinessState { None, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs index b3362f59fa139..6cf9efad08e67 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs @@ -20,6 +20,7 @@ using OpenQA.Selenium.BiDi.Communication; using System; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -56,6 +57,7 @@ public struct PrintMargin public double? Top { get; set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum PrintOrientation { Portrait, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs index e6b8a1541c0c6..43f1e1d880bda 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs @@ -28,6 +28,7 @@ public record UserPromptOpenedEventArgs(BiDi BiDi, BrowsingContext Context, User public string? DefaultValue { get; internal set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum UserPromptType { Alert, diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index a078c80fbf3fd..8491fae594ee9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -147,6 +147,7 @@ public record PointerParameters public PointerType? PointerType { get; set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum PointerType { Mouse, diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs index 52b57a4db11fd..316954c86100b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Log; @@ -38,6 +39,7 @@ public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Te : Entry(BiDi, Level, Source, Text, Timestamp); } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum Level { Debug, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs index 67490235f9651..4728f22f5cfb1 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs @@ -17,8 +17,9 @@ // under the License. // -using System.Collections.Generic; using OpenQA.Selenium.BiDi.Communication; +using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Network; @@ -48,6 +49,7 @@ public record BrowsingContextAddInterceptOptions public record AddInterceptResult(Intercept Intercept); +[JsonConverter(typeof(JsonStringEnumConverter))] public enum InterceptPhase { BeforeRequestSent, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs index 98754195731f2..40a2fa8727bed 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs @@ -28,6 +28,7 @@ public record Cookie(string Name, BytesValue Value, string Domain, string Path, public DateTimeOffset? Expiry { get; internal set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum SameSite { Strict, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs index c9cc0bf5f0f91..1a4b55c980bcb 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs @@ -17,6 +17,8 @@ // under the License. // +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Modules.Network; public record Initiator(InitiatorType Type) @@ -30,6 +32,7 @@ public record Initiator(InitiatorType Type) public Request? Request { get; set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum InitiatorType { Parser, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs index 11a372901c22a..edf4bf3f79d13 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs @@ -17,8 +17,9 @@ // under the License. // -using System.Collections.Generic; using OpenQA.Selenium.BiDi.Communication; +using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Network; @@ -47,6 +48,7 @@ public record BrowsingContextSetCacheBehaviorOptions } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum CacheBehavior { Default, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs index 0958b42929edf..925ba5030f43d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs @@ -17,8 +17,11 @@ // under the License. // +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Modules.Script; +[JsonConverter(typeof(JsonStringEnumConverter))] public enum RealmType { Window, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index 8ff737adf44cf..33ebd76746271 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -269,6 +269,7 @@ public record Properties(BrowsingContext.BrowsingContext Context); public abstract record PrimitiveProtocolRemoteValue : RemoteValue; +[JsonConverter(typeof(JsonStringEnumConverter))] public enum Mode { Open, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs index f72d799c061a2..0399753c99c03 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs @@ -17,8 +17,11 @@ // under the License. // +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Modules.Script; +[JsonConverter(typeof(JsonStringEnumConverter))] public enum ResultOwnership { Root, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs index ea4dc82c6da9c..18070105ec489 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs @@ -17,6 +17,8 @@ // under the License. // +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Modules.Script; public class SerializationOptions @@ -28,6 +30,7 @@ public class SerializationOptions public ShadowTree? IncludeShadowTree { get; set; } } +[JsonConverter(typeof(JsonStringEnumConverter))] public enum ShadowTree { None, diff --git a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs index f577c7439a940..afe3d1b551fc3 100644 --- a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs +++ b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs @@ -361,6 +361,8 @@ public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion) /// /// Closes a DevTools session. /// + [RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)] + [RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)] public void CloseDevToolsSession() { if (this.devToolsSession != null) diff --git a/dotnet/src/webdriver/Command.cs b/dotnet/src/webdriver/Command.cs index b3bce18434aa2..43ec4839dbbc3 100644 --- a/dotnet/src/webdriver/Command.cs +++ b/dotnet/src/webdriver/Command.cs @@ -118,7 +118,7 @@ public override string ToString() /// If is . private static Dictionary? ConvertParametersFromJson(string value) { - Dictionary? parameters = JsonSerializer.Deserialize>(value, s_jsonSerializerOptions); + Dictionary? parameters = JsonSerializer.Deserialize>(value, CommandJsonSerializerContext.Default.DictionaryStringObject!); return parameters; } } @@ -167,5 +167,6 @@ public override string ToString() [JsonSerializable(typeof(Dictionary))] [JsonSerializable(typeof(Dictionary))] [JsonSerializable(typeof(Dictionary))] + [JsonSourceGenerationOptions(Converters = [typeof(ResponseValueJsonConverter)])] internal partial class CommandJsonSerializerContext : JsonSerializerContext; } From b4f7fd53081c1c5b84e32403fd5b6720834e1da0 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 8 Mar 2025 00:39:58 -0500 Subject: [PATCH 02/11] Invert in in `Command.ParametersAsJsonString` for future ease of error handling --- dotnet/src/webdriver/Command.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/dotnet/src/webdriver/Command.cs b/dotnet/src/webdriver/Command.cs index 43ec4839dbbc3..5b004b0caafd2 100644 --- a/dotnet/src/webdriver/Command.cs +++ b/dotnet/src/webdriver/Command.cs @@ -86,17 +86,12 @@ public string ParametersAsJsonString { get { - string parametersString; - if (this.Parameters != null && this.Parameters.Count > 0) + if (this.Parameters == null || this.Parameters.Count <= 0) { - parametersString = JsonSerializer.Serialize(this.Parameters, s_jsonSerializerOptions); - } - else - { - parametersString = "{}"; + return "{}"; } - return parametersString; + return JsonSerializer.Serialize(this.Parameters, s_jsonSerializerOptions); } } From ac867a6a74cb13d75cff30796232d3c2a3046fcc Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 8 Mar 2025 00:50:49 -0500 Subject: [PATCH 03/11] Minimise warnings from one place to two --- dotnet/src/webdriver/Internal/FileUtilities.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/Internal/FileUtilities.cs b/dotnet/src/webdriver/Internal/FileUtilities.cs index b3bff70bd1b76..5d0aeadd6ed37 100644 --- a/dotnet/src/webdriver/Internal/FileUtilities.cs +++ b/dotnet/src/webdriver/Internal/FileUtilities.cs @@ -168,9 +168,10 @@ public static string GetCurrentDirectory() string? location = null; // Make sure not to call Path.GetDirectoryName if assembly location is null or empty - if (!string.IsNullOrEmpty(executingAssembly.Location)) + string assemblyLocation = executingAssembly.Location; + if (!string.IsNullOrEmpty(assemblyLocation)) { - location = Path.GetDirectoryName(executingAssembly.Location); + location = Path.GetDirectoryName(assemblyLocation); } if (string.IsNullOrEmpty(location)) From e95a4fddf6504a572c8e54bcc28622973184eb81 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 8 Mar 2025 14:04:38 -0500 Subject: [PATCH 04/11] Retain camel-casing of BiDi enums --- .../CamelCaseJsonEnumStringConverter.cs | 29 +++++++++++++++++++ .../BiDi/Modules/Browser/ClientWindowInfo.cs | 3 +- .../CaptureScreenshotCommand.cs | 3 +- .../Modules/BrowsingContext/CreateCommand.cs | 3 +- .../BiDi/Modules/BrowsingContext/Locator.cs | 3 +- .../BrowsingContext/NavigateCommand.cs | 3 +- .../Modules/BrowsingContext/PrintCommand.cs | 3 +- .../UserPromptOpenedEventArgs.cs | 3 +- .../BiDi/Modules/Input/SourceActions.cs | 3 +- .../src/webdriver/BiDi/Modules/Log/Entry.cs | 3 +- .../Modules/Network/AddInterceptCommand.cs | 3 +- .../webdriver/BiDi/Modules/Network/Cookie.cs | 3 +- .../BiDi/Modules/Network/Initiator.cs | 3 +- .../Network/SetCacheBehaviorCommand.cs | 3 +- .../BiDi/Modules/Script/RealmType.cs | 3 +- .../BiDi/Modules/Script/RemoteValue.cs | 3 +- .../BiDi/Modules/Script/ResultOwnership.cs | 3 +- .../Modules/Script/SerializationOptions.cs | 3 +- 18 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs new file mode 100644 index 0000000000000..db97b6bbf9651 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs @@ -0,0 +1,29 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters +{ + internal sealed class CamelCaseJsonEnumStringConverter() + : JsonStringEnumConverter(JsonNamingPolicy.CamelCase) + where TEnum : struct, Enum; +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs index bce50a6fd9edf..1d765c30f4f17 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs @@ -17,13 +17,14 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Browser; public record ClientWindowInfo([property: JsonPropertyName("active")] bool IsActive, ClientWindow ClientWindow, ClientWindowState State, int Height, int Width, int X, int Y); -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ClientWindowState { Fullscreen, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 9fc270293b0b1..df24f764c49ef 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -36,7 +37,7 @@ public record CaptureScreenshotOptions : CommandOptions public ClipRectangle? Clip { get; set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum Origin { Viewport, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs index 892ba4d01fc05..07ee3a0954ea8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -36,7 +37,7 @@ public record CreateOptions : CommandOptions public Browser.UserContext? UserContext { get; set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ContextType { Tab, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index 77a5b91a25169..5159b18caa0be 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -51,7 +52,7 @@ public record InnerText(string Value) : Locator public record XPath(string Value) : Locator; } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum MatchType { Full, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs index 7400d653df6a4..1f856af89d762 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -32,7 +33,7 @@ public record NavigateOptions : CommandOptions public ReadinessState? Wait { get; set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ReadinessState { None, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs index 6cf9efad08e67..06bf549110d9a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -57,7 +58,7 @@ public struct PrintMargin public double? Top { get; set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum PrintOrientation { Portrait, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs index 43f1e1d880bda..128c70dddaeeb 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -28,7 +29,7 @@ public record UserPromptOpenedEventArgs(BiDi BiDi, BrowsingContext Context, User public string? DefaultValue { get; internal set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum UserPromptType { Alert, diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 8491fae594ee9..ecaca4c4f121d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections; using System.Collections.Generic; @@ -147,7 +148,7 @@ public record PointerParameters public PointerType? PointerType { get; set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum PointerType { Mouse, diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs index 316954c86100b..3a5d35366b2a3 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -39,7 +40,7 @@ public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Te : Entry(BiDi, Level, Source, Text, Timestamp); } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum Level { Debug, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs index 4728f22f5cfb1..6ba3dc63b1361 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -49,7 +50,7 @@ public record BrowsingContextAddInterceptOptions public record AddInterceptResult(Intercept Intercept); -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum InterceptPhase { BeforeRequestSent, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs index 40a2fa8727bed..c347625c96091 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Text.Json.Serialization; @@ -28,7 +29,7 @@ public record Cookie(string Name, BytesValue Value, string Domain, string Path, public DateTimeOffset? Expiry { get; internal set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum SameSite { Strict, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs index 1a4b55c980bcb..9106002acf2ac 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Network; @@ -32,7 +33,7 @@ public record Initiator(InitiatorType Type) public Request? Request { get; set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum InitiatorType { Parser, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs index edf4bf3f79d13..8708b3ff47544 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -48,7 +49,7 @@ public record BrowsingContextSetCacheBehaviorOptions } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum CacheBehavior { Default, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs index 925ba5030f43d..79f53626ab9a4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs @@ -17,11 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Script; -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum RealmType { Window, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index 33ebd76746271..5f8c43c5a7755 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections.Generic; using System.Text.Json; @@ -269,7 +270,7 @@ public record Properties(BrowsingContext.BrowsingContext Context); public abstract record PrimitiveProtocolRemoteValue : RemoteValue; -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum Mode { Open, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs index 0399753c99c03..a490bd4ae7452 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs @@ -17,11 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Script; -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ResultOwnership { Root, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs index 18070105ec489..d81d4d4ae768c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Script; @@ -30,7 +31,7 @@ public class SerializationOptions public ShadowTree? IncludeShadowTree { get; set; } } -[JsonConverter(typeof(JsonStringEnumConverter))] +[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ShadowTree { None, From b13ae71403c33b4b1d498f51cd0368a9f7f7c1d6 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 8 Mar 2025 14:36:48 -0500 Subject: [PATCH 05/11] Remove JSON enum string changes --- .../webdriver/BiDi/Communication/Broker.cs | 1 + .../CamelCaseJsonEnumStringConverter.cs | 29 ------------------- .../BiDi/Modules/Browser/BrowserModule.cs | 1 - .../BiDi/Modules/Browser/ClientWindowInfo.cs | 2 -- .../CaptureScreenshotCommand.cs | 2 -- .../Modules/BrowsingContext/CreateCommand.cs | 3 -- .../BiDi/Modules/BrowsingContext/Locator.cs | 2 -- .../BrowsingContext/NavigateCommand.cs | 3 -- .../Modules/BrowsingContext/PrintCommand.cs | 3 -- .../UserPromptOpenedEventArgs.cs | 2 -- .../BiDi/Modules/Input/SourceActions.cs | 2 -- .../src/webdriver/BiDi/Modules/Log/Entry.cs | 3 -- .../Modules/Network/AddInterceptCommand.cs | 3 -- .../webdriver/BiDi/Modules/Network/Cookie.cs | 2 -- .../BiDi/Modules/Network/Initiator.cs | 4 --- .../Network/SetCacheBehaviorCommand.cs | 3 -- .../BiDi/Modules/Script/RealmType.cs | 4 --- .../BiDi/Modules/Script/RemoteValue.cs | 3 -- .../BiDi/Modules/Script/ResultOwnership.cs | 4 --- .../Modules/Script/SerializationOptions.cs | 4 --- 20 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 7d3bf7e9424cd..de7fd33a35180 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -82,6 +82,7 @@ internal Broker(BiDi bidi, ITransport transport) new PrintPageRangeConverter(), new InputOriginConverter(), new SubscriptionConverter(), + new JsonStringEnumConverter(JsonNamingPolicy.CamelCase), // https://github.com/dotnet/runtime/issues/72604 new Json.Converters.Polymorphic.MessageConverter(), diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs deleted file mode 100644 index db97b6bbf9651..0000000000000 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/CamelCaseJsonEnumStringConverter.cs +++ /dev/null @@ -1,29 +0,0 @@ -// -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -using System; -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace OpenQA.Selenium.BiDi.Communication.Json.Converters -{ - internal sealed class CamelCaseJsonEnumStringConverter() - : JsonStringEnumConverter(JsonNamingPolicy.CamelCase) - where TEnum : struct, Enum; -} diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs index 822fbe26ae33d..456cec5f9acad 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs @@ -17,7 +17,6 @@ // under the License. // -using System.Collections.Generic; using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Communication; diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs index 1d765c30f4f17..c5f123048e983 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/ClientWindowInfo.cs @@ -17,14 +17,12 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Browser; public record ClientWindowInfo([property: JsonPropertyName("active")] bool IsActive, ClientWindow ClientWindow, ClientWindowState State, int Height, int Width, int X, int Y); -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ClientWindowState { Fullscreen, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index df24f764c49ef..328644b8ed82b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -18,7 +18,6 @@ // using OpenQA.Selenium.BiDi.Communication; -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -37,7 +36,6 @@ public record CaptureScreenshotOptions : CommandOptions public ClipRectangle? Clip { get; set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum Origin { Viewport, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs index 07ee3a0954ea8..ade319e27390c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs @@ -18,8 +18,6 @@ // using OpenQA.Selenium.BiDi.Communication; -using OpenQA.Selenium.BiDi.Communication.Json.Converters; -using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -37,7 +35,6 @@ public record CreateOptions : CommandOptions public Browser.UserContext? UserContext { get; set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ContextType { Tab, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index 5159b18caa0be..d026bc9933034 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -17,7 +17,6 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -52,7 +51,6 @@ public record InnerText(string Value) : Locator public record XPath(string Value) : Locator; } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum MatchType { Full, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs index 1f856af89d762..87a2e295c8c8c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs @@ -18,8 +18,6 @@ // using OpenQA.Selenium.BiDi.Communication; -using OpenQA.Selenium.BiDi.Communication.Json.Converters; -using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -33,7 +31,6 @@ public record NavigateOptions : CommandOptions public ReadinessState? Wait { get; set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ReadinessState { None, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs index 06bf549110d9a..b3362f59fa139 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs @@ -18,10 +18,8 @@ // using OpenQA.Selenium.BiDi.Communication; -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections.Generic; -using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -58,7 +56,6 @@ public struct PrintMargin public double? Top { get; set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum PrintOrientation { Portrait, diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs index 128c70dddaeeb..e6b8a1541c0c6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs @@ -17,7 +17,6 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -29,7 +28,6 @@ public record UserPromptOpenedEventArgs(BiDi BiDi, BrowsingContext Context, User public string? DefaultValue { get; internal set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum UserPromptType { Alert, diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index ecaca4c4f121d..a078c80fbf3fd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -17,7 +17,6 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections; using System.Collections.Generic; @@ -148,7 +147,6 @@ public record PointerParameters public PointerType? PointerType { get; set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum PointerType { Mouse, diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs index 3a5d35366b2a3..52b57a4db11fd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs @@ -17,10 +17,8 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections.Generic; -using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Log; @@ -40,7 +38,6 @@ public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Te : Entry(BiDi, Level, Source, Text, Timestamp); } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum Level { Debug, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs index 6ba3dc63b1361..ab7259fa39b9d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs @@ -18,9 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Collections.Generic; -using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Network; @@ -50,7 +48,6 @@ public record BrowsingContextAddInterceptOptions public record AddInterceptResult(Intercept Intercept); -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum InterceptPhase { BeforeRequestSent, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs index c347625c96091..98754195731f2 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs @@ -17,7 +17,6 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Text.Json.Serialization; @@ -29,7 +28,6 @@ public record Cookie(string Name, BytesValue Value, string Domain, string Path, public DateTimeOffset? Expiry { get; internal set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum SameSite { Strict, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs index 9106002acf2ac..c9cc0bf5f0f91 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs @@ -17,9 +17,6 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; -using System.Text.Json.Serialization; - namespace OpenQA.Selenium.BiDi.Modules.Network; public record Initiator(InitiatorType Type) @@ -33,7 +30,6 @@ public record Initiator(InitiatorType Type) public Request? Request { get; set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum InitiatorType { Parser, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs index 8708b3ff47544..ad937f309272b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs @@ -18,9 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System.Collections.Generic; -using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Network; @@ -49,7 +47,6 @@ public record BrowsingContextSetCacheBehaviorOptions } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum CacheBehavior { Default, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs index 79f53626ab9a4..0958b42929edf 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs @@ -17,12 +17,8 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; -using System.Text.Json.Serialization; - namespace OpenQA.Selenium.BiDi.Modules.Script; -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum RealmType { Window, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index 5f8c43c5a7755..3f2769a25882d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -17,10 +17,8 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; using System; using System.Collections.Generic; -using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Script; @@ -270,7 +268,6 @@ public record Properties(BrowsingContext.BrowsingContext Context); public abstract record PrimitiveProtocolRemoteValue : RemoteValue; -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum Mode { Open, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs index a490bd4ae7452..f72d799c061a2 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs @@ -17,12 +17,8 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; -using System.Text.Json.Serialization; - namespace OpenQA.Selenium.BiDi.Modules.Script; -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ResultOwnership { Root, diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs index d81d4d4ae768c..ea4dc82c6da9c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs @@ -17,9 +17,6 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication.Json.Converters; -using System.Text.Json.Serialization; - namespace OpenQA.Selenium.BiDi.Modules.Script; public class SerializationOptions @@ -31,7 +28,6 @@ public class SerializationOptions public ShadowTree? IncludeShadowTree { get; set; } } -[JsonConverter(typeof(CamelCaseJsonEnumStringConverter))] public enum ShadowTree { None, From 87cfb98d4d9b0d4f20624d0c87e4cd751e7142c9 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 21 Mar 2025 11:20:01 -0400 Subject: [PATCH 06/11] minimize unnecessary changes --- dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs | 1 + .../src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs | 2 +- .../webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs index 456cec5f9acad..822fbe26ae33d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs @@ -17,6 +17,7 @@ // under the License. // +using System.Collections.Generic; using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Communication; diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs index ab7259fa39b9d..67490235f9651 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs @@ -17,8 +17,8 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +using OpenQA.Selenium.BiDi.Communication; namespace OpenQA.Selenium.BiDi.Modules.Network; diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs index ad937f309272b..11a372901c22a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs @@ -17,8 +17,8 @@ // under the License. // -using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +using OpenQA.Selenium.BiDi.Communication; namespace OpenQA.Selenium.BiDi.Modules.Network; From a6be912c50eccb40e32baf683b31f7c450f38c2f Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 28 Mar 2025 00:53:10 -0400 Subject: [PATCH 07/11] Back out `Command` changes --- dotnet/src/webdriver/Command.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dotnet/src/webdriver/Command.cs b/dotnet/src/webdriver/Command.cs index 5b004b0caafd2..b3bce18434aa2 100644 --- a/dotnet/src/webdriver/Command.cs +++ b/dotnet/src/webdriver/Command.cs @@ -86,12 +86,17 @@ public string ParametersAsJsonString { get { - if (this.Parameters == null || this.Parameters.Count <= 0) + string parametersString; + if (this.Parameters != null && this.Parameters.Count > 0) { - return "{}"; + parametersString = JsonSerializer.Serialize(this.Parameters, s_jsonSerializerOptions); + } + else + { + parametersString = "{}"; } - return JsonSerializer.Serialize(this.Parameters, s_jsonSerializerOptions); + return parametersString; } } @@ -113,7 +118,7 @@ public override string ToString() /// If is . private static Dictionary? ConvertParametersFromJson(string value) { - Dictionary? parameters = JsonSerializer.Deserialize>(value, CommandJsonSerializerContext.Default.DictionaryStringObject!); + Dictionary? parameters = JsonSerializer.Deserialize>(value, s_jsonSerializerOptions); return parameters; } } @@ -162,6 +167,5 @@ public override string ToString() [JsonSerializable(typeof(Dictionary))] [JsonSerializable(typeof(Dictionary))] [JsonSerializable(typeof(Dictionary))] - [JsonSourceGenerationOptions(Converters = [typeof(ResponseValueJsonConverter)])] internal partial class CommandJsonSerializerContext : JsonSerializerContext; } From 38c1eaa9d5ab181ae8eb97810922171ee81234df Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Mon, 7 Apr 2025 19:12:04 +0300 Subject: [PATCH 08/11] Enumerable --- .../Enumerable/GetClientWindowsResultConverter.cs | 6 ++---- .../Enumerable/GetCookiesResultConverter.cs | 8 +++----- .../Enumerable/GetRealmsResultConverter.cs | 6 ++---- .../Enumerable/GetUserContextsResultConverter.cs | 6 ++---- .../Enumerable/InputSourceActionsConverter.cs | 12 +++++++----- .../Enumerable/LocateNodesResultConverter.cs | 6 ++---- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs index 7d7934d7c6672..4cae6d25dff2b 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs @@ -20,20 +20,18 @@ using OpenQA.Selenium.BiDi.Modules.Browser; using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetClientWindowsResultConverter : JsonConverter { public override GetClientWindowsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var clientWindows = doc.RootElement.GetProperty("clientWindows").Deserialize>(options); + var clientWindows = doc.RootElement.GetProperty("clientWindows").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); return new GetClientWindowsResult(clientWindows!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs index 0a8dc399aa12c..515eb559064fa 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs @@ -20,21 +20,19 @@ using OpenQA.Selenium.BiDi.Modules.Storage; using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetCookiesResultConverter : JsonConverter { public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var cookies = doc.RootElement.GetProperty("cookies").Deserialize>(options); - var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize(options); + var cookies = doc.RootElement.GetProperty("cookies").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); + var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize((JsonTypeInfo)options.GetTypeInfo(typeof(PartitionKey))); return new GetCookiesResult(cookies!, partitionKey!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs index efa03daabc144..d7a7691dbde06 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs @@ -20,20 +20,18 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetRealmsResultConverter : JsonConverter { public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var realms = doc.RootElement.GetProperty("realms").Deserialize>(options); + var realms = doc.RootElement.GetProperty("realms").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); return new GetRealmsResult(realms!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs index dc6f4683018e6..a061f054ee7b0 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs @@ -20,20 +20,18 @@ using OpenQA.Selenium.BiDi.Modules.Browser; using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class GetUserContextsResultConverter : JsonConverter { public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize>(options); + var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); return new GetUserContextsResult(userContexts!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs index 559a3a874c83f..957cbba485ef4 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -19,10 +19,12 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; @@ -46,7 +48,7 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria case KeyActions keys: writer.WriteString("type", "key"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), options); + JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); break; case PointerActions pointers: @@ -54,23 +56,23 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria if (pointers.Options is not null) { writer.WritePropertyName("parameters"); - JsonSerializer.Serialize(writer, pointers.Options, options); + JsonSerializer.Serialize(writer, pointers.Options, (JsonTypeInfo)options.GetTypeInfo(typeof(PointerParameters))); } writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), options); + JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); break; case WheelActions wheels: writer.WriteString("type", "wheel"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), options); + JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); break; case NoneActions none: writer.WriteString("type", "none"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), options); + JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); break; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs index 4091ddac4666d..5caba6e34b633 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs @@ -21,20 +21,18 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class LocateNodesResultConverter : JsonConverter { public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var nodes = doc.RootElement.GetProperty("nodes").Deserialize>(options); + var nodes = doc.RootElement.GetProperty("nodes").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); return new LocateNodesResult(nodes!); } From 7eecb0af2978e530ffd6f832f8ef468fc9d848b1 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Mon, 7 Apr 2025 19:22:52 +0300 Subject: [PATCH 09/11] Extension --- .../Enumerable/GetClientWindowsResultConverter.cs | 4 ++-- .../Enumerable/GetCookiesResultConverter.cs | 3 ++- .../Enumerable/GetRealmsResultConverter.cs | 4 ++-- .../Enumerable/GetUserContextsResultConverter.cs | 4 ++-- .../Enumerable/InputSourceActionsConverter.cs | 12 ++++++------ .../Enumerable/LocateNodesResultConverter.cs | 4 ++-- .../Communication/Json/Internal/JsonExtensions.cs | 6 ++++++ 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs index 4cae6d25dff2b..f3184aaa607da 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetClientWindowsResultConverter.cs @@ -17,12 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Browser; using System; using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; @@ -31,7 +31,7 @@ internal class GetClientWindowsResultConverter : JsonConverter>)options.GetTypeInfo(typeof(IReadOnlyList))); + var clientWindows = doc.RootElement.GetProperty("clientWindows").Deserialize(options.GetTypeInfo>()); return new GetClientWindowsResult(clientWindows!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs index 515eb559064fa..eb5944eb1719c 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Storage; using System; using System.Collections.Generic; @@ -31,7 +32,7 @@ internal class GetCookiesResultConverter : JsonConverter public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var cookies = doc.RootElement.GetProperty("cookies").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); + var cookies = doc.RootElement.GetProperty("cookies").Deserialize(options.GetTypeInfo>()); var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize((JsonTypeInfo)options.GetTypeInfo(typeof(PartitionKey))); return new GetCookiesResult(cookies!, partitionKey!); diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs index d7a7691dbde06..2759ba6ba6b7f 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs @@ -17,12 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Script; using System; using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; @@ -31,7 +31,7 @@ internal class GetRealmsResultConverter : JsonConverter public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var realms = doc.RootElement.GetProperty("realms").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); + var realms = doc.RootElement.GetProperty("realms").Deserialize(options.GetTypeInfo>()); return new GetRealmsResult(realms!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs index a061f054ee7b0..55b533e877518 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs @@ -17,12 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Browser; using System; using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; @@ -31,7 +31,7 @@ internal class GetUserContextsResultConverter : JsonConverter>)options.GetTypeInfo(typeof(IReadOnlyList))); + var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize(options.GetTypeInfo>()); return new GetUserContextsResult(userContexts!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs index 957cbba485ef4..d997fb708b0b4 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -17,6 +17,7 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Input; using System; using System.Collections.Generic; @@ -24,7 +25,6 @@ using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; @@ -48,7 +48,7 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria case KeyActions keys: writer.WriteString("type", "key"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); + JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), options.GetTypeInfo>()); break; case PointerActions pointers: @@ -56,23 +56,23 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria if (pointers.Options is not null) { writer.WritePropertyName("parameters"); - JsonSerializer.Serialize(writer, pointers.Options, (JsonTypeInfo)options.GetTypeInfo(typeof(PointerParameters))); + JsonSerializer.Serialize(writer, pointers.Options, options.GetTypeInfo(typeof(PointerParameters))); } writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); + JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), options.GetTypeInfo>()); break; case WheelActions wheels: writer.WriteString("type", "wheel"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); + JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), options.GetTypeInfo>()); break; case NoneActions none: writer.WriteString("type", "none"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), (JsonTypeInfo>)options.GetTypeInfo(typeof(IEnumerable))); + JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), options.GetTypeInfo>()); break; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs index 5caba6e34b633..36afde9ef7094 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs @@ -17,13 +17,13 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using OpenQA.Selenium.BiDi.Modules.Script; using System; using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; @@ -32,7 +32,7 @@ internal class LocateNodesResultConverter : JsonConverter public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var nodes = doc.RootElement.GetProperty("nodes").Deserialize((JsonTypeInfo>)options.GetTypeInfo(typeof(IReadOnlyList))); + var nodes = doc.RootElement.GetProperty("nodes").Deserialize(options.GetTypeInfo>()); return new LocateNodesResult(nodes!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Internal/JsonExtensions.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Internal/JsonExtensions.cs index 812416dc02e95..95bc5ad4915e3 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Internal/JsonExtensions.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Internal/JsonExtensions.cs @@ -18,6 +18,7 @@ // using System.Text.Json; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi.Communication.Json.Internal; @@ -51,4 +52,9 @@ public static string GetDiscriminator(this ref Utf8JsonReader reader, string nam return discriminator ?? throw new JsonException($"Couldn't determine '{name}' discriminator."); } + + public static JsonTypeInfo GetTypeInfo(this JsonSerializerOptions options) + { + return (JsonTypeInfo)options.GetTypeInfo(typeof(T)); + } } From ed9bf29424e0a9823f08715d62c5fd0359388db4 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Mon, 7 Apr 2025 19:30:56 +0300 Subject: [PATCH 10/11] Polymorphic --- .../Polymorphic/EvaluateResultConverter.cs | 7 +-- .../Polymorphic/LogEntryConverter.cs | 7 +-- .../Polymorphic/RealmInfoConverter.cs | 19 +++---- .../Polymorphic/RemoteValueConverter.cs | 55 +++++++++---------- 4 files changed, 38 insertions(+), 50 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs index 237159f302104..81da2edda5a2b 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs @@ -20,14 +20,11 @@ using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Script; using System; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] // https://github.com/dotnet/runtime/issues/72604 internal class EvaluateResultConverter : JsonConverter { @@ -35,8 +32,8 @@ internal class EvaluateResultConverter : JsonConverter { return reader.GetDiscriminator("type") switch { - "success" => JsonSerializer.Deserialize(ref reader, options), - "exception" => JsonSerializer.Deserialize(ref reader, options), + "success" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "exception" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), _ => null, }; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs index a5979eb3b20e2..17c917d3cd82a 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs @@ -20,23 +20,20 @@ using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Log; using System; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class LogEntryConverter : JsonConverter { public override Modules.Log.LogEntry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return reader.GetDiscriminator("type") switch { - "console" => JsonSerializer.Deserialize(ref reader, options), - "javascript" => JsonSerializer.Deserialize(ref reader, options), + "console" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "javascript" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), _ => null, }; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs index cbee5b2cd126d..635e2eb79864c 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs @@ -20,29 +20,26 @@ using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Script; using System; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class RealmInfoConverter : JsonConverter { public override RealmInfo? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { return reader.GetDiscriminator("type") switch { - "window" => JsonSerializer.Deserialize(ref reader, options), - "dedicated-worker" => JsonSerializer.Deserialize(ref reader, options), - "shared-worker" => JsonSerializer.Deserialize(ref reader, options), - "service-worker" => JsonSerializer.Deserialize(ref reader, options), - "worker" => JsonSerializer.Deserialize(ref reader, options), - "paint-worklet" => JsonSerializer.Deserialize(ref reader, options), - "audio-worklet" => JsonSerializer.Deserialize(ref reader, options), - "worklet" => JsonSerializer.Deserialize(ref reader, options), + "window" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "dedicated-worker" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "shared-worker" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "service-worker" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "worker" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "paint-worklet" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "audio-worklet" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "worklet" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), _ => null, }; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs index 25aea24e3467a..2daacdf987e4c 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs @@ -20,15 +20,12 @@ using OpenQA.Selenium.BiDi.Communication.Json.Internal; using OpenQA.Selenium.BiDi.Modules.Script; using System; -using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class RemoteValueConverter : JsonConverter { public override RemoteValue? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) @@ -40,32 +37,32 @@ internal class RemoteValueConverter : JsonConverter return reader.GetDiscriminator("type") switch { - "number" => JsonSerializer.Deserialize(ref reader, options), - "boolean" => JsonSerializer.Deserialize(ref reader, options), - "bigint" => JsonSerializer.Deserialize(ref reader, options), - "string" => JsonSerializer.Deserialize(ref reader, options), - "null" => JsonSerializer.Deserialize(ref reader, options), - "undefined" => JsonSerializer.Deserialize(ref reader, options), - "symbol" => JsonSerializer.Deserialize(ref reader, options), - "array" => JsonSerializer.Deserialize(ref reader, options), - "object" => JsonSerializer.Deserialize(ref reader, options), - "function" => JsonSerializer.Deserialize(ref reader, options), - "regexp" => JsonSerializer.Deserialize(ref reader, options), - "date" => JsonSerializer.Deserialize(ref reader, options), - "map" => JsonSerializer.Deserialize(ref reader, options), - "set" => JsonSerializer.Deserialize(ref reader, options), - "weakmap" => JsonSerializer.Deserialize(ref reader, options), - "weakset" => JsonSerializer.Deserialize(ref reader, options), - "generator" => JsonSerializer.Deserialize(ref reader, options), - "error" => JsonSerializer.Deserialize(ref reader, options), - "proxy" => JsonSerializer.Deserialize(ref reader, options), - "promise" => JsonSerializer.Deserialize(ref reader, options), - "typedarray" => JsonSerializer.Deserialize(ref reader, options), - "arraybuffer" => JsonSerializer.Deserialize(ref reader, options), - "nodelist" => JsonSerializer.Deserialize(ref reader, options), - "htmlcollection" => JsonSerializer.Deserialize(ref reader, options), - "node" => JsonSerializer.Deserialize(ref reader, options), - "window" => JsonSerializer.Deserialize(ref reader, options), + "number" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "boolean" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "bigint" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "string" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "null" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "undefined" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "symbol" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "array" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "object" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "function" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "regexp" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "date" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "map" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "set" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "weakmap" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "weakset" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "generator" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "error" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "proxy" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "promise" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "typedarray" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "arraybuffer" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "nodelist" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "htmlcollection" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "node" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), + "window" => JsonSerializer.Deserialize(ref reader, options.GetTypeInfo()), _ => null, }; } From e379653f01e97a2b1ba61172b141d3dfd192aca2 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Mon, 7 Apr 2025 19:40:36 +0300 Subject: [PATCH 11/11] Update InputSourceActionsConverter.cs --- .../Json/Converters/Enumerable/InputSourceActionsConverter.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs index d997fb708b0b4..478cdf423cb50 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -21,15 +21,12 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")] -[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")] internal class InputSourceActionsConverter : JsonConverter { public override SourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)