diff --git a/dotnet/src/webdriver/BiDi/Browser/ClientWindow.cs b/dotnet/src/webdriver/BiDi/Browser/ClientWindow.cs index 44387a5d67441..d8203dac5962b 100644 --- a/dotnet/src/webdriver/BiDi/Browser/ClientWindow.cs +++ b/dotnet/src/webdriver/BiDi/Browser/ClientWindow.cs @@ -17,8 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Browser; +[JsonConverter(typeof(BrowserClientWindowConverter))] public sealed record ClientWindow { internal ClientWindow(string id) diff --git a/dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs b/dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs index 2d90714d20fec..f5482e65c8b0a 100644 --- a/dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs @@ -18,8 +18,10 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; using System.Collections; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Browser; @@ -28,6 +30,7 @@ internal sealed class GetClientWindowsCommand() public sealed class GetClientWindowsOptions : CommandOptions; +[JsonConverter(typeof(GetClientWindowsResultConverter))] public sealed record GetClientWindowsResult : EmptyResult, IReadOnlyList { internal GetClientWindowsResult(IReadOnlyList clientWindows) diff --git a/dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs b/dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs index 67d1648186f31..08b3b887ba032 100644 --- a/dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs @@ -18,8 +18,10 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; using System.Collections; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Browser; @@ -28,6 +30,7 @@ internal sealed class GetUserContextsCommand() public class GetUserContextsOptions : CommandOptions; +[JsonConverter(typeof(GetUserContextsResultConverter))] public sealed record GetUserContextsResult : EmptyResult, IReadOnlyList { internal GetUserContextsResult(IReadOnlyList userContexts) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEventArgs.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEventArgs.cs index 59812df106df4..1e3dda74f7808 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/DownloadEndEventArgs.cs @@ -17,7 +17,9 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; using System; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.BrowsingContext; @@ -25,6 +27,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; //[JsonPolymorphic(TypeDiscriminatorPropertyName = "status")] //[JsonDerivedType(typeof(DownloadCanceledEventArgs), "canceled")] //[JsonDerivedType(typeof(DownloadCompleteEventArgs), "complete")] +[JsonConverter(typeof(DownloadEndEventArgsConverter))] public abstract record DownloadEndEventArgs(BiDi BiDi, BrowsingContext Context) : BrowsingContextEventArgs(BiDi, Context); diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs index fdc9d0c284d38..f3d989f40f94f 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs @@ -18,8 +18,10 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; using System.Collections; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.BrowsingContext; @@ -47,6 +49,7 @@ public sealed record BrowsingContextGetTreeOptions public long? MaxDepth { get; set; } } +[JsonConverter(typeof(GetTreeResultConverter))] public sealed record GetTreeResult : EmptyResult, IReadOnlyList { internal GetTreeResult(IReadOnlyList contexts) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs index 3f38ab986eeaf..9ba8872e2f76e 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs @@ -18,8 +18,10 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; using System.Collections; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.BrowsingContext; @@ -37,6 +39,7 @@ public sealed class LocateNodesOptions : CommandOptions public IEnumerable? StartNodes { get; set; } } +[JsonConverter(typeof(LocateNodesResultConverter))] public sealed record LocateNodesResult : EmptyResult, IReadOnlyList { internal LocateNodesResult(IReadOnlyList nodes) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/Navigation.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/Navigation.cs index c763d7cc4a482..9acb3047f7c52 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/Navigation.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/Navigation.cs @@ -17,6 +17,10 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.BrowsingContext; +[JsonConverter(typeof(NavigationConverter))] public sealed record Navigation(string Id); diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs index 41b184c98ce7f..85cad725ca42a 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs @@ -72,6 +72,7 @@ public struct PrintPage public double? Width { get; set; } } +[JsonConverter(typeof(PrintPageRangeConverter))] public readonly record struct PrintPageRange(int? Start, int? End) { public static implicit operator PrintPageRange(int index) { return new PrintPageRange(index, index); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 8f5b7848bb21f..3049ea23a2e50 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -72,39 +72,15 @@ internal Broker(BiDi bidi, Uri url) Converters = { new BrowsingContextConverter(_bidi), - new BrowserUserContextConverter(bidi), - new BrowserClientWindowConverter(), - new NavigationConverter(), + new BrowserUserContextConverter(_bidi), new CollectorConverter(_bidi), new InterceptConverter(_bidi), - new RequestConverter(), - new ChannelConverter(), new HandleConverter(_bidi), new InternalIdConverter(_bidi), new PreloadScriptConverter(_bidi), new RealmConverter(_bidi), new DateTimeOffsetConverter(), - new PrintPageRangeConverter(), - new InputOriginConverter(), new WebExtensionConverter(_bidi), - new SubscriptionConverter(), - - // https://github.com/dotnet/runtime/issues/72604 - new Json.Converters.Polymorphic.EvaluateResultConverter(), - new Json.Converters.Polymorphic.RemoteValueConverter(), - new Json.Converters.Polymorphic.RealmInfoConverter(), - new Json.Converters.Polymorphic.LogEntryConverter(), - new Json.Converters.Polymorphic.DownloadEndEventArgsConverter(), - // - - // Enumerable - new Json.Converters.Enumerable.GetCookiesResultConverter(), - new Json.Converters.Enumerable.LocateNodesResultConverter(), - new Json.Converters.Enumerable.InputSourceActionsConverter(), - new Json.Converters.Enumerable.GetUserContextsResultConverter(), - new Json.Converters.Enumerable.GetClientWindowsResultConverter(), - new Json.Converters.Enumerable.GetRealmsResultConverter(), - new Json.Converters.Enumerable.GetTreeResultConverter(), } }; diff --git a/dotnet/src/webdriver/BiDi/Input/Origin.cs b/dotnet/src/webdriver/BiDi/Input/Origin.cs index 55eb1eb6361f3..fc1d4dcc61377 100644 --- a/dotnet/src/webdriver/BiDi/Input/Origin.cs +++ b/dotnet/src/webdriver/BiDi/Input/Origin.cs @@ -17,8 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Input; +[JsonConverter(typeof(InputOriginConverter))] public abstract record Origin; public sealed record ViewportOrigin() : Origin; diff --git a/dotnet/src/webdriver/BiDi/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Input/SourceActions.cs index e1152b1d3d89b..cfc5983e2b066 100644 --- a/dotnet/src/webdriver/BiDi/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Input/SourceActions.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; using System; using System.Collections; using System.Collections.Generic; @@ -25,6 +26,7 @@ namespace OpenQA.Selenium.BiDi.Input; +[JsonConverter(typeof(InputSourceActionsConverter))] public abstract record SourceActions { public string Id { get; } = Guid.NewGuid().ToString(); diff --git a/dotnet/src/webdriver/BiDi/Log/LogEntry.cs b/dotnet/src/webdriver/BiDi/Log/LogEntry.cs index b08d9d207dbe6..783495c3fef26 100644 --- a/dotnet/src/webdriver/BiDi/Log/LogEntry.cs +++ b/dotnet/src/webdriver/BiDi/Log/LogEntry.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; using System; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -29,6 +30,7 @@ namespace OpenQA.Selenium.BiDi.Log; //[JsonDerivedType(typeof(GenericLogEntry))] //[JsonDerivedType(typeof(ConsoleLogEntry), "console")] //[JsonDerivedType(typeof(JavascriptLogEntry), "javascript")] +[JsonConverter(typeof(LogEntryConverter))] public abstract record LogEntry(BiDi BiDi, Level Level, Script.Source Source, string? Text, DateTimeOffset Timestamp) : EventArgs(BiDi) { diff --git a/dotnet/src/webdriver/BiDi/Network/Request.cs b/dotnet/src/webdriver/BiDi/Network/Request.cs index 0182c49838205..c3d97ace206ad 100644 --- a/dotnet/src/webdriver/BiDi/Network/Request.cs +++ b/dotnet/src/webdriver/BiDi/Network/Request.cs @@ -17,8 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Network; +[JsonConverter(typeof(RequestConverter))] public sealed class Request { internal Request(string id) diff --git a/dotnet/src/webdriver/BiDi/Script/Channel.cs b/dotnet/src/webdriver/BiDi/Script/Channel.cs index ea21ef212f3d3..9d1ca1f61b5cf 100644 --- a/dotnet/src/webdriver/BiDi/Script/Channel.cs +++ b/dotnet/src/webdriver/BiDi/Script/Channel.cs @@ -17,6 +17,10 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Script; +[JsonConverter(typeof(ChannelConverter))] public sealed record Channel(string Id); diff --git a/dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs b/dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs index 170cc8ad01c08..3396c240e5148 100644 --- a/dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs @@ -18,7 +18,9 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; using System; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Script; @@ -40,6 +42,7 @@ public sealed class EvaluateOptions : CommandOptions //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] //[JsonDerivedType(typeof(EvaluateResultSuccess), "success")] //[JsonDerivedType(typeof(EvaluateResultException), "exception")] +[JsonConverter(typeof(EvaluateResultConverter))] public abstract record EvaluateResult : EmptyResult { public RemoteValue AsSuccessResult() diff --git a/dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs b/dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs index 94f23a1063c4c..4adfd14c76acc 100644 --- a/dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs @@ -18,8 +18,10 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; using System.Collections; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Script; @@ -35,6 +37,7 @@ public sealed class GetRealmsOptions : CommandOptions public RealmType? Type { get; set; } } +[JsonConverter(typeof(GetRealmsResultConverter))] public sealed record GetRealmsResult : EmptyResult, IReadOnlyList { private readonly IReadOnlyList _realms; diff --git a/dotnet/src/webdriver/BiDi/Script/RealmInfo.cs b/dotnet/src/webdriver/BiDi/Script/RealmInfo.cs index 84a97bee9ee2c..c22c7cb52be8f 100644 --- a/dotnet/src/webdriver/BiDi/Script/RealmInfo.cs +++ b/dotnet/src/webdriver/BiDi/Script/RealmInfo.cs @@ -17,7 +17,9 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; using System.Collections.Generic; +using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Script; @@ -31,6 +33,7 @@ namespace OpenQA.Selenium.BiDi.Script; //[JsonDerivedType(typeof(PaintWorkletRealmInfo), "paint-worklet")] //[JsonDerivedType(typeof(AudioWorkletRealmInfo), "audio-worklet")] //[JsonDerivedType(typeof(WorkletRealmInfo), "worklet")] +[JsonConverter(typeof(RealmInfoConverter))] public abstract record RealmInfo(BiDi BiDi, Realm Realm, string Origin) : EventArgs(BiDi); public sealed record WindowRealmInfo(BiDi BiDi, Realm Realm, string Origin, BrowsingContext.BrowsingContext Context) : RealmInfo(BiDi, Realm, Origin) diff --git a/dotnet/src/webdriver/BiDi/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Script/RemoteValue.cs index e42ad9b1a942a..be58fcc6a2d77 100644 --- a/dotnet/src/webdriver/BiDi/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Script/RemoteValue.cs @@ -18,12 +18,12 @@ // using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; using System; using System.Collections.Generic; using System.Numerics; using System.Text.Json; using System.Text.Json.Serialization; -using OpenQA.Selenium.BiDi.Communication.Json.Converters; namespace OpenQA.Selenium.BiDi.Script; @@ -55,6 +55,7 @@ namespace OpenQA.Selenium.BiDi.Script; //[JsonDerivedType(typeof(HtmlCollectionRemoteValue), "htmlcollection")] //[JsonDerivedType(typeof(NodeRemoteValue), "node")] //[JsonDerivedType(typeof(WindowProxyRemoteValue), "window")] +[JsonConverter(typeof(RemoteValueConverter))] public abstract record RemoteValue { public static implicit operator double(RemoteValue remoteValue) => (double)((NumberRemoteValue)remoteValue).Value; diff --git a/dotnet/src/webdriver/BiDi/Session/Subscription.cs b/dotnet/src/webdriver/BiDi/Session/Subscription.cs index 89788503a78f8..7f9899581f556 100644 --- a/dotnet/src/webdriver/BiDi/Session/Subscription.cs +++ b/dotnet/src/webdriver/BiDi/Session/Subscription.cs @@ -17,8 +17,12 @@ // under the License. // +using OpenQA.Selenium.BiDi.Communication.Json.Converters; +using System.Text.Json.Serialization; + namespace OpenQA.Selenium.BiDi.Session; +[JsonConverter(typeof(SubscriptionConverter))] public sealed class Subscription { internal Subscription(string id) diff --git a/dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs index 781de8e09a4f9..8ff742f4a1e35 100644 --- a/dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs @@ -18,6 +18,7 @@ // using OpenQA.Selenium.BiDi.Communication; +using OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; using System; using System.Collections; using System.Collections.Generic; @@ -37,6 +38,7 @@ public sealed class GetCookiesOptions : CommandOptions public PartitionDescriptor? Partition { get; set; } } +[JsonConverter(typeof(GetCookiesResultConverter))] public sealed record GetCookiesResult : EmptyResult, IReadOnlyList { internal GetCookiesResult(IReadOnlyList cookies, PartitionKey partitionKey)