diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index 32c3335a61bb3..3f4fc34018617 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -66,8 +66,8 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Modules.Script.RealmInfo.AudioWorklet))] [JsonSerializable(typeof(Modules.Script.RealmInfo.Worklet))] -[JsonSerializable(typeof(Modules.Log.Entry.Console))] -[JsonSerializable(typeof(Modules.Log.Entry.Javascript))] +[JsonSerializable(typeof(Modules.Log.ConsoleLogEntry))] +[JsonSerializable(typeof(Modules.Log.JavascriptLogEntry))] #endregion [JsonSerializable(typeof(Command))] @@ -157,7 +157,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Modules.Script.RealmDestroyedEventArgs))] [JsonSerializable(typeof(IReadOnlyList))] -[JsonSerializable(typeof(Modules.Log.Entry))] +[JsonSerializable(typeof(Modules.Log.LogEntry))] [JsonSerializable(typeof(Modules.Storage.GetCookiesCommand))] [JsonSerializable(typeof(Modules.Storage.GetCookiesResult))] 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..82cf56dd6013b 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs @@ -25,21 +25,21 @@ namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 -internal class LogEntryConverter : JsonConverter +internal class LogEntryConverter : JsonConverter { - public override Modules.Log.Entry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override Modules.Log.LogEntry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var jsonDocument = JsonDocument.ParseValue(ref reader); return jsonDocument.RootElement.GetProperty("type").ToString() switch { - "console" => jsonDocument.Deserialize(options), - "javascript" => jsonDocument.Deserialize(options), + "console" => jsonDocument.Deserialize(options), + "javascript" => jsonDocument.Deserialize(options), _ => null, }; } - public override void Write(Utf8JsonWriter writer, Modules.Log.Entry value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, Modules.Log.LogEntry value, JsonSerializerOptions options) { throw new NotImplementedException(); } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs index 026e2dfd496e6..f70473c50dea6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs @@ -25,7 +25,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextLogModule(BrowsingContext context, LogModule logModule) { - public Task OnEntryAddedAsync(Func handler, SubscriptionOptions? options = null) + public Task OnEntryAddedAsync(Func handler, SubscriptionOptions? options = null) { return logModule.OnEntryAddedAsync(async args => { @@ -36,7 +36,7 @@ public Task OnEntryAddedAsync(Func handler, Subscript }, options); } - public Task OnEntryAddedAsync(Action handler, SubscriptionOptions? options = null) + public Task OnEntryAddedAsync(Action handler, SubscriptionOptions? options = null) { return logModule.OnEntryAddedAsync(args => { diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs b/dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs similarity index 62% rename from dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs rename to dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs index 52b57a4db11fd..5022ed0a5c6b7 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs @@ -1,4 +1,4 @@ -// +// // 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 @@ -24,19 +24,19 @@ namespace OpenQA.Selenium.BiDi.Modules.Log; // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(Console), "console")] -//[JsonDerivedType(typeof(Javascript), "javascript")] -public abstract record Entry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) +//[JsonDerivedType(typeof(ConsoleLogEntry), "console")] +//[JsonDerivedType(typeof(JavascriptLogEntry), "javascript")] +public abstract record LogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) : EventArgs(BiDi) { public Script.StackTrace? StackTrace { get; set; } +} - public record Console(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList Args) - : Entry(BiDi, Level, Source, Text, Timestamp); +public record ConsoleLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList Args) + : LogEntry(BiDi, Level, Source, Text, Timestamp); - public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) - : Entry(BiDi, Level, Source, Text, Timestamp); -} +public record JavascriptLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) + : LogEntry(BiDi, Level, Source, Text, Timestamp); public enum Level { diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs b/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs index 5fbdfc9acca07..f1442ee1ee358 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs @@ -25,12 +25,12 @@ namespace OpenQA.Selenium.BiDi.Modules.Log; public sealed class LogModule(Broker broker) : Module(broker) { - public async Task OnEntryAddedAsync(Func handler, SubscriptionOptions? options = null) + public async Task OnEntryAddedAsync(Func handler, SubscriptionOptions? options = null) { return await Broker.SubscribeAsync("log.entryAdded", handler, options).ConfigureAwait(false); } - public async Task OnEntryAddedAsync(Action handler, SubscriptionOptions? options = null) + public async Task OnEntryAddedAsync(Action handler, SubscriptionOptions? options = null) { return await Broker.SubscribeAsync("log.entryAdded", handler, options).ConfigureAwait(false); } diff --git a/dotnet/test/common/BiDi/Log/LogTest.cs b/dotnet/test/common/BiDi/Log/LogTest.cs index 58e0c6a701f6b..00d9b1cedc203 100644 --- a/dotnet/test/common/BiDi/Log/LogTest.cs +++ b/dotnet/test/common/BiDi/Log/LogTest.cs @@ -29,7 +29,7 @@ class LogTest : BiDiTestFixture [Test] public async Task CanListenToConsoleLog() { - TaskCompletionSource tcs = new(); + TaskCompletionSource tcs = new(); await using var subscription = await context.Log.OnEntryAddedAsync(tcs.SetResult); @@ -44,9 +44,9 @@ public async Task CanListenToConsoleLog() Assert.That(logEntry.Source.Realm, Is.Not.Null); Assert.That(logEntry.Text, Is.EqualTo("Hello, world!")); Assert.That(logEntry.Level, Is.EqualTo(Level.Info)); - Assert.That(logEntry, Is.AssignableFrom()); + Assert.That(logEntry, Is.AssignableFrom()); - var consoleLogEntry = logEntry as Entry.Console; + var consoleLogEntry = logEntry as ConsoleLogEntry; Assert.That(consoleLogEntry.Method, Is.EqualTo("log")); @@ -58,7 +58,7 @@ public async Task CanListenToConsoleLog() [Test] public async Task CanListenToJavascriptLog() { - TaskCompletionSource tcs = new(); + TaskCompletionSource tcs = new(); await using var subscription = await context.Log.OnEntryAddedAsync(tcs.SetResult); @@ -73,13 +73,13 @@ public async Task CanListenToJavascriptLog() Assert.That(logEntry.Source.Realm, Is.Not.Null); Assert.That(logEntry.Text, Is.EqualTo("Error: Not working")); Assert.That(logEntry.Level, Is.EqualTo(Level.Error)); - Assert.That(logEntry, Is.AssignableFrom()); + Assert.That(logEntry, Is.AssignableFrom()); } [Test] public async Task CanRetrieveStacktrace() { - TaskCompletionSource tcs = new(); + TaskCompletionSource tcs = new(); await using var subscription = await bidi.Log.OnEntryAddedAsync(tcs.SetResult); diff --git a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs index 6c5e6e3b6cfb1..e5448fcaefd6a 100644 --- a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs +++ b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs @@ -93,7 +93,7 @@ public async Task CanAddPreloadScript() Assert.That(preloadScript, Is.Not.Null); - TaskCompletionSource tcs = new(); + TaskCompletionSource tcs = new(); await context.Log.OnEntryAddedAsync(tcs.SetResult);