From 12785576d49dca6ab9803e51697a4d8f623008f8 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:13:49 +0300 Subject: [PATCH 01/60] Refactor --- dotnet/src/webdriver/BiDi/BiDi.cs | 53 +-- .../Polymorphic/EvaluateResultConverter.cs | 4 +- .../Polymorphic/LogEntryConverter.cs | 4 +- .../Polymorphic/RealmInfoConverter.cs | 16 +- .../Polymorphic/RemoteValueConverter.cs | 46 +-- .../BrowsingContext/BrowsingContext.cs | 52 +-- .../BrowsingContext/BrowsingContextModule.cs | 2 +- .../BrowsingContextScriptModule.cs | 4 +- .../BrowsingContextStorageModule.cs | 6 +- .../CaptureScreenshotCommand.cs | 17 +- .../BrowsingContext/LocateNodesCommand.cs | 2 +- .../BiDi/Modules/BrowsingContext/Locator.cs | 58 ++-- .../webdriver/BiDi/Modules/Log/LogEntry.cs | 15 +- .../BiDi/Modules/Network/AuthCredentials.cs | 6 +- .../BiDi/Modules/Network/BytesValue.cs | 12 +- .../BiDi/Modules/Network/UrlPattern.cs | 32 +- .../BiDi/Modules/Script/EvaluateCommand.cs | 13 +- .../BiDi/Modules/Script/LocalValue.cs | 71 ++-- .../BiDi/Modules/Script/NodeProperties.cs | 4 +- .../BiDi/Modules/Script/RealmInfo.cs | 41 +-- .../BiDi/Modules/Script/RemoteValue.cs | 295 ++++++++--------- .../Modules/Script/ScriptEvaluateException.cs | 4 +- .../BiDi/Modules/Script/ScriptModule.cs | 8 +- .../webdriver/BiDi/Modules/Script/Target.cs | 22 +- .../Modules/Session/ProxyConfiguration.cs | 39 +-- .../BiDi/Modules/Storage/GetCookiesCommand.cs | 25 +- dotnet/test/common/BiDi/BiDiFixture.cs | 21 ++ .../BiDi/Modules/BrowsingContextTest.cs | 305 ++++++++++++++++++ .../test/common/BiDi/Modules/NetworkTest.cs | 21 ++ .../test/common/Environment/DriverFactory.cs | 5 +- 30 files changed, 757 insertions(+), 446 deletions(-) create mode 100644 dotnet/test/common/BiDi/BiDiFixture.cs create mode 100644 dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs create mode 100644 dotnet/test/common/BiDi/Modules/NetworkTest.cs diff --git a/dotnet/src/webdriver/BiDi/BiDi.cs b/dotnet/src/webdriver/BiDi/BiDi.cs index db53571e8ad8c..973fd2ced99cb 100644 --- a/dotnet/src/webdriver/BiDi/BiDi.cs +++ b/dotnet/src/webdriver/BiDi/BiDi.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Communication; using OpenQA.Selenium.BiDi.Communication.Transport; @@ -38,7 +37,7 @@ internal BiDi(string url) } internal Modules.Session.SessionModule SessionModule => _sessionModule.Value; - internal Modules.BrowsingContext.BrowsingContextModule BrowsingContextModule => _browsingContextModule.Value; + internal Modules.BrowsingContext.BrowsingContextModule BrowsingContext => _browsingContextModule.Value; public Modules.Browser.BrowserModule Browser => _browserModule.Value; public Modules.Network.NetworkModule Network => _networkModule.Value; internal Modules.Input.InputModule InputModule => _inputModule.Value; @@ -60,16 +59,6 @@ public static async Task ConnectAsync(string url) return bidi; } - public Task CreateContextAsync(Modules.BrowsingContext.ContextType type, Modules.BrowsingContext.CreateOptions? options = null) - { - return BrowsingContextModule.CreateAsync(type, options); - } - - public Task> GetTreeAsync(Modules.BrowsingContext.GetTreeOptions? options = null) - { - return BrowsingContextModule.GetTreeAsync(options); - } - public Task EndAsync(Modules.Session.EndOptions? options = null) { return SessionModule.EndAsync(options); @@ -81,44 +70,4 @@ public async ValueTask DisposeAsync() _transport?.Dispose(); } - - public Task OnContextCreatedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnContextCreatedAsync(handler, options); - } - - public Task OnContextCreatedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnContextCreatedAsync(handler, options); - } - - public Task OnContextDestroyedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnContextDestroyedAsync(handler, options); - } - - public Task OnContextDestroyedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnContextDestroyedAsync(handler, options); - } - - public Task OnUserPromptOpenedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnUserPromptOpenedAsync(handler, options); - } - - public Task OnUserPromptOpenedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnUserPromptOpenedAsync(handler, options); - } - - public Task OnUserPromptClosedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnUserPromptClosedAsync(handler, options); - } - - public Task OnUserPromptClosedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) - { - return BrowsingContextModule.OnUserPromptClosedAsync(handler, 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 c349d82f90f04..3d8669c372ebf 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs @@ -14,8 +14,8 @@ internal class EvaluateResultConverter : JsonConverter return jsonDocument.RootElement.GetProperty("type").ToString() switch { - "success" => jsonDocument.Deserialize(options), - "exception" => jsonDocument.Deserialize(options), + "success" => jsonDocument.Deserialize(options), + "exception" => jsonDocument.Deserialize(options), _ => 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 ada10ab054a50..13a388bb97ff1 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs @@ -14,8 +14,8 @@ internal class LogEntryConverter : JsonConverter return jsonDocument.RootElement.GetProperty("type").ToString() switch { - "console" => jsonDocument.Deserialize(options), - "javascript" => jsonDocument.Deserialize(options), + "console" => jsonDocument.Deserialize(options), + "javascript" => jsonDocument.Deserialize(options), _ => 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 b3d061783dfae..3fff1242c6698 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs @@ -14,14 +14,14 @@ internal class RealmInfoConverter : JsonConverter return jsonDocument.RootElement.GetProperty("type").ToString() switch { - "window" => jsonDocument.Deserialize(options), - "dedicated-worker" => jsonDocument.Deserialize(options), - "shared-worker" => jsonDocument.Deserialize(options), - "service-worker" => jsonDocument.Deserialize(options), - "worker" => jsonDocument.Deserialize(options), - "paint-worklet" => jsonDocument.Deserialize(options), - "audio-worklet" => jsonDocument.Deserialize(options), - "worklet" => jsonDocument.Deserialize(options), + "window" => jsonDocument.Deserialize(options), + "dedicated-worker" => jsonDocument.Deserialize(options), + "shared-worker" => jsonDocument.Deserialize(options), + "service-worker" => jsonDocument.Deserialize(options), + "worker" => jsonDocument.Deserialize(options), + "paint-worklet" => jsonDocument.Deserialize(options), + "audio-worklet" => jsonDocument.Deserialize(options), + "worklet" => jsonDocument.Deserialize(options), _ => 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 1d3b08211b348..9451e541d8f5a 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs @@ -14,29 +14,29 @@ internal class RemoteValueConverter : JsonConverter return jsonDocument.RootElement.GetProperty("type").ToString() switch { - "number" => jsonDocument.Deserialize(options), - "string" => jsonDocument.Deserialize(options), - "null" => jsonDocument.Deserialize(options), - "undefined" => jsonDocument.Deserialize(options), - "symbol" => jsonDocument.Deserialize(options), - "object" => jsonDocument.Deserialize(options), - "function" => jsonDocument.Deserialize(options), - "regexp" => jsonDocument.Deserialize(options), - "date" => jsonDocument.Deserialize(options), - "map" => jsonDocument.Deserialize(options), - "set" => jsonDocument.Deserialize(options), - "weakmap" => jsonDocument.Deserialize(options), - "weakset" => jsonDocument.Deserialize(options), - "generator" => jsonDocument.Deserialize(options), - "error" => jsonDocument.Deserialize(options), - "proxy" => jsonDocument.Deserialize(options), - "promise" => jsonDocument.Deserialize(options), - "typedarray" => jsonDocument.Deserialize(options), - "arraybuffer" => jsonDocument.Deserialize(options), - "nodelist" => jsonDocument.Deserialize(options), - "htmlcollection" => jsonDocument.Deserialize(options), - "node" => jsonDocument.Deserialize(options), - "window" => jsonDocument.Deserialize(options), + "number" => jsonDocument.Deserialize(options), + "string" => jsonDocument.Deserialize(options), + "null" => jsonDocument.Deserialize(options), + "undefined" => jsonDocument.Deserialize(options), + "symbol" => jsonDocument.Deserialize(options), + "object" => jsonDocument.Deserialize(options), + "function" => jsonDocument.Deserialize(options), + "regexp" => jsonDocument.Deserialize(options), + "date" => jsonDocument.Deserialize(options), + "map" => jsonDocument.Deserialize(options), + "set" => jsonDocument.Deserialize(options), + "weakmap" => jsonDocument.Deserialize(options), + "weakset" => jsonDocument.Deserialize(options), + "generator" => jsonDocument.Deserialize(options), + "error" => jsonDocument.Deserialize(options), + "proxy" => jsonDocument.Deserialize(options), + "promise" => jsonDocument.Deserialize(options), + "typedarray" => jsonDocument.Deserialize(options), + "arraybuffer" => jsonDocument.Deserialize(options), + "nodelist" => jsonDocument.Deserialize(options), + "htmlcollection" => jsonDocument.Deserialize(options), + "node" => jsonDocument.Deserialize(options), + "window" => jsonDocument.Deserialize(options), _ => null, }; } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs index 80c7b7d49fb70..e0b27bf73d199 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs @@ -40,37 +40,37 @@ internal BrowsingContext(BiDi bidi, string id) public Task NavigateAsync(string url, NavigateOptions? options = null) { - return BiDi.BrowsingContextModule.NavigateAsync(this, url, options); + return BiDi.BrowsingContext.NavigateAsync(this, url, options); } public Task ReloadAsync(ReloadOptions? options = null) { - return BiDi.BrowsingContextModule.ReloadAsync(this, options); + return BiDi.BrowsingContext.ReloadAsync(this, options); } public Task ActivateAsync(ActivateOptions? options = null) { - return BiDi.BrowsingContextModule.ActivateAsync(this, options); + return BiDi.BrowsingContext.ActivateAsync(this, options); } - public Task> LocateNodesAsync(Locator locator, LocateNodesOptions? options = null) + public Task> LocateNodesAsync(Locator locator, LocateNodesOptions? options = null) { - return BiDi.BrowsingContextModule.LocateNodesAsync(this, locator, options); + return BiDi.BrowsingContext.LocateNodesAsync(this, locator, options); } public Task CaptureScreenshotAsync(CaptureScreenshotOptions? options = null) { - return BiDi.BrowsingContextModule.CaptureScreenshotAsync(this, options); + return BiDi.BrowsingContext.CaptureScreenshotAsync(this, options); } public Task CloseAsync(CloseOptions? options = null) { - return BiDi.BrowsingContextModule.CloseAsync(this, options); + return BiDi.BrowsingContext.CloseAsync(this, options); } public Task TraverseHistoryAsync(int delta, TraverseHistoryOptions? options = null) { - return BiDi.BrowsingContextModule.TraverseHistoryAsync(this, delta, options); + return BiDi.BrowsingContext.TraverseHistoryAsync(this, delta, options); } public Task NavigateBackAsync(TraverseHistoryOptions? options = null) @@ -85,17 +85,17 @@ public Task NavigateForwardAsync(TraverseHistoryOptions? options = null) public Task SetViewportAsync(SetViewportOptions? options = null) { - return BiDi.BrowsingContextModule.SetViewportAsync(this, options); + return BiDi.BrowsingContext.SetViewportAsync(this, options); } public Task PrintAsync(PrintOptions? options = null) { - return BiDi.BrowsingContextModule.PrintAsync(this, options); + return BiDi.BrowsingContext.PrintAsync(this, options); } public Task HandleUserPromptAsync(HandleUserPromptOptions? options = null) { - return BiDi.BrowsingContextModule.HandleUserPromptAsync(this, options); + return BiDi.BrowsingContext.HandleUserPromptAsync(this, options); } public Task> GetTreeAsync(BrowsingContextGetTreeOptions? options = null) @@ -105,77 +105,77 @@ public Task> GetTreeAsync(BrowsingContextGetT Root = this }; - return BiDi.BrowsingContextModule.GetTreeAsync(getTreeOptions); + return BiDi.BrowsingContext.GetTreeAsync(getTreeOptions); } public Task OnNavigationStartedAsync(Func handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnNavigationStartedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnNavigationStartedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnNavigationStartedAsync(Action handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnNavigationStartedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnNavigationStartedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnFragmentNavigatedAsync(Func handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnFragmentNavigatedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnFragmentNavigatedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnFragmentNavigatedAsync(Action handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnFragmentNavigatedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnFragmentNavigatedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnDomContentLoadedAsync(Func handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnDomContentLoadedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnDomContentLoadedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnLoadAsync(Action handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnLoadAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnLoadAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnLoadAsync(Func handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnLoadAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnLoadAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnDownloadWillBeginAsync(Action handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnDownloadWillBeginAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnDownloadWillBeginAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnDownloadWillBeginAsync(Func handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnDownloadWillBeginAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnDownloadWillBeginAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnNavigationAbortedAsync(Action handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnNavigationAbortedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnNavigationAbortedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnNavigationAbortedAsync(Func handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnNavigationAbortedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnNavigationAbortedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnNavigationFailedAsync(Action handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnNavigationFailedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnNavigationFailedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnNavigationFailedAsync(Func handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnNavigationFailedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnNavigationFailedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public Task OnDomContentLoadedAsync(Action handler, SubscriptionOptions? options = null) { - return BiDi.BrowsingContextModule.OnDomContentLoadedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + return BiDi.BrowsingContext.OnDomContentLoadedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } public override bool Equals(object? obj) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs index fe7a1d3f36343..fbba82c5e1dc7 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs @@ -42,7 +42,7 @@ public async Task ActivateAsync(BrowsingContext context, ActivateOptions? option await Broker.ExecuteCommandAsync(new ActivateCommand(@params), options).ConfigureAwait(false); } - public async Task> LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null) + public async Task> LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null) { var @params = new LocateNodesCommandParameters(context, locator); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs index d2756ecc503cc..6ba84549f0f33 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs @@ -27,7 +27,7 @@ public async Task> GetRealmsAsync(GetRealmsOptions? opt public Task EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null) { - var contextTarget = new ContextTarget(context); + var contextTarget = new Target.Context(context); if (targetOptions is not null) { @@ -46,7 +46,7 @@ public Task EvaluateAsync(string expression, bool awaitPromise, Eva public Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, CallFunctionOptions? options = null, ContextTargetOptions? targetOptions = null) { - var contextTarget = new ContextTarget(context); + var contextTarget = new Target.Context(context); if (targetOptions is not null) { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs index 810f1ab0b32db..1c425302f5f00 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs @@ -9,7 +9,7 @@ public Task GetCookiesAsync(GetCookiesOptions? options = null) { options ??= new(); - options.Partition = new BrowsingContextPartitionDescriptor(context); + options.Partition = new PartitionDescriptor.Context(context); return storageModule.GetCookiesAsync(options); } @@ -18,7 +18,7 @@ public async Task DeleteCookiesAsync(DeleteCookiesOptions? options { options ??= new(); - options.Partition = new BrowsingContextPartitionDescriptor(context); + options.Partition = new PartitionDescriptor.Context(context); var res = await storageModule.DeleteCookiesAsync(options).ConfigureAwait(false); @@ -29,7 +29,7 @@ public async Task SetCookieAsync(PartialCookie cookie, SetCookieOp { options ??= new(); - options.Partition = new BrowsingContextPartitionDescriptor(context); + options.Partition = new PartitionDescriptor.Context(context); var res = await storageModule.SetCookieAsync(cookie, options).ConfigureAwait(false); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 69ea01b0e70d8..3774716518d29 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -35,13 +35,18 @@ public record struct ImageFormat(string Type) } [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(BoxClipRectangle), "box")] -[JsonDerivedType(typeof(ElementClipRectangle), "element")] -public abstract record ClipRectangle; - -public record BoxClipRectangle(double X, double Y, double Width, double Height) : ClipRectangle; +[JsonDerivedType(typeof(Box), "box")] +[JsonDerivedType(typeof(Element), "element")] +public abstract record ClipRectangle +{ + public record Box(double X, double Y, double Width, double Height) : ClipRectangle; -public record ElementClipRectangle(Script.SharedReference Element) : ClipRectangle; + public record Element(Script.SharedReference SharedReference) : ClipRectangle + { + [JsonPropertyName("element")] + public Script.SharedReference SharedReference { get; } = SharedReference; + } +} public record CaptureScreenshotResult(string Data) { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs index 2dce843e557a3..9abc7708fd6cd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs @@ -23,4 +23,4 @@ public record LocateNodesOptions : CommandOptions public IEnumerable? StartNodes { get; set; } } -public record LocateNodesResult(IReadOnlyList Nodes); +public record LocateNodesResult(IReadOnlyList Nodes); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index d931019afd446..ada22f9d6f331 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -1,49 +1,39 @@ using System.Text.Json.Serialization; -using static OpenQA.Selenium.BiDi.Modules.BrowsingContext.AccessibilityLocator; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(AccessibilityLocator), "accessibility")] -[JsonDerivedType(typeof(CssLocator), "css")] -[JsonDerivedType(typeof(InnerTextLocator), "innerText")] -[JsonDerivedType(typeof(XPathLocator), "xpath")] +[JsonDerivedType(typeof(Accessibility), "accessibility")] +[JsonDerivedType(typeof(Css), "css")] +[JsonDerivedType(typeof(InnerText), "innerText")] +[JsonDerivedType(typeof(XPath), "xpath")] public abstract record Locator { - public static CssLocator Css(string value) - => new(value); - - public static InnerTextLocator InnerText(string value, bool? ignoreCase = null, MatchType? matchType = null, long? maxDepth = null) - => new(value) { IgnoreCase = ignoreCase, MatchType = matchType, MaxDepth = maxDepth }; - - public static XPathLocator XPath(string value) - => new(value); -} - -public record AccessibilityLocator(AccessibilityValue Value) : Locator -{ - public record AccessibilityValue + public record Accessibility(Accessibility.AccessibilityValue Value) : Locator { - public string? Name { get; set; } - public string? Role { get; set; } + public record AccessibilityValue + { + public string? Name { get; set; } + public string? Role { get; set; } + } } -} -public record CssLocator(string Value) : Locator; + public record Css(string Value) : Locator; -public record InnerTextLocator(string Value) : Locator -{ - public bool? IgnoreCase { get; set; } + public record InnerText(string Value) : Locator + { + public bool? IgnoreCase { get; set; } - public MatchType? MatchType { get; set; } + public MatchType? MatchType { get; set; } - public long? MaxDepth { get; set; } -} + public long? MaxDepth { get; set; } + } -public enum MatchType -{ - Full, - Partial -} + public record XPath(string Value) : Locator; -public record XPathLocator(string Value) : Locator; + public enum MatchType + { + Full, + Partial + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs b/dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs index f210c126a8859..8233c33629ab0 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs @@ -5,16 +5,17 @@ namespace OpenQA.Selenium.BiDi.Modules.Log; // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(ConsoleLogEntry), "console")] -//[JsonDerivedType(typeof(JavascriptLogEntry), "javascript")] +//[JsonDerivedType(typeof(Console), "console")] +//[JsonDerivedType(typeof(Javascript), "javascript")] public abstract record BaseLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) - : EventArgs(BiDi); - -public record ConsoleLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList Args) + : EventArgs(BiDi) +{ + public record Console(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList Args) : BaseLogEntry(BiDi, Level, Source, Text, Timestamp); -public record JavascriptLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) - : BaseLogEntry(BiDi, Level, Source, Text, Timestamp); + public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) + : BaseLogEntry(BiDi, Level, Source, Text, Timestamp); +} public enum Level { diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs index 384360e660f44..51725de887f40 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs @@ -3,10 +3,10 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(BasicAuthCredentials), "password")] +[JsonDerivedType(typeof(Basic), "password")] public abstract record AuthCredentials { - public static BasicAuthCredentials Basic(string username, string password) => new(username, password); + public record Basic(string Username, string Password) : AuthCredentials; } -public record BasicAuthCredentials(string Username, string Password) : AuthCredentials; + diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs b/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs index 02b982422d4c7..355324d621cee 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs @@ -3,13 +3,13 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(StringValue), "string")] -[JsonDerivedType(typeof(Base64Value), "base64")] +[JsonDerivedType(typeof(String), "string")] +[JsonDerivedType(typeof(Base64), "base64")] public abstract record BytesValue { - public static implicit operator BytesValue(string value) => new StringValue(value); -} + public static implicit operator BytesValue(string value) => new String(value); -public record StringValue(string Value) : BytesValue; + public record String(string Value) : BytesValue; -public record Base64Value(string Value) : BytesValue; + public record Base64(string Value) : BytesValue; +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs b/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs index 50226a115f327..97bdba38e8302 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs @@ -3,29 +3,27 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(UrlPatternPattern), "pattern")] -[JsonDerivedType(typeof(UrlPatternString), "string")] +[JsonDerivedType(typeof(Pattern), "pattern")] +[JsonDerivedType(typeof(String), "string")] public abstract record UrlPattern { - public static UrlPatternPattern Patter(string? protocol = null, string? hostname = null, string? port = null, string? pathname = null, string? search = null) - => new() { Protocol = protocol, Hostname = hostname, Port = port, Pathname = pathname, Search = search }; + public static implicit operator UrlPattern(string value) => new String(value); - public static UrlPatternString String(string pattern) => new UrlPatternString(pattern); + public record Pattern : UrlPattern + { + public string? Protocol { get; set; } - public static implicit operator UrlPattern(string value) => new UrlPatternString(value); -} - -public record UrlPatternPattern : UrlPattern -{ - public string? Protocol { get; set; } + public string? Hostname { get; set; } - public string? Hostname { get; set; } + public string? Port { get; set; } - public string? Port { get; set; } + public string? Pathname { get; set; } - public string? Pathname { get; set; } + public string? Search { get; set; } + } - public string? Search { get; set; } + public record String(string Pattern) : UrlPattern + { + public string Pattern { get; } = Pattern; + } } - -public record UrlPatternString(string Pattern) : UrlPattern; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs index 307a9156e8b4b..966b12f18e6ca 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs @@ -24,12 +24,13 @@ public record EvaluateOptions : CommandOptions // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(EvaluateResultSuccess), "success")] -//[JsonDerivedType(typeof(EvaluateResultException), "exception")] -public abstract record EvaluateResult; - -public record EvaluateResultSuccess(RemoteValue Result) : EvaluateResult; +//[JsonDerivedType(typeof(Success), "success")] +//[JsonDerivedType(typeof(Exception), "exception")] +public abstract record EvaluateResult +{ + public record Success(RemoteValue Result) : EvaluateResult; -public record EvaluateResultException(ExceptionDetails ExceptionDetails) : EvaluateResult; + public record Exception(ExceptionDetails ExceptionDetails) : EvaluateResult; +} public record ExceptionDetails(long ColumnNumber, long LineNumber, StackTrace StackTrace, string Text); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs index 3451352ab962d..ea5b0ee425c93 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs @@ -4,20 +4,20 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(NumberLocalValue), "number")] -[JsonDerivedType(typeof(StringLocalValue), "string")] -[JsonDerivedType(typeof(NullLocalValue), "null")] -[JsonDerivedType(typeof(UndefinedLocalValue), "undefined")] -[JsonDerivedType(typeof(ArrayLocalValue), "array")] -[JsonDerivedType(typeof(DateLocalValue), "date")] -[JsonDerivedType(typeof(MapLocalValue), "map")] -[JsonDerivedType(typeof(ObjectLocalValue), "object")] -[JsonDerivedType(typeof(RegExpLocalValue), "regexp")] -[JsonDerivedType(typeof(SetLocalValue), "set")] +[JsonDerivedType(typeof(Number), "number")] +[JsonDerivedType(typeof(String), "string")] +[JsonDerivedType(typeof(Null), "null")] +[JsonDerivedType(typeof(Undefined), "undefined")] +[JsonDerivedType(typeof(Array), "array")] +[JsonDerivedType(typeof(Date), "date")] +[JsonDerivedType(typeof(Map), "map")] +[JsonDerivedType(typeof(Object), "object")] +[JsonDerivedType(typeof(RegExp), "regexp")] +[JsonDerivedType(typeof(Set), "set")] public abstract record LocalValue { - public static implicit operator LocalValue(int value) { return new NumberLocalValue(value); } - public static implicit operator LocalValue(string value) { return new StringLocalValue(value); } + public static implicit operator LocalValue(int value) { return new Number(value); } + public static implicit operator LocalValue(string value) { return new String(value); } // TODO: Extend converting from types public static LocalValue ConvertFrom(object? value) @@ -25,7 +25,7 @@ public static LocalValue ConvertFrom(object? value) switch (value) { case null: - return new NullLocalValue(); + return new Null(); case int: return (int)value; case string: @@ -43,41 +43,42 @@ public static LocalValue ConvertFrom(object? value) values.Add([property.Name, ConvertFrom(property.GetValue(value))]); } - return new ObjectLocalValue(values); + return new Object(values); } } } -} -public abstract record PrimitiveProtocolLocalValue : LocalValue -{ + public abstract record PrimitiveProtocolLocalValue : LocalValue + { -} + } -public record NumberLocalValue(long Value) : PrimitiveProtocolLocalValue -{ - public static explicit operator NumberLocalValue(int n) => new NumberLocalValue(n); -} + public record Number(long Value) : PrimitiveProtocolLocalValue + { + public static explicit operator Number(int n) => new Number(n); + } -public record StringLocalValue(string Value) : PrimitiveProtocolLocalValue; + public record String(string Value) : PrimitiveProtocolLocalValue; -public record NullLocalValue : PrimitiveProtocolLocalValue; + public record Null : PrimitiveProtocolLocalValue; -public record UndefinedLocalValue : PrimitiveProtocolLocalValue; + public record Undefined : PrimitiveProtocolLocalValue; -public record ArrayLocalValue(IEnumerable Value) : LocalValue; + public record Array(IEnumerable Value) : LocalValue; -public record DateLocalValue(string Value) : LocalValue; + public record Date(string Value) : LocalValue; -public record MapLocalValue(IDictionary Value) : LocalValue; // seems to implement IDictionary + public record Map(IDictionary Value) : LocalValue; // seems to implement IDictionary -public record ObjectLocalValue(IEnumerable> Value) : LocalValue; + public record Object(IEnumerable> Value) : LocalValue; -public record RegExpLocalValue(RegExpValue Value) : LocalValue; + public record RegExp(RegExp.RegExpValue Value) : LocalValue + { + public record RegExpValue(string Pattern) + { + public string? Flags { get; set; } + } + } -public record RegExpValue(string Pattern) -{ - public string? Flags { get; set; } + public record Set(IEnumerable Value) : LocalValue; } - -public record SetLocalValue(IEnumerable Value) : LocalValue; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs b/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs index 87bf2680efa6f..dd695a171128b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs @@ -9,7 +9,7 @@ public record NodeProperties(long NodeType, long ChildNodeCount) public IReadOnlyDictionary? Attributes { get; internal set; } [JsonInclude] - public IReadOnlyList? Children { get; internal set; } + public IReadOnlyList? Children { get; internal set; } [JsonInclude] public string? LocalName { get; internal set; } @@ -24,5 +24,5 @@ public record NodeProperties(long NodeType, long ChildNodeCount) public string? NodeValue { get; internal set; } [JsonInclude] - public NodeRemoteValue? ShadowRoot { get; internal set; } + public RemoteValue.Node? ShadowRoot { get; internal set; } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs index 4d88aa5e7b25c..d4844bfb1a881 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs @@ -4,33 +4,34 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(WindowRealmInfo), "window")] -//[JsonDerivedType(typeof(DedicatedWorkerRealmInfo), "dedicated-worker")] -//[JsonDerivedType(typeof(SharedWorkerRealmInfo), "shared-worker")] -//[JsonDerivedType(typeof(ServiceWorkerRealmInfo), "service-worker")] -//[JsonDerivedType(typeof(WorkerRealmInfo), "worker")] -//[JsonDerivedType(typeof(PaintWorkletRealmInfo), "paint-worklet")] -//[JsonDerivedType(typeof(AudioWorkletRealmInfo), "audio-worklet")] -//[JsonDerivedType(typeof(WorkletRealmInfo), "worklet")] +//[JsonDerivedType(typeof(Window), "window")] +//[JsonDerivedType(typeof(DedicatedWorker), "dedicated-worker")] +//[JsonDerivedType(typeof(SharedWorker), "shared-worker")] +//[JsonDerivedType(typeof(ServiceWorker), "service-worker")] +//[JsonDerivedType(typeof(Worker), "worker")] +//[JsonDerivedType(typeof(PaintWorklet), "paint-worklet")] +//[JsonDerivedType(typeof(AudioWorklet), "audio-worklet")] +//[JsonDerivedType(typeof(Worklet), "worklet")] public abstract record RealmInfo(BiDi BiDi) : EventArgs(BiDi); -public abstract record BaseRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi); - -public record WindowRealmInfo(BiDi BiDi, Realm Realm, string Origin, BrowsingContext.BrowsingContext Context) : BaseRealmInfo(BiDi, Realm, Origin) +public abstract record BaseRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi) { - public string? Sandbox { get; set; } -} + public record Window(BiDi BiDi, Realm Realm, string Origin, BrowsingContext.BrowsingContext Context) : BaseRealmInfo(BiDi, Realm, Origin) + { + public string? Sandbox { get; set; } + } -public record DedicatedWorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin, IReadOnlyList Owners) : BaseRealmInfo(BiDi, Realm, Origin); + public record DedicatedWorker(BiDi BiDi, Realm Realm, string Origin, IReadOnlyList Owners) : BaseRealmInfo(BiDi, Realm, Origin); -public record SharedWorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record SharedWorker(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); -public record ServiceWorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record ServiceWorker(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); -public record WorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record Worker(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); -public record PaintWorkletRealmInfo(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record PaintWorklet(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); -public record AudioWorkletRealmInfo(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record AudioWorklet(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); -public record WorkletRealmInfo(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record Worklet(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index 0ce3be3404fa5..c3bef4971cf37 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -6,39 +6,39 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(NumberRemoteValue), "number")] -//[JsonDerivedType(typeof(StringRemoteValue), "string")] -//[JsonDerivedType(typeof(NullRemoteValue), "null")] -//[JsonDerivedType(typeof(UndefinedRemoteValue), "undefined")] -//[JsonDerivedType(typeof(SymbolRemoteValue), "symbol")] -//[JsonDerivedType(typeof(ObjectRemoteValue), "object")] -//[JsonDerivedType(typeof(FunctionRemoteValue), "function")] -//[JsonDerivedType(typeof(RegExpRemoteValue), "regexp")] -//[JsonDerivedType(typeof(DateRemoteValue), "date")] -//[JsonDerivedType(typeof(MapRemoteValue), "map")] -//[JsonDerivedType(typeof(SetRemoteValue), "set")] -//[JsonDerivedType(typeof(WeakMapRemoteValue), "weakmap")] -//[JsonDerivedType(typeof(WeakSetRemoteValue), "weakset")] -//[JsonDerivedType(typeof(GeneratorRemoteValue), "generator")] -//[JsonDerivedType(typeof(ErrorRemoteValue), "error")] -//[JsonDerivedType(typeof(ProxyRemoteValue), "proxy")] -//[JsonDerivedType(typeof(PromiseRemoteValue), "promise")] -//[JsonDerivedType(typeof(TypedArrayRemoteValue), "typedarray")] -//[JsonDerivedType(typeof(ArrayBufferRemoteValue), "arraybuffer")] -//[JsonDerivedType(typeof(NodeListRemoteValue), "nodelist")] -//[JsonDerivedType(typeof(HtmlCollectionRemoteValue), "htmlcollection")] -//[JsonDerivedType(typeof(NodeRemoteValue), "node")] -//[JsonDerivedType(typeof(WindowProxyRemoteValue), "window")] +//[JsonDerivedType(typeof(Number), "number")] +//[JsonDerivedType(typeof(String), "string")] +//[JsonDerivedType(typeof(Null), "null")] +//[JsonDerivedType(typeof(Undefined), "undefined")] +//[JsonDerivedType(typeof(Symbol), "symbol")] +//[JsonDerivedType(typeof(Object), "object")] +//[JsonDerivedType(typeof(Function), "function")] +//[JsonDerivedType(typeof(RegExp), "regexp")] +//[JsonDerivedType(typeof(Date), "date")] +//[JsonDerivedType(typeof(Map), "map")] +//[JsonDerivedType(typeof(Set), "set")] +//[JsonDerivedType(typeof(WeakMap), "weakmap")] +//[JsonDerivedType(typeof(WeakSet), "weakset")] +//[JsonDerivedType(typeof(Generator), "generator")] +//[JsonDerivedType(typeof(Error), "error")] +//[JsonDerivedType(typeof(Proxy), "proxy")] +//[JsonDerivedType(typeof(Promise), "promise")] +//[JsonDerivedType(typeof(TypedArray), "typedarray")] +//[JsonDerivedType(typeof(ArrayBuffer), "arraybuffer")] +//[JsonDerivedType(typeof(NodeList), "nodelist")] +//[JsonDerivedType(typeof(HtmlCollection), "htmlcollection")] +//[JsonDerivedType(typeof(Node), "node")] +//[JsonDerivedType(typeof(WindowProxy), "window")] public abstract record RemoteValue { - public static implicit operator int(RemoteValue remoteValue) => (int)((NumberRemoteValue)remoteValue).Value; - public static implicit operator long(RemoteValue remoteValue) => ((NumberRemoteValue)remoteValue).Value; + public static implicit operator int(RemoteValue remoteValue) => (int)((Number)remoteValue).Value; + public static implicit operator long(RemoteValue remoteValue) => ((Number)remoteValue).Value; public static implicit operator string(RemoteValue remoteValue) { return remoteValue switch { - StringRemoteValue stringValue => stringValue.Value, - NullRemoteValue => null!, + String stringValue => stringValue.Value, + Null => null!, _ => throw new BiDiException($"Cannot convert {remoteValue} to string") }; } @@ -50,11 +50,11 @@ public static implicit operator string(RemoteValue remoteValue) if (type == typeof(int)) { - return (TResult)(Convert.ToInt32(((NumberRemoteValue)this).Value) as object); + return (TResult)(Convert.ToInt32(((Number)this).Value) as object); } else if (type == typeof(string)) { - return (TResult)(((StringRemoteValue)this).Value as object); + return (TResult)(((String)this).Value as object); } else if (type is object) { @@ -64,177 +64,182 @@ public static implicit operator string(RemoteValue remoteValue) throw new BiDiException("Cannot convert ....."); } -} -public abstract record PrimitiveProtocolRemoteValue : RemoteValue; + public record Number(long Value) : PrimitiveProtocolRemoteValue; -public record NumberRemoteValue(long Value) : PrimitiveProtocolRemoteValue; + public record String(string Value) : PrimitiveProtocolRemoteValue; -public record StringRemoteValue(string Value) : PrimitiveProtocolRemoteValue; + public record Null : PrimitiveProtocolRemoteValue; -public record NullRemoteValue : PrimitiveProtocolRemoteValue; + public record Undefined : PrimitiveProtocolRemoteValue; -public record UndefinedRemoteValue : PrimitiveProtocolRemoteValue; + public record Symbol : RemoteValue + { + public Handle? Handle { get; set; } -public record SymbolRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } + } - public InternalId? InternalId { get; set; } -} + public record Array : RemoteValue + { + public Handle? Handle { get; set; } -public record ArrayRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } + public IReadOnlyList? Value { get; set; } + } - public IReadOnlyList? Value { get; set; } -} + public record Object : RemoteValue + { + public Handle? Handle { get; set; } -public record ObjectRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } + public IReadOnlyList>? Value { get; set; } + } - public IReadOnlyList>? Value { get; set; } -} + public record Function : RemoteValue + { + public Handle? Handle { get; set; } -public record FunctionRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } + } - public InternalId? InternalId { get; set; } -} + public record RegExp(RegExp.RegExpValue Value) : RemoteValue + { + public Handle? Handle { get; set; } -public record RegExpRemoteValue(RegExpValue Value) : RemoteValue -{ - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } -} + public record RegExpValue(string Pattern) + { + public string? Flags { get; set; } + } + } -public record DateRemoteValue(string Value) : RemoteValue -{ - public Handle? Handle { get; set; } + public record Date(string Value) : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record MapRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record Map : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } - public IDictionary? Value { get; set; } -} + public IDictionary? Value { get; set; } + } -public record SetRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record Set : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } - public IReadOnlyList? Value { get; set; } -} + public IReadOnlyList? Value { get; set; } + } -public record WeakMapRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record WeakMap : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record WeakSetRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record WeakSet : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record GeneratorRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record Generator : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record ErrorRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record Error : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record ProxyRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record Proxy : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record PromiseRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record Promise : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record TypedArrayRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record TypedArray : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record ArrayBufferRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record ArrayBuffer : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } -} + public InternalId? InternalId { get; set; } + } -public record NodeListRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record NodeList : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } - public IReadOnlyList? Value { get; set; } -} + public IReadOnlyList? Value { get; set; } + } -public record HtmlCollectionRemoteValue : RemoteValue -{ - public Handle? Handle { get; set; } + public record HtmlCollection : RemoteValue + { + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } - public IReadOnlyList? Value { get; set; } -} + public IReadOnlyList? Value { get; set; } + } -public record NodeRemoteValue : RemoteValue -{ - [JsonInclude] - public string? SharedId { get; internal set; } + public record Node : RemoteValue + { + [JsonInclude] + public string? SharedId { get; internal set; } - public Handle? Handle { get; set; } + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } - [JsonInclude] - public NodeProperties? Value { get; internal set; } -} + [JsonInclude] + public NodeProperties? Value { get; internal set; } + } -public record WindowProxyRemoteValue(WindowProxyProperties Value) : RemoteValue -{ - public Handle? Handle { get; set; } + public record WindowProxy(WindowProxy.Properties Value) : RemoteValue + { + public Handle? Handle { get; set; } + + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } + public record Properties(BrowsingContext.BrowsingContext Context); + } } -public record WindowProxyProperties(BrowsingContext.BrowsingContext Context); +public abstract record PrimitiveProtocolRemoteValue : RemoteValue; public enum Mode { diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs index 2270835f32639..a4a3dcaef76f7 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs @@ -2,9 +2,9 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; -public class ScriptEvaluateException(EvaluateResultException evaluateResultException) : Exception +public class ScriptEvaluateException(EvaluateResult.Exception evaluateResultException) : Exception { - private readonly EvaluateResultException _evaluateResultException = evaluateResultException; + private readonly EvaluateResult.Exception _evaluateResultException = evaluateResultException; public string Text => _evaluateResultException.ExceptionDetails.Text; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs index b5e8f2ae61b22..f53aaf4f03046 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs @@ -20,12 +20,12 @@ public async Task EvaluateAsync(string expression, bool awaitPromis var result = await Broker.ExecuteCommandAsync(new EvaluateCommand(@params), options).ConfigureAwait(false); - if (result is EvaluateResultException exp) + if (result is EvaluateResult.Exception exp) { throw new ScriptEvaluateException(exp); } - return ((EvaluateResultSuccess)result).Result; + return ((EvaluateResult.Success)result).Result; } public async Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, Target target, CallFunctionOptions? options = null) @@ -43,12 +43,12 @@ public async Task CallFunctionAsync(string functionDeclaration, boo var result = await Broker.ExecuteCommandAsync(new CallFunctionCommand(@params), options).ConfigureAwait(false); - if (result is EvaluateResultException exp) + if (result is EvaluateResult.Exception exp) { throw new ScriptEvaluateException(exp); } - return ((EvaluateResultSuccess)result).Result; + return ((EvaluateResult.Success)result).Result; } public async Task> GetRealmsAsync(GetRealmsOptions? options = null) diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs index 7c20cb8b33b6f..efbb1191fe7ab 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs @@ -2,15 +2,23 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; -[JsonDerivedType(typeof(RealmTarget))] -[JsonDerivedType(typeof(ContextTarget))] -public abstract record Target; +[JsonDerivedType(typeof(Realm))] +[JsonDerivedType(typeof(Context))] +public abstract record Target +{ + public record Realm(Script.Realm Target) : Target + { + [JsonPropertyName("realm")] + public Script.Realm Target { get; } = Target; + } -public record RealmTarget(Realm Realm) : Target; + public record Context(BrowsingContext.BrowsingContext Target) : Target + { + [JsonPropertyName("context")] + public BrowsingContext.BrowsingContext Target { get; } = Target; -public record ContextTarget(BrowsingContext.BrowsingContext Context) : Target -{ - public string? Sandbox { get; set; } + public string? Sandbox { get; set; } + } } public class ContextTargetOptions diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs b/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs index 171dbb0ec8c2b..dee625079b837 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs @@ -3,30 +3,31 @@ namespace OpenQA.Selenium.BiDi.Modules.Session; [JsonPolymorphic(TypeDiscriminatorPropertyName = "proxyType")] -[JsonDerivedType(typeof(AutodetectProxyConfiguration), "autodetect")] -[JsonDerivedType(typeof(DirectProxyConfiguration), "direct")] -[JsonDerivedType(typeof(ManualProxyConfiguration), "manual")] -[JsonDerivedType(typeof(PacProxyConfiguration), "pac")] -[JsonDerivedType(typeof(SystemProxyConfiguration), "system")] -public abstract record ProxyConfiguration; +[JsonDerivedType(typeof(Autodetect), "autodetect")] +[JsonDerivedType(typeof(Direct), "direct")] +[JsonDerivedType(typeof(Manual), "manual")] +[JsonDerivedType(typeof(Pac), "pac")] +[JsonDerivedType(typeof(System), "system")] +public abstract record ProxyConfiguration +{ + public record Autodetect : ProxyConfiguration; -public record AutodetectProxyConfiguration : ProxyConfiguration; + public record Direct : ProxyConfiguration; -public record DirectProxyConfiguration : ProxyConfiguration; + public record Manual : ProxyConfiguration + { + public string? FtpProxy { get; set; } -public record ManualProxyConfiguration : ProxyConfiguration -{ - public string? FtpProxy { get; set; } + public string? HttpProxy { get; set; } - public string? HttpProxy { get; set; } + public string? SslProxy { get; set; } - public string? SslProxy { get; set; } + public string? SocksProxy { get; set; } - public string? SocksProxy { get; set; } + public long? SocksVersion { get; set; } + } - public long? SocksVersion { get; set; } -} + public record Pac(string ProxyAutoconfigUrl) : ProxyConfiguration; -public record PacProxyConfiguration(string ProxyAutoconfigUrl) : ProxyConfiguration; - -public record SystemProxyConfiguration : ProxyConfiguration; + public record System : ProxyConfiguration; +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs index c7c7c2c01dda3..468387760b7a8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs @@ -45,15 +45,20 @@ public class CookieFilter } [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(BrowsingContextPartitionDescriptor), "context")] -[JsonDerivedType(typeof(StorageKeyPartitionDescriptor), "storageKey")] -public abstract record PartitionDescriptor; - -public record BrowsingContextPartitionDescriptor(BrowsingContext.BrowsingContext Context) : PartitionDescriptor; - -public record StorageKeyPartitionDescriptor : PartitionDescriptor +[JsonDerivedType(typeof(Context), "context")] +[JsonDerivedType(typeof(StorageKey), "storageKey")] +public abstract record PartitionDescriptor { - public string? UserContext { get; set; } - - public string? SourceOrigin { get; set; } + public record Context(BrowsingContext.BrowsingContext Descriptor) : PartitionDescriptor + { + [JsonPropertyName("context")] + public BrowsingContext.BrowsingContext Descriptor { get; } = Descriptor; + } + + public record StorageKey : PartitionDescriptor + { + public string? UserContext { get; set; } + + public string? SourceOrigin { get; set; } + } } diff --git a/dotnet/test/common/BiDi/BiDiFixture.cs b/dotnet/test/common/BiDi/BiDiFixture.cs new file mode 100644 index 0000000000000..c45b2689f3d61 --- /dev/null +++ b/dotnet/test/common/BiDi/BiDiFixture.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.BrowsingContext; +using OpenQA.Selenium.Environment; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi; + +class BiDiFixture : DriverTestFixture +{ + protected BiDi bidi; + protected BrowsingContext context; + + protected UrlBuilder UrlBuilder { get; } = EnvironmentManager.Instance.UrlBuilder; + + [OneTimeSetUp] + public async Task BiDiSetUp() + { + context = await driver.AsBiDiContextAsync(); + bidi = context.BiDi; + } +} diff --git a/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs b/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs new file mode 100644 index 0000000000000..66e4bc3d1c1ca --- /dev/null +++ b/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs @@ -0,0 +1,305 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.BrowsingContext; +using System.Linq; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Modules; + +class BrowsingContextTest : BiDiFixture +{ + [Test] + public async Task CanCreateNewTab() + { + var tab = await bidi.BrowsingContext.CreateAsync(ContextType.Tab); + + Assert.That(tab, Is.Not.Null); + } + + [Test] + public async Task CanCreateNewTabWithReferencedContext() + { + var tab = await bidi.BrowsingContext.CreateAsync(ContextType.Tab, new() + { + ReferenceContext = context + }); + + Assert.That(tab, Is.Not.Null); + } + + [Test] + public async Task CanCreateNewWindow() + { + var window = await bidi.BrowsingContext.CreateAsync(ContextType.Window); + + Assert.That(window, Is.Not.Null); + } + + [Test] + public async Task CanCreateNewWindowWithReferencedContext() + { + var window = await bidi.BrowsingContext.CreateAsync(ContextType.Window, new() + { + ReferenceContext = context + }); + + Assert.That(window, Is.Not.Null); + } + + [Test] + public async Task CanCreateContextWithAllParameters() + { + var userContext = await bidi.Browser.CreateUserContextAsync(); + + var window = await bidi.BrowsingContext.CreateAsync(ContextType.Window, new() + { + ReferenceContext = context, + UserContext = userContext.UserContext, + Background = true + }); + + Assert.That(window, Is.Not.Null); + } + + [Test] + public async Task CanNavigateToUrl() + { + var info = await context.NavigateAsync(UrlBuilder.WhereIs("/bidi/logEntryAdded.html")); + + Assert.That(info.Url, Does.Contain("/bidi/logEntryAdded.html")); + } + + [Test] + public async Task CanNavigateToUrlWithReadinessState() + { + var info = await context.NavigateAsync(UrlBuilder.WhereIs("/bidi/logEntryAdded.html"), new() + { + Wait = ReadinessState.Complete + }); + + Assert.That(info, Is.Not.Null); + Assert.That(info.Url, Does.Contain("/bidi/logEntryAdded.html")); + } + + [Test] + public async Task CanGetTreeWithChild() + { + await context.NavigateAsync(UrlBuilder.WhereIs("iframes.html"), new() { Wait = ReadinessState.Complete }); + + var tree = await context.GetTreeAsync(); + + Assert.That(tree, Has.Count.EqualTo(1)); + Assert.That(tree[0].Context, Is.EqualTo(context)); + Assert.That(tree[0].Children, Has.Count.EqualTo(1)); + Assert.That(tree[0].Children[0].Url, Does.Contain("formPage.html")); + } + + [Test] + public async Task CanGetTreeWithDepth() + { + await context.NavigateAsync(UrlBuilder.WhereIs("iframes.html"), new() { Wait = ReadinessState.Complete }); + + var tree = await context.GetTreeAsync(new() { MaxDepth = 0 }); + + Assert.That(tree, Has.Count.EqualTo(1)); + Assert.That(tree[0].Context, Is.EqualTo(context)); + Assert.That(tree[0].Children, Is.Null); + } + + [Test] + public async Task CanGetTreeTopLevel() + { + var window1 = await bidi.BrowsingContext.CreateAsync(ContextType.Window); + var window2 = await bidi.BrowsingContext.CreateAsync(ContextType.Window); + + var tree = await bidi.BrowsingContext.GetTreeAsync(); + + Assert.That(tree, Has.Count.GreaterThanOrEqualTo(2)); + } + + [Test] + public async Task CanCloseWindow() + { + var window = await bidi.BrowsingContext.CreateAsync(ContextType.Window); + + await window.CloseAsync(); + + var tree = await bidi.BrowsingContext.GetTreeAsync(); + + Assert.That(tree.Select(i => i.Context), Does.Not.Contain(window)); + } + + [Test] + public async Task CanCloseTab() + { + var tab = await bidi.BrowsingContext.CreateAsync(ContextType.Tab); + + await tab.CloseAsync(); + + var tree = await bidi.BrowsingContext.GetTreeAsync(); + + Assert.That(tree.Select(i => i.Context), Does.Not.Contain(tab)); + } + + [Test] + public async Task CanActivate() + { + await context.ActivateAsync(); + + // TODO: Add assertion when https://w3c.github.io/webdriver-bidi/#type-browser-ClientWindowInfo is implemented + } + + [Test] + public async Task CanReload() + { + string url = UrlBuilder.WhereIs("/bidi/logEntryAdded.html"); + + await context.NavigateAsync(url, new() { Wait = ReadinessState.Complete }); + + var info = await context.ReloadAsync(); + + Assert.That(info, Is.Not.Null); + Assert.That(info.Url, Does.Contain("/bidi/logEntryAdded.html")); + } + + [Test] + public async Task CanReloadWithReadinessState() + { + string url = UrlBuilder.WhereIs("/bidi/logEntryAdded.html"); + + await context.NavigateAsync(url, new() { Wait = ReadinessState.Complete }); + + var info = await context.ReloadAsync(new() + { + Wait = ReadinessState.Complete, + IgnoreCache = true + }); + + Assert.That(info, Is.Not.Null); + Assert.That(info.Url, Does.Contain("/bidi/logEntryAdded.html")); + } + + [Test] + public async Task CanHandleUserPrompt() + { + await context.NavigateAsync(alertsPage); + + driver.FindElement(By.Id("alert")).Click(); + WaitFor(() => driver.SwitchTo().Alert(), "No alert"); + + await context.HandleUserPromptAsync(); + } + + [Test] + public async Task CanAcceptUserPrompt() + { + await context.NavigateAsync(alertsPage); + + driver.FindElement(By.Id("alert")).Click(); + WaitFor(() => driver.SwitchTo().Alert(), "No alert"); + + await context.HandleUserPromptAsync(new() + { + Accept = true + }); + } + + [Test] + public async Task CanDismissUserPrompt() + { + await context.NavigateAsync(alertsPage); + + driver.FindElement(By.Id("alert")).Click(); + WaitFor(() => driver.SwitchTo().Alert(), "No alert"); + + await context.HandleUserPromptAsync(new() + { + Accept = false + }); + } + + [Test] + public async Task CanPassUserTextToPrompt() + { + await context.NavigateAsync(alertsPage); + + driver.FindElement(By.Id("alert")).Click(); + WaitFor(() => driver.SwitchTo().Alert(), "No alert"); + + await context.HandleUserPromptAsync(new() + { + UserText = "Selenium automates browsers" + }); + } + + [Test] + public async Task CanCaptureScreenshot() + { + var screenshot = await context.CaptureScreenshotAsync(); + + Assert.That(screenshot, Is.Not.Null); + Assert.That(screenshot.Data, Is.Not.Empty); + } + + [Test] + public async Task CanCaptureScreenshotWithParameters() + { + var screenshot = await context.CaptureScreenshotAsync(new() + { + Origin = Origin.Document, + Clip = new ClipRectangle.Box(5, 5, 10, 10) + }); + + Assert.That(screenshot, Is.Not.Null); + Assert.That(screenshot.Data, Is.Not.Empty); + } + + [Test] + public async Task CanCaptureScreenshotOfViewport() + { + var screenshot = await context.CaptureScreenshotAsync(new() + { + Origin = Origin.Viewport, + Clip = new ClipRectangle.Box(5, 5, 10, 10) + }); + + Assert.That(screenshot, Is.Not.Null); + Assert.That(screenshot.Data, Is.Not.Empty); + } + + [Test] + public async Task CanCaptureScreenshotOfElement() + { + await context.NavigateAsync(UrlBuilder.WhereIs("formPage.html"), new() { Wait = ReadinessState.Complete }); + + var elements = await context.LocateNodesAsync(new Locator.Css("#checky")); + + var screenshot = await context.CaptureScreenshotAsync(new() + { + Clip = new ClipRectangle.Element(new Script.SharedReference(elements[0].SharedId)) + }); + + Assert.That(screenshot, Is.Not.Null); + Assert.That(screenshot.Data, Is.Not.Empty); + } + + [Test] + public async Task CanSetViewport() + { + await context.SetViewportAsync(new() { Viewport = new(250, 300) }); + } + + [Test] + public async Task CanSetViewportWithDevicePixelRatio() + { + await context.SetViewportAsync(new() { Viewport = new(250, 300), DevicePixelRatio = 5 }); + } + + [Test] + public async Task CanPrintPage() + { + var pdf = await context.PrintAsync(); + + Assert.That(pdf, Is.Not.Null); + Assert.That(pdf.Data, Is.Not.Empty); + } +} diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Modules/NetworkTest.cs new file mode 100644 index 0000000000000..f09ba79cc7bdc --- /dev/null +++ b/dotnet/test/common/BiDi/Modules/NetworkTest.cs @@ -0,0 +1,21 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Network; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Modules; + +class NetworkTest : BiDiFixture +{ + [Test] + public async Task CanListenRequests() + { + IList requests = []; + + await bidi.Network.OnBeforeRequestSentAsync(requests.Add); + + await context.NavigateAsync("https://selenium.dev", new() { Wait = BrowsingContext.ReadinessState.Complete }); + + Assert.That(requests, Is.Not.Empty); + } +} diff --git a/dotnet/test/common/Environment/DriverFactory.cs b/dotnet/test/common/Environment/DriverFactory.cs index 8ce615235dc7d..ef807c0f25427 100644 --- a/dotnet/test/common/Environment/DriverFactory.cs +++ b/dotnet/test/common/Environment/DriverFactory.cs @@ -67,12 +67,11 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO { browser = Browser.Chrome; options = GetDriverOptions(driverType, driverOptions); - // Disabling this since we do not have any BiDi tests currently. - //options.UseWebSocketUrl = true; + options.UseWebSocketUrl = true; // If BiDi is enabled above then the undhandler prompt behaviour needs to set accordingly. // Reasoning : https://github.com/SeleniumHQ/selenium/pull/14429#issuecomment-2311614822 - //options.UnhandledPromptBehavior = UnhandledPromptBehavior.Ignore; + options.UnhandledPromptBehavior = UnhandledPromptBehavior.Ignore; var chromeOptions = (ChromeOptions)options; chromeOptions.AddArguments("--no-sandbox", "--disable-dev-shm-usage"); From f6eb03d216fb6e7f3d8e4fa4e0f0d7dd6250acf8 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:16:07 +0300 Subject: [PATCH 02/60] Auth --- .../Network/ContinueWithAuthCommand.cs | 25 +++++++++++-------- .../BiDi/Modules/Network/NetworkModule.cs | 6 ++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs index 4c6553181da92..f592c399d7404 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs @@ -6,16 +6,21 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; internal class ContinueWithAuthCommand(ContinueWithAuthParameters @params) : Command(@params); [JsonPolymorphic(TypeDiscriminatorPropertyName = "action")] -[JsonDerivedType(typeof(ContinueWithAuthCredentials), "provideCredentials")] -[JsonDerivedType(typeof(ContinueWithDefaultAuth), "default")] -[JsonDerivedType(typeof(ContinueWithCancelledAuth), "cancel")] -internal abstract record ContinueWithAuthParameters(Request Request) : CommandParameters; - -internal record ContinueWithAuthCredentials(Request Request, AuthCredentials Credentials) : ContinueWithAuthParameters(Request); - -internal record ContinueWithDefaultAuth(Request Request) : ContinueWithAuthParameters(Request); - -internal record ContinueWithCancelledAuth(Request Request) : ContinueWithAuthParameters(Request); +[JsonDerivedType(typeof(Credentials), "provideCredentials")] +[JsonDerivedType(typeof(Default), "default")] +[JsonDerivedType(typeof(Cancel), "cancel")] +internal abstract record ContinueWithAuthParameters(Request Request) : CommandParameters +{ + internal record Credentials(Request Request, AuthCredentials AuthCredentials) : ContinueWithAuthParameters(Request) + { + [JsonPropertyName("credentials")] + public AuthCredentials AuthCredentials { get; } = AuthCredentials; + } + + internal record Default(Request Request) : ContinueWithAuthParameters(Request); + + internal record Cancel(Request Request) : ContinueWithAuthParameters(Request); +} public record ContinueWithAuthOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs index 65264dbf51a67..85cb0b2e28cd8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs @@ -113,17 +113,17 @@ internal async Task ProvideResponseAsync(Request request, ProvideResponseOptions internal async Task ContinueWithAuthAsync(Request request, AuthCredentials credentials, ContinueWithAuthOptions? options = null) { - await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthCredentials(request, credentials)), options).ConfigureAwait(false); + await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthParameters.Credentials(request, credentials)), options).ConfigureAwait(false); } internal async Task ContinueWithAuthAsync(Request request, ContinueWithDefaultAuthOptions? options = null) { - await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithDefaultAuth(request)), options).ConfigureAwait(false); + await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthParameters.Default(request)), options).ConfigureAwait(false); } internal async Task ContinueWithAuthAsync(Request request, ContinueWithCancelledAuthOptions? options = null) { - await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithCancelledAuth(request)), options).ConfigureAwait(false); + await Broker.ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthParameters.Cancel(request)), options).ConfigureAwait(false); } public async Task OnBeforeRequestSentAsync(Func handler, SubscriptionOptions? options = null) From 2c32a8ed7b6dffc120fb7cc94df9883d2dcc9563 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:31:19 +0300 Subject: [PATCH 03/60] Log tests --- .../Polymorphic/LogEntryConverter.cs | 10 +-- .../BrowsingContextLogModule.cs | 4 +- .../Modules/Log/{LogEntry.cs => Entry.cs} | 8 +- .../webdriver/BiDi/Modules/Log/LogModule.cs | 4 +- dotnet/test/common/BiDi/BiDiFixture.cs | 11 ++- dotnet/test/common/BiDi/Modules/LogTest.cs | 75 +++++++++++++++++++ .../test/common/BiDi/Modules/NetworkTest.cs | 10 ++- 7 files changed, 108 insertions(+), 14 deletions(-) rename dotnet/src/webdriver/BiDi/Modules/Log/{LogEntry.cs => Entry.cs} (71%) create mode 100644 dotnet/test/common/BiDi/Modules/LogTest.cs 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 13a388bb97ff1..edcfd2446b691 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs @@ -6,21 +6,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 BaseLogEntry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override Modules.Log.Entry? 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, BaseLogEntry value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, Modules.Log.Entry 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 03187efd7265c..d95422f0c04e8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs @@ -6,7 +6,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 => { @@ -17,7 +17,7 @@ public Task OnEntryAddedAsync(Func handler, Su }, 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/LogEntry.cs b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs similarity index 71% rename from dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs rename to dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs index 8233c33629ab0..3cfbb52857641 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs @@ -7,14 +7,16 @@ namespace OpenQA.Selenium.BiDi.Modules.Log; //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] //[JsonDerivedType(typeof(Console), "console")] //[JsonDerivedType(typeof(Javascript), "javascript")] -public abstract record BaseLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) +public abstract record Entry(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) - : BaseLogEntry(BiDi, Level, Source, Text, Timestamp); + : Entry(BiDi, Level, Source, Text, Timestamp); public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp) - : BaseLogEntry(BiDi, Level, Source, Text, Timestamp); + : Entry(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 7bf84d530126a..1e89279912ea1 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs @@ -6,12 +6,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/BiDiFixture.cs b/dotnet/test/common/BiDi/BiDiFixture.cs index c45b2689f3d61..475ced72501cb 100644 --- a/dotnet/test/common/BiDi/BiDiFixture.cs +++ b/dotnet/test/common/BiDi/BiDiFixture.cs @@ -12,10 +12,19 @@ class BiDiFixture : DriverTestFixture protected UrlBuilder UrlBuilder { get; } = EnvironmentManager.Instance.UrlBuilder; - [OneTimeSetUp] + [SetUp] public async Task BiDiSetUp() { context = await driver.AsBiDiContextAsync(); bidi = context.BiDi; } + + [TearDown] + public async Task BiDiTearDown() + { + if (bidi is not null) + { + await bidi.DisposeAsync(); + } + } } diff --git a/dotnet/test/common/BiDi/Modules/LogTest.cs b/dotnet/test/common/BiDi/Modules/LogTest.cs new file mode 100644 index 0000000000000..5f2c75decea9d --- /dev/null +++ b/dotnet/test/common/BiDi/Modules/LogTest.cs @@ -0,0 +1,75 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Log; +using System; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Modules; + +class LogTest : BiDiFixture +{ + [Test] + public async Task CanListenToConsoleLog() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await context.Log.OnEntryAddedAsync(tcs.SetResult); + + driver.Url = UrlBuilder.WhereIs("bidi/logEntryAdded.html"); + driver.FindElement(By.Id("consoleLog")).Click(); + + var logEntry = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(logEntry, Is.Not.Null); + Assert.That(logEntry.Source, Is.Not.Null); + Assert.That(logEntry.Source.Context, Is.EqualTo(context)); + 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()); + + var consoleLogEntry = logEntry as Entry.Console; + + Assert.That(consoleLogEntry.Method, Is.EqualTo("log")); + + Assert.That(consoleLogEntry.Args, Is.Not.Null); + Assert.That(consoleLogEntry.Args, Has.Count.EqualTo(1)); + Assert.That(consoleLogEntry.Args[0], Is.AssignableFrom()); + } + + [Test] + public async Task CanListenToJavascriptLog() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await context.Log.OnEntryAddedAsync(tcs.SetResult); + + driver.Url = UrlBuilder.WhereIs("bidi/logEntryAdded.html"); + driver.FindElement(By.Id("jsException")).Click(); + + var logEntry = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(logEntry, Is.Not.Null); + Assert.That(logEntry.Source, Is.Not.Null); + Assert.That(logEntry.Source.Context, Is.EqualTo(context)); + 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()); + } + + [Test] + public async Task CanRetrieveStacktrace() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await bidi.Log.OnEntryAddedAsync(tcs.SetResult); + + driver.Url = UrlBuilder.WhereIs("bidi/logEntryAdded.html"); + driver.FindElement(By.Id("logWithStacktrace")).Click(); + + var logEntry = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(logEntry, Is.Not.Null); + Assert.That(logEntry.StackTrace, Is.Not.Null); + } +} diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Modules/NetworkTest.cs index f09ba79cc7bdc..aa49d27faf53d 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Modules/NetworkTest.cs @@ -12,10 +12,18 @@ public async Task CanListenRequests() { IList requests = []; - await bidi.Network.OnBeforeRequestSentAsync(requests.Add); + await using var subscription = await bidi.Network.OnBeforeRequestSentAsync(requests.Add); await context.NavigateAsync("https://selenium.dev", new() { Wait = BrowsingContext.ReadinessState.Complete }); Assert.That(requests, Is.Not.Empty); } + + [Test] + public async Task Intercept() + { + await using var intercept = await bidi.Network.InterceptRequestAsync(async e => await e.Request.Request.ContinueAsync()); + + await context.NavigateAsync("https://selenium.dev", new() { Wait = BrowsingContext.ReadinessState.Complete }); + } } From 27583a2924dd21b0eaa54bbafbbcc33caa1cb4ff Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:34:35 +0300 Subject: [PATCH 04/60] Auth tests --- .../BrowsingContextNetworkModule.cs | 2 +- .../BiDi/Modules/Network/NetworkModule.cs | 2 +- .../test/common/BiDi/Modules/NetworkTest.cs | 152 ++++++++++++++++-- 3 files changed, 145 insertions(+), 11 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs index 4b4d805eb3041..e781c67795fcd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs @@ -34,7 +34,7 @@ public async Task InterceptResponseAsync(Func InterceptAuthenticationAsync(Func handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null) + public async Task InterceptAuthAsync(Func handler, BrowsingContextAddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null) { AddInterceptOptions addInterceptOptions = new(interceptOptions) { diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs index 85cb0b2e28cd8..b42e7d677a7bc 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs @@ -47,7 +47,7 @@ public async Task InterceptResponseAsync(Func InterceptAuthenticationAsync(Func handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null) + public async Task InterceptAuthAsync(Func handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null) { var intercept = await AddInterceptAsync([InterceptPhase.AuthRequired], interceptOptions).ConfigureAwait(false); diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Modules/NetworkTest.cs index aa49d27faf53d..3686320caa4ba 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Modules/NetworkTest.cs @@ -1,6 +1,5 @@ using NUnit.Framework; using OpenQA.Selenium.BiDi.Modules.Network; -using System.Collections.Generic; using System.Threading.Tasks; namespace OpenQA.Selenium.BiDi.Modules; @@ -8,22 +7,157 @@ namespace OpenQA.Selenium.BiDi.Modules; class NetworkTest : BiDiFixture { [Test] - public async Task CanListenRequests() + public async Task CanAddIntercept() { - IList requests = []; + await using var intercept = await bidi.Network.InterceptRequestAsync(e => Task.CompletedTask); - await using var subscription = await bidi.Network.OnBeforeRequestSentAsync(requests.Add); + Assert.That(intercept, Is.Not.Null); + } + + [Test] + public async Task CanContinueRequest() + { + int times = 0; + await using var intercept = await bidi.Network.InterceptRequestAsync(async e => + { + await e.Request.Request.ContinueAsync(); + + times++; + }); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + + Assert.That(intercept, Is.Not.Null); + Assert.That(times, Is.GreaterThan(0)); + } + + [Test] + public async Task CanContinueResponse() + { + int times = 0; + + await using var intercept = await bidi.Network.InterceptResponseAsync(async e => + { + await e.Request.Request.ContinueResponseAsync(); + + times++; + }); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); - await context.NavigateAsync("https://selenium.dev", new() { Wait = BrowsingContext.ReadinessState.Complete }); + Assert.That(intercept, Is.Not.Null); + Assert.That(times, Is.GreaterThan(0)); + } + + [Test] + public async Task CanProvideResponse() + { + int times = 0; + + await using var intercept = await bidi.Network.InterceptRequestAsync(async e => + { + await e.Request.Request.ProvideResponseAsync(); + + times++; + }); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); - Assert.That(requests, Is.Not.Empty); + Assert.That(intercept, Is.Not.Null); + Assert.That(times, Is.GreaterThan(0)); } [Test] - public async Task Intercept() + public async Task CanProvideResponseWithParameters() { - await using var intercept = await bidi.Network.InterceptRequestAsync(async e => await e.Request.Request.ContinueAsync()); + int times = 0; + + await using var intercept = await bidi.Network.InterceptRequestAsync(async e => + { + await e.Request.Request.ProvideResponseAsync(new() { Body = """ + + + Hello + + + + + """ }); + + times++; + }); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + + Assert.That(intercept, Is.Not.Null); + Assert.That(times, Is.GreaterThan(0)); + Assert.That(driver.Title, Is.EqualTo("Hello")); + } + + [Test] + public async Task CanRemoveIntercept() + { + var intercept = await bidi.Network.InterceptRequestAsync(_ => Task.CompletedTask); + + await intercept.RemoveAsync(); + + // or + + intercept = await context.Network.InterceptRequestAsync(_ => Task.CompletedTask); + + await intercept.DisposeAsync(); + } + + [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + public async Task CanContinueWithAuthCredentials() + { + await using var intercept = await bidi.Network.InterceptAuthAsync(async e => + { + //TODO Seems it would be better to have method which takes abstract options + await e.Request.Request.ContinueWithAuthAsync(new AuthCredentials.Basic("test", "test")); + }); + + await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + + Assert.That(driver.FindElement(By.CssSelector("h1")).Text, Is.EqualTo("authorized")); + } + + [Test] + public async Task CanContinueWithDefaultCredentials() + { + await using var intercept = await bidi.Network.InterceptAuthAsync(async e => + { + await e.Request.Request.ContinueWithAuthAsync(new ContinueWithDefaultAuthOptions()); + }); + + var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + + Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_INVALID_AUTH_CREDENTIALS")); + } + + [Test] + public async Task CanContinueWithCanceledCredentials() + { + await using var intercept = await bidi.Network.InterceptAuthAsync(async e => + { + await e.Request.Request.ContinueWithAuthAsync(new ContinueWithCancelledAuthOptions()); + }); + + var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + + Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_HTTP_RESPONSE_CODE_FAILURE")); + } + + [Test] + public async Task CanFailRequest() + { + await using var intercept = await bidi.Network.InterceptRequestAsync(async e => + { + await e.Request.Request.FailAsync(); + }); + + var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); - await context.NavigateAsync("https://selenium.dev", new() { Wait = BrowsingContext.ReadinessState.Complete }); + Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_FAILED")); } } From b4a92c522c6e0e5a4c2f3d3dad4015cd3c819cda Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:52:51 +0300 Subject: [PATCH 05/60] Intercept options --- .../test/common/BiDi/Modules/NetworkTest.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Modules/NetworkTest.cs index 3686320caa4ba..db65d5a25ef4a 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Modules/NetworkTest.cs @@ -14,6 +14,35 @@ public async Task CanAddIntercept() Assert.That(intercept, Is.Not.Null); } + [Test] + public async Task CanAddInterceptStringUrlPattern() + { + await using var intercept = await bidi.Network.InterceptRequestAsync(e => Task.CompletedTask, new() + { + UrlPatterns = [ + new UrlPattern.String("http://localhost:4444/*"), + "http://localhost:4444/*" + ] + }); + + Assert.That(intercept, Is.Not.Null); + } + + [Test] + public async Task CanAddInterceptUrlPattern() + { + await using var intercept = await bidi.Network.InterceptRequestAsync(e => Task.CompletedTask, interceptOptions: new() + { + UrlPatterns = [new UrlPattern.Pattern() + { + Hostname = "localhost", + Protocol = "http" + }] + }); + + Assert.That(intercept, Is.Not.Null); + } + [Test] public async Task CanContinueRequest() { From c52550797d5351b7f2d45c53f67d1b1ae9164c7d Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 19:17:13 +0300 Subject: [PATCH 06/60] Stabilize tests --- .../test/common/BiDi/Modules/BrowsingContextTest.cs | 11 +++++------ dotnet/test/common/BiDi/Modules/NetworkTest.cs | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs b/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs index 66e4bc3d1c1ca..65efef7228d0a 100644 --- a/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs @@ -170,8 +170,7 @@ public async Task CanReloadWithReadinessState() var info = await context.ReloadAsync(new() { - Wait = ReadinessState.Complete, - IgnoreCache = true + Wait = ReadinessState.Complete }); Assert.That(info, Is.Not.Null); @@ -181,7 +180,7 @@ public async Task CanReloadWithReadinessState() [Test] public async Task CanHandleUserPrompt() { - await context.NavigateAsync(alertsPage); + await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); WaitFor(() => driver.SwitchTo().Alert(), "No alert"); @@ -192,7 +191,7 @@ public async Task CanHandleUserPrompt() [Test] public async Task CanAcceptUserPrompt() { - await context.NavigateAsync(alertsPage); + await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); WaitFor(() => driver.SwitchTo().Alert(), "No alert"); @@ -206,7 +205,7 @@ await context.HandleUserPromptAsync(new() [Test] public async Task CanDismissUserPrompt() { - await context.NavigateAsync(alertsPage); + await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); WaitFor(() => driver.SwitchTo().Alert(), "No alert"); @@ -220,7 +219,7 @@ await context.HandleUserPromptAsync(new() [Test] public async Task CanPassUserTextToPrompt() { - await context.NavigateAsync(alertsPage); + await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); WaitFor(() => driver.SwitchTo().Alert(), "No alert"); diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Modules/NetworkTest.cs index db65d5a25ef4a..40932562b66ac 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Modules/NetworkTest.cs @@ -20,8 +20,8 @@ public async Task CanAddInterceptStringUrlPattern() await using var intercept = await bidi.Network.InterceptRequestAsync(e => Task.CompletedTask, new() { UrlPatterns = [ - new UrlPattern.String("http://localhost:4444/*"), - "http://localhost:4444/*" + new UrlPattern.String("http://localhost:4444"), + "http://localhost:4444/" ] }); From c41f5679c478895608c688d2cf1b77089d48825f Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 21:33:03 +0300 Subject: [PATCH 07/60] Finish network tests --- .../BrowsingContextNetworkModule.cs | 7 +- .../BiDi/Modules/Network/NetworkModule.cs | 7 +- .../common/BiDi/Modules/NetworkEventsTest.cs | 131 ++++++++++++++++++ 3 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs index e781c67795fcd..72fd7c2e3daa9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs @@ -88,7 +88,12 @@ public Task OnFetchErrorAsync(Action handler, return networkModule.OnFetchErrorAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }); } - internal Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null) + public Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null) + { + return networkModule.OnAuthRequiredAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }); + } + + public Task OnAuthRequiredAsync(Action handler, SubscriptionOptions? options = null) { return networkModule.OnAuthRequiredAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs index b42e7d677a7bc..3df8b5de3d01b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs @@ -166,7 +166,12 @@ public async Task OnFetchErrorAsync(Action ha return await Broker.SubscribeAsync("network.fetchError", handler, options).ConfigureAwait(false); } - internal async Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null) + public async Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("network.authRequired", handler, options).ConfigureAwait(false); + } + + public async Task OnAuthRequiredAsync(Action handler, SubscriptionOptions? options = null) { return await Broker.SubscribeAsync("network.authRequired", handler, options).ConfigureAwait(false); } diff --git a/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs b/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs new file mode 100644 index 0000000000000..28df5207def70 --- /dev/null +++ b/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs @@ -0,0 +1,131 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Network; +using System; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Modules; + +class NetworkEventsTest : BiDiFixture +{ + [Test] + public async Task CanListenToBeforeRequestSentEvent() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await bidi.Network.OnBeforeRequestSentAsync(tcs.SetResult); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + + var req = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(req.Context, Is.EqualTo(context)); + Assert.That(req.Request, Is.Not.Null); + Assert.That(req.Request.Method, Is.EqualTo("GET")); + Assert.That(req.Request.Url, Does.Contain("bidi/logEntryAdded.html")); + Assert.That(req.Initiator.Type, Is.EqualTo(InitiatorType.Other)); + } + + [Test] + public async Task CanListenToResponseStartedEvent() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await bidi.Network.OnResponseStartedAsync(tcs.SetResult); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + + var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(res.Context, Is.EqualTo(context)); + Assert.That(res.Request, Is.Not.Null); + Assert.That(res.Request.Method, Is.EqualTo("GET")); + Assert.That(res.Request.Url, Does.Contain("bidi/logEntryAdded.html")); + Assert.That(res.Response.Headers, Is.Not.Empty); + Assert.That(res.Response.Status, Is.EqualTo(200)); + } + + [Test] + public async Task CanListenToResponseCompletedEvent() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await bidi.Network.OnResponseCompletedAsync(tcs.SetResult); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + + var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(res.Context, Is.EqualTo(context)); + Assert.That(res.Request, Is.Not.Null); + Assert.That(res.Request.Method, Is.EqualTo("GET")); + Assert.That(res.Request.Url, Does.Contain("bidi/logEntryAdded.html")); + Assert.That(res.Response.Url, Does.Contain("bidi/logEntryAdded.html")); + Assert.That(res.Response.Headers, Is.Not.Empty); + Assert.That(res.Response.Status, Is.EqualTo(200)); + } + + [Test] + public async Task CanListenToBeforeRequestSentEventWithCookie() + { + TaskCompletionSource tcs = new(); + + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + + driver.Manage().Cookies.AddCookie(new("foo", "bar")); + + await using var subscription = await bidi.Network.OnBeforeRequestSentAsync(tcs.SetResult); + + await context.ReloadAsync(); + + var req = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(req.Request.Cookies.Count, Is.EqualTo(1)); + Assert.That(req.Request.Cookies[0].Name, Is.EqualTo("foo")); + Assert.That((req.Request.Cookies[0].Value as BytesValue.String).Value, Is.EqualTo("bar")); + } + + [Test] + [IgnoreBrowser(Selenium.Browser.Chrome)] + [IgnoreBrowser(Selenium.Browser.Edge)] + public async Task CanListenToOnAuthRequiredEvent() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await bidi.Network.OnAuthRequiredAsync(tcs.SetResult); + + driver.Url = UrlBuilder.WhereIs("basicAuth"); + + var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(res.Context, Is.EqualTo(context)); + Assert.That(res.Request, Is.Not.Null); + Assert.That(res.Request.Method, Is.EqualTo("GET")); + Assert.That(res.Request.Url, Does.Contain("basicAuth")); + Assert.That(res.Response.Headers, Is.GreaterThanOrEqualTo(1)); + Assert.That(res.Response.Status, Is.EqualTo(401)); + } + + [Test] + public async Task CanListenToFetchError() + { + TaskCompletionSource tcs = new(); + + await using var subscription = await bidi.Network.OnFetchErrorAsync(tcs.SetResult); + + try + { + await context.NavigateAsync("https://not_a_valid_url.test"); + } + catch (Exception) { } + + var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(res.Context, Is.EqualTo(context)); + Assert.That(res.Request, Is.Not.Null); + Assert.That(res.Request.Method, Is.EqualTo("GET")); + Assert.That(res.Request.Url, Does.Contain("https://not_a_valid_url.test")); + Assert.That(res.Request.Headers.Count, Is.GreaterThanOrEqualTo(1)); + Assert.That(res.Navigation, Is.Not.Null); + Assert.That(res.ErrorText, Does.Contain("net::ERR_NAME_NOT_RESOLVED")); + } +} From f3c93cbdf9bf8991738652167e67ae4fb22c6059 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 21:41:44 +0300 Subject: [PATCH 08/60] Stabilize --- .../common/BiDi/Modules/NetworkEventsTest.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs b/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs index 28df5207def70..5a773492f30f0 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs +++ b/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs @@ -12,9 +12,9 @@ public async Task CanListenToBeforeRequestSentEvent() { TaskCompletionSource tcs = new(); - await using var subscription = await bidi.Network.OnBeforeRequestSentAsync(tcs.SetResult); + await using var subscription = await context.Network.OnBeforeRequestSentAsync(tcs.SetResult); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); var req = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); @@ -30,9 +30,9 @@ public async Task CanListenToResponseStartedEvent() { TaskCompletionSource tcs = new(); - await using var subscription = await bidi.Network.OnResponseStartedAsync(tcs.SetResult); + await using var subscription = await context.Network.OnResponseStartedAsync(tcs.SetResult); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); @@ -49,9 +49,9 @@ public async Task CanListenToResponseCompletedEvent() { TaskCompletionSource tcs = new(); - await using var subscription = await bidi.Network.OnResponseCompletedAsync(tcs.SetResult); + await using var subscription = await context.Network.OnResponseCompletedAsync(tcs.SetResult); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); @@ -69,7 +69,7 @@ public async Task CanListenToBeforeRequestSentEventWithCookie() { TaskCompletionSource tcs = new(); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html")); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); driver.Manage().Cookies.AddCookie(new("foo", "bar")); @@ -91,7 +91,7 @@ public async Task CanListenToOnAuthRequiredEvent() { TaskCompletionSource tcs = new(); - await using var subscription = await bidi.Network.OnAuthRequiredAsync(tcs.SetResult); + await using var subscription = await context.Network.OnAuthRequiredAsync(tcs.SetResult); driver.Url = UrlBuilder.WhereIs("basicAuth"); @@ -110,11 +110,11 @@ public async Task CanListenToFetchError() { TaskCompletionSource tcs = new(); - await using var subscription = await bidi.Network.OnFetchErrorAsync(tcs.SetResult); + await using var subscription = await context.Network.OnFetchErrorAsync(tcs.SetResult); try { - await context.NavigateAsync("https://not_a_valid_url.test"); + await context.NavigateAsync("https://not_a_valid_url.test", new() { Wait = BrowsingContext.ReadinessState.Complete }); } catch (Exception) { } From 0fdd4c49f5998e7d6ed41a4ce65f3931f267cfb7 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 22:00:26 +0300 Subject: [PATCH 09/60] Browser tests --- .../BiDi/Modules/Browser/UserContext.cs | 12 +++++ .../test/common/BiDi/Modules/BrowserTest.cs | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 dotnet/test/common/BiDi/Modules/BrowserTest.cs diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs index 5e8bcd712062a..9a0424dad2e7e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs @@ -24,4 +24,16 @@ public async ValueTask DisposeAsync() { await RemoveAsync().ConfigureAwait(false); } + + public override bool Equals(object? obj) + { + if (obj is UserContext userContextObj) return userContextObj.Id == Id; + + return false; + } + + public override int GetHashCode() + { + return Id.GetHashCode(); + } } diff --git a/dotnet/test/common/BiDi/Modules/BrowserTest.cs b/dotnet/test/common/BiDi/Modules/BrowserTest.cs new file mode 100644 index 0000000000000..ee1b434622f83 --- /dev/null +++ b/dotnet/test/common/BiDi/Modules/BrowserTest.cs @@ -0,0 +1,44 @@ +using NUnit.Framework; +using System.Linq; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Modules; + +class BrowserTest : BiDiFixture +{ + [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + public async Task CanCreateUserContext() + { + var userContext = await bidi.Browser.CreateUserContextAsync(); + + Assert.That(userContext, Is.Not.Null); + } + + [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + public async Task CanGetUserContexts() + { + var userContext1 = await bidi.Browser.CreateUserContextAsync(); + var userContext2 = await bidi.Browser.CreateUserContextAsync(); + + var userContexts = await bidi.Browser.GetUserContextsAsync(); + + Assert.That(userContexts, Is.Not.Null); + Assert.That(userContexts.Count, Is.GreaterThanOrEqualTo(2)); + Assert.That(userContexts, Does.Contain(userContext1)); + Assert.That(userContexts, Does.Contain(userContext2)); + } + + [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + public async Task CanRemoveUserContext() + { + var userContext1 = await bidi.Browser.CreateUserContextAsync(); + var userContext2 = await bidi.Browser.CreateUserContextAsync(); + + await userContext2.UserContext.RemoveAsync(); + + var userContexts = await bidi.Browser.GetUserContextsAsync(); + + Assert.That(userContexts, Does.Contain(userContext1)); + Assert.That(userContexts, Does.Not.Contain(userContext2)); + } +} From e55f10a8d34d9635f2a26aef097045f972a771ff Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 25 Sep 2024 22:22:14 +0300 Subject: [PATCH 10/60] Update InputModule.cs --- dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs index a31b0371dfb4a..2626be49d179f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs @@ -21,6 +21,6 @@ public async Task ReleaseActionsAsync(BrowsingContext.BrowsingContext context, R { var @params = new ReleaseActionsCommandParameters(context); - await Broker.ExecuteCommandAsync(new ReleaseActionsCommand(@params), options); + await Broker.ExecuteCommandAsync(new ReleaseActionsCommand(@params), options).ConfigureAwait(false); } } From 6557ff25ac94642cf30fe6e24fb90b0951e87343 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:27:58 +0300 Subject: [PATCH 11/60] Parallelize --- dotnet/test/common/BiDi/BiDiFixture.cs | 26 ++++++++++++++++++- .../test/common/BiDi/Modules/BrowserTest.cs | 7 +++-- .../BiDi/Modules/BrowsingContextTest.cs | 12 +++------ .../test/common/BiDi/Modules/NetworkTest.cs | 2 +- .../test/common/Environment/DriverFactory.cs | 4 ++- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/dotnet/test/common/BiDi/BiDiFixture.cs b/dotnet/test/common/BiDi/BiDiFixture.cs index 475ced72501cb..abc4634092cdd 100644 --- a/dotnet/test/common/BiDi/BiDiFixture.cs +++ b/dotnet/test/common/BiDi/BiDiFixture.cs @@ -5,8 +5,11 @@ namespace OpenQA.Selenium.BiDi; -class BiDiFixture : DriverTestFixture +[Parallelizable(ParallelScope.All)] +[FixtureLifeCycle(LifeCycle.InstancePerTestCase)] +class BiDiFixture { + protected IWebDriver driver; protected BiDi bidi; protected BrowsingContext context; @@ -15,6 +18,13 @@ class BiDiFixture : DriverTestFixture [SetUp] public async Task BiDiSetUp() { + var options = new BiDiEnabledDriverOptions() + { + UseWebSocketUrl = true, + }; + + driver = EnvironmentManager.Instance.CreateDriverInstance(options); + context = await driver.AsBiDiContextAsync(); bidi = context.BiDi; } @@ -26,5 +36,19 @@ public async Task BiDiTearDown() { await bidi.DisposeAsync(); } + + driver?.Dispose(); + } + + public class BiDiEnabledDriverOptions : DriverOptions + { + public override void AddAdditionalOption(string capabilityName, object capabilityValue) + { + } + + public override ICapabilities ToCapabilities() + { + return null; + } } } diff --git a/dotnet/test/common/BiDi/Modules/BrowserTest.cs b/dotnet/test/common/BiDi/Modules/BrowserTest.cs index ee1b434622f83..9a985bb8d893b 100644 --- a/dotnet/test/common/BiDi/Modules/BrowserTest.cs +++ b/dotnet/test/common/BiDi/Modules/BrowserTest.cs @@ -1,12 +1,11 @@ using NUnit.Framework; -using System.Linq; using System.Threading.Tasks; namespace OpenQA.Selenium.BiDi.Modules; class BrowserTest : BiDiFixture { - [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + [Test] public async Task CanCreateUserContext() { var userContext = await bidi.Browser.CreateUserContextAsync(); @@ -14,7 +13,7 @@ public async Task CanCreateUserContext() Assert.That(userContext, Is.Not.Null); } - [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + [Test] public async Task CanGetUserContexts() { var userContext1 = await bidi.Browser.CreateUserContextAsync(); @@ -28,7 +27,7 @@ public async Task CanGetUserContexts() Assert.That(userContexts, Does.Contain(userContext2)); } - [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + [Test] public async Task CanRemoveUserContext() { var userContext1 = await bidi.Browser.CreateUserContextAsync(); diff --git a/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs b/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs index 65efef7228d0a..c9212f1d9abbb 100644 --- a/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs @@ -180,10 +180,9 @@ public async Task CanReloadWithReadinessState() [Test] public async Task CanHandleUserPrompt() { - await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("alerts.html"), new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); - WaitFor(() => driver.SwitchTo().Alert(), "No alert"); await context.HandleUserPromptAsync(); } @@ -191,10 +190,9 @@ public async Task CanHandleUserPrompt() [Test] public async Task CanAcceptUserPrompt() { - await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("alerts.html"), new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); - WaitFor(() => driver.SwitchTo().Alert(), "No alert"); await context.HandleUserPromptAsync(new() { @@ -205,10 +203,9 @@ await context.HandleUserPromptAsync(new() [Test] public async Task CanDismissUserPrompt() { - await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("alerts.html"), new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); - WaitFor(() => driver.SwitchTo().Alert(), "No alert"); await context.HandleUserPromptAsync(new() { @@ -219,10 +216,9 @@ await context.HandleUserPromptAsync(new() [Test] public async Task CanPassUserTextToPrompt() { - await context.NavigateAsync(alertsPage, new() { Wait = ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("alerts.html"), new() { Wait = ReadinessState.Complete }); driver.FindElement(By.Id("alert")).Click(); - WaitFor(() => driver.SwitchTo().Alert(), "No alert"); await context.HandleUserPromptAsync(new() { diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Modules/NetworkTest.cs index 40932562b66ac..cd41aabbf9615 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Modules/NetworkTest.cs @@ -137,7 +137,7 @@ public async Task CanRemoveIntercept() await intercept.DisposeAsync(); } - [Test, NeedsFreshDriver(IsCreatedAfterTest = true)] + [Test] public async Task CanContinueWithAuthCredentials() { await using var intercept = await bidi.Network.InterceptAuthAsync(async e => diff --git a/dotnet/test/common/Environment/DriverFactory.cs b/dotnet/test/common/Environment/DriverFactory.cs index ef807c0f25427..1451631971997 100644 --- a/dotnet/test/common/Environment/DriverFactory.cs +++ b/dotnet/test/common/Environment/DriverFactory.cs @@ -67,7 +67,7 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO { browser = Browser.Chrome; options = GetDriverOptions(driverType, driverOptions); - options.UseWebSocketUrl = true; + //options.UseWebSocketUrl = true; // If BiDi is enabled above then the undhandler prompt behaviour needs to set accordingly. // Reasoning : https://github.com/SeleniumHQ/selenium/pull/14429#issuecomment-2311614822 @@ -187,6 +187,8 @@ protected void OnDriverLaunching(DriverService service, DriverOptions options) options.ScriptTimeout = overriddenOptions.ScriptTimeout; options.PageLoadTimeout = overriddenOptions.PageLoadTimeout; options.ImplicitWaitTimeout = overriddenOptions.ImplicitWaitTimeout; + + options.UseWebSocketUrl = overriddenOptions.UseWebSocketUrl; } return options; From 5498d8c64511091e26c28d1558864eabdbc87785 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:12:36 +0300 Subject: [PATCH 12/60] Storage tests --- .../BiDi/Modules/Browser/UserContext.cs | 2 +- .../BiDi/Modules/Storage/PartitionKey.cs | 2 +- .../test/common/BiDi/Modules/StorageTest.cs | 161 ++++++++++++++++++ 3 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 dotnet/test/common/BiDi/Modules/StorageTest.cs diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs index 9a0424dad2e7e..49ba71eef3f1d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs @@ -13,7 +13,7 @@ internal UserContext(BiDi bidi, string id) Id = id; } - public string Id { get; } + internal string Id { get; } public Task RemoveAsync() { diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs index 2d9ac37a41a22..fd2798be0ae03 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs @@ -2,7 +2,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Storage; public class PartitionKey { - public string? UserContext { get; set; } + public Browser.UserContext? UserContext { get; set; } public string? SourceOrigin { get; set; } } diff --git a/dotnet/test/common/BiDi/Modules/StorageTest.cs b/dotnet/test/common/BiDi/Modules/StorageTest.cs new file mode 100644 index 0000000000000..ce088adef0404 --- /dev/null +++ b/dotnet/test/common/BiDi/Modules/StorageTest.cs @@ -0,0 +1,161 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Network; +using System; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Modules; + +class StorageTest : BiDiFixture +{ + [Test] + public async Task CanGetCookieByName() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + var cookies = await bidi.Storage.GetCookiesAsync(new() + { + Filter = new() + { + Name = Guid.NewGuid().ToString(), + Value = "set" + } + }); + + Assert.That(cookies, Is.Not.Null); + Assert.That(cookies.Cookies, Is.Empty); + } + + [Test] + public async Task CanGetCookieInDefaultUserContext() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + var userContexts = await bidi.Browser.GetUserContextsAsync(); + + var cookies = await context.Storage.GetCookiesAsync(new() + { + Filter = new() + { + Name = Guid.NewGuid().ToString(), + Value = "set" + } + }); + + Assert.That(cookies, Is.Not.Null); + Assert.That(cookies.Cookies, Is.Empty); + Assert.That(cookies.PartitionKey.UserContext, Is.EqualTo(userContexts[0].UserContext)); + } + + [Test] + public async Task CanAddCookie() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + var partitionKey = await context.Storage.SetCookieAsync(new("fish", "cod", UrlBuilder.HostName)); + + Assert.That(partitionKey, Is.Not.Null); + } + + [Test] + public async Task CanAddAndGetCookie() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + var expiry = DateTime.Now.AddDays(1); + + await context.Storage.SetCookieAsync(new("fish", "cod", UrlBuilder.HostName) + { + Path = "/common/animals", + HttpOnly = true, + Secure = false, + SameSite = SameSite.Lax, + Expiry = expiry + }); + + var cookies = await context.Storage.GetCookiesAsync(); + + Assert.That(cookies, Is.Not.Null); + Assert.That(cookies.Cookies.Count, Is.EqualTo(1)); + + var cookie = cookies.Cookies[0]; + + Assert.That(cookie.Name, Is.EqualTo("fish")); + Assert.That((cookie.Value as BytesValue.String).Value, Is.EqualTo("cod")); + Assert.That(cookie.Path, Is.EqualTo("/common/animals")); + Assert.That(cookie.HttpOnly, Is.True); + Assert.That(cookie.Secure, Is.False); + Assert.That(cookie.SameSite, Is.EqualTo(SameSite.Lax)); + Assert.That(cookie.Size, Is.EqualTo(7)); + // Assert.That(cookie.Expiry, Is.EqualTo(expiry)); // chrome issue + } + + [Test] + public async Task CanGetAllCookies() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + driver.Manage().Cookies.AddCookie(new("key1", "value1")); + driver.Manage().Cookies.AddCookie(new("key2", "value2")); + + var cookies = await bidi.Storage.GetCookiesAsync(); + + Assert.That(cookies, Is.Not.Null); + Assert.That(cookies.Cookies.Count, Is.EqualTo(2)); + Assert.That(cookies.Cookies[0].Name, Is.EqualTo("key1")); + Assert.That(cookies.Cookies[1].Name, Is.EqualTo("key2")); + } + + [Test] + public async Task CanDeleteAllCookies() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + driver.Manage().Cookies.AddCookie(new("key1", "value1")); + driver.Manage().Cookies.AddCookie(new("key2", "value2")); + + var result = await bidi.Storage.DeleteCookiesAsync(); + + Assert.That(result, Is.Not.Null); + + var cookies = await bidi.Storage.GetCookiesAsync(); + + Assert.That(cookies, Is.Not.Null); + Assert.That(cookies.Cookies.Count, Is.EqualTo(0)); + } + + [Test] + public async Task CanDeleteCookieWithName() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + driver.Manage().Cookies.AddCookie(new("key1", "value1")); + driver.Manage().Cookies.AddCookie(new("key2", "value2")); + + var result = await bidi.Storage.DeleteCookiesAsync(new() { Filter = new() { Name = "key1" } }); + + Assert.That(result, Is.Not.Null); + + var cookies = await bidi.Storage.GetCookiesAsync(); + + Assert.That(cookies, Is.Not.Null); + Assert.That(cookies.Cookies.Count, Is.EqualTo(1)); + Assert.That(cookies.Cookies[0].Name, Is.EqualTo("key2")); + } + + [Test] + public async Task AddCookiesWithDifferentPathsThatAreRelatedToOurs() + { + driver.Url = UrlBuilder.WhereIs("animals"); + + await context.Storage.SetCookieAsync(new("fish", "cod", UrlBuilder.HostName) + { + Path = "/common/animals" + }); + + driver.Url = UrlBuilder.WhereIs("simpleTest"); + + var result = driver.Manage().Cookies.AllCookies; + + Assert.That(result, Is.Empty); + } +} From b8be96d667f754a59ffba89898137133fa5b541a Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:17:38 +0300 Subject: [PATCH 13/60] Stabilize --- dotnet/test/common/BiDi/Modules/NetworkTest.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Modules/NetworkTest.cs index cd41aabbf9615..65ac70b35d94d 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Modules/NetworkTest.cs @@ -49,9 +49,9 @@ public async Task CanContinueRequest() int times = 0; await using var intercept = await bidi.Network.InterceptRequestAsync(async e => { - await e.Request.Request.ContinueAsync(); - times++; + + await e.Request.Request.ContinueAsync(); }); await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); @@ -67,9 +67,9 @@ public async Task CanContinueResponse() await using var intercept = await bidi.Network.InterceptResponseAsync(async e => { - await e.Request.Request.ContinueResponseAsync(); - times++; + + await e.Request.Request.ContinueResponseAsync(); }); await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); @@ -85,9 +85,9 @@ public async Task CanProvideResponse() await using var intercept = await bidi.Network.InterceptRequestAsync(async e => { - await e.Request.Request.ProvideResponseAsync(); - times++; + + await e.Request.Request.ProvideResponseAsync(); }); await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); @@ -103,6 +103,8 @@ public async Task CanProvideResponseWithParameters() await using var intercept = await bidi.Network.InterceptRequestAsync(async e => { + times++; + await e.Request.Request.ProvideResponseAsync(new() { Body = """ @@ -112,8 +114,6 @@ await e.Request.Request.ProvideResponseAsync(new() { Body = """ """ }); - - times++; }); await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); From 25f1c799c26a86eb66bb159a81a6060d6025ffc1 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:08:39 +0300 Subject: [PATCH 14/60] Enumerable cookies --- .../webdriver/BiDi/Communication/Broker.cs | 3 +++ .../Enumerable/GetCookiesResultConverter.cs | 25 +++++++++++++++++++ .../BiDi/Modules/Storage/GetCookiesCommand.cs | 22 +++++++++++++++- .../test/common/BiDi/Modules/StorageTest.cs | 20 +++++++-------- 4 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 82549d1d5c5b1..2f933fff0dbae 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -68,6 +68,9 @@ public Broker(BiDi bidi, ITransport transport) new Json.Converters.Polymorphic.RealmInfoConverter(), new Json.Converters.Polymorphic.LogEntryConverter(), // + + // Enumerable + new Json.Converters.Enumerable.GetCookiesResultConverter(), } }; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs new file mode 100644 index 0000000000000..c50b3b9c0f268 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs @@ -0,0 +1,25 @@ +using OpenQA.Selenium.BiDi.Modules.Storage; +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable +{ + internal class GetCookiesResultConverter : JsonConverter + { + public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var doc = JsonDocument.ParseValue(ref reader); + var cookies = doc.RootElement.GetProperty("cookies").Deserialize>(options); + var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize(options); + + return new GetCookiesResult(cookies, partitionKey); + } + + public override void Write(Utf8JsonWriter writer, GetCookiesResult value, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs index 468387760b7a8..cd9e6441bbba9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs @@ -1,5 +1,6 @@ using OpenQA.Selenium.BiDi.Communication; using System; +using System.Collections; using System.Collections.Generic; using System.Text.Json.Serialization; @@ -21,7 +22,26 @@ public record GetCookiesOptions : CommandOptions public PartitionDescriptor? Partition { get; set; } } -public record GetCookiesResult(IReadOnlyList Cookies, PartitionKey PartitionKey); +public record GetCookiesResult : IReadOnlyList +{ + private readonly IReadOnlyList _cookies; + + internal GetCookiesResult(IReadOnlyList cookies, PartitionKey partitionKey) + { + _cookies = cookies; + PartitionKey = partitionKey; + } + + public PartitionKey PartitionKey { get; init; } + + public Network.Cookie this[int index] => _cookies[index]; + + public int Count => _cookies.Count; + + public IEnumerator GetEnumerator() => _cookies.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => (_cookies as IEnumerable).GetEnumerator(); +} public class CookieFilter { diff --git a/dotnet/test/common/BiDi/Modules/StorageTest.cs b/dotnet/test/common/BiDi/Modules/StorageTest.cs index ce088adef0404..243cfb7125c72 100644 --- a/dotnet/test/common/BiDi/Modules/StorageTest.cs +++ b/dotnet/test/common/BiDi/Modules/StorageTest.cs @@ -22,7 +22,7 @@ public async Task CanGetCookieByName() }); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Cookies, Is.Empty); + Assert.That(cookies, Is.Empty); } [Test] @@ -42,7 +42,7 @@ public async Task CanGetCookieInDefaultUserContext() }); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Cookies, Is.Empty); + Assert.That(cookies, Is.Empty); Assert.That(cookies.PartitionKey.UserContext, Is.EqualTo(userContexts[0].UserContext)); } @@ -75,9 +75,9 @@ await context.Storage.SetCookieAsync(new("fish", "cod", UrlBuilder.HostName) var cookies = await context.Storage.GetCookiesAsync(); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Cookies.Count, Is.EqualTo(1)); + Assert.That(cookies.Count, Is.EqualTo(1)); - var cookie = cookies.Cookies[0]; + var cookie = cookies[0]; Assert.That(cookie.Name, Is.EqualTo("fish")); Assert.That((cookie.Value as BytesValue.String).Value, Is.EqualTo("cod")); @@ -100,9 +100,9 @@ public async Task CanGetAllCookies() var cookies = await bidi.Storage.GetCookiesAsync(); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Cookies.Count, Is.EqualTo(2)); - Assert.That(cookies.Cookies[0].Name, Is.EqualTo("key1")); - Assert.That(cookies.Cookies[1].Name, Is.EqualTo("key2")); + Assert.That(cookies.Count, Is.EqualTo(2)); + Assert.That(cookies[0].Name, Is.EqualTo("key1")); + Assert.That(cookies[1].Name, Is.EqualTo("key2")); } [Test] @@ -120,7 +120,7 @@ public async Task CanDeleteAllCookies() var cookies = await bidi.Storage.GetCookiesAsync(); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Cookies.Count, Is.EqualTo(0)); + Assert.That(cookies.Count, Is.EqualTo(0)); } [Test] @@ -138,8 +138,8 @@ public async Task CanDeleteCookieWithName() var cookies = await bidi.Storage.GetCookiesAsync(); Assert.That(cookies, Is.Not.Null); - Assert.That(cookies.Cookies.Count, Is.EqualTo(1)); - Assert.That(cookies.Cookies[0].Name, Is.EqualTo("key2")); + Assert.That(cookies.Count, Is.EqualTo(1)); + Assert.That(cookies[0].Name, Is.EqualTo("key2")); } [Test] From c26d2133b1aacc3876cb72f87a8ffe33b05cdd7c Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 26 Sep 2024 21:19:50 +0300 Subject: [PATCH 15/60] Update Subscription.cs --- dotnet/src/webdriver/BiDi/Subscription.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Subscription.cs b/dotnet/src/webdriver/BiDi/Subscription.cs index 21995fee00dcf..a271fb6b9d5cd 100644 --- a/dotnet/src/webdriver/BiDi/Subscription.cs +++ b/dotnet/src/webdriver/BiDi/Subscription.cs @@ -7,18 +7,18 @@ namespace OpenQA.Selenium.BiDi; public class Subscription : IAsyncDisposable { - private readonly Broker Broker; + private readonly Broker _broker; private readonly Communication.EventHandler _eventHandler; internal Subscription(Broker broker, Communication.EventHandler eventHandler) { - Broker = broker; + _broker = broker; _eventHandler = eventHandler; } public async Task UnsubscribeAsync() { - await Broker.UnsubscribeAsync(_eventHandler).ConfigureAwait(false); + await _broker.UnsubscribeAsync(_eventHandler).ConfigureAwait(false); } public async ValueTask DisposeAsync() From 42f415089fe9d385e9b7710175a8e47d0ffdd26c Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:36:59 +0300 Subject: [PATCH 16/60] Script tests --- dotnet/src/webdriver/BiDi/BiDi.cs | 2 +- .../Polymorphic/RealmInfoConverter.cs | 16 +- .../Polymorphic/RemoteValueConverter.cs | 7 + .../BrowsingContext/BrowsingContext.cs | 2 +- .../BrowsingContextScriptModule.cs | 15 +- .../BiDi/Modules/Script/EvaluateCommand.cs | 7 +- .../BiDi/Modules/Script/LocalValue.cs | 2 + .../BiDi/Modules/Script/PreloadScript.cs | 2 +- .../BiDi/Modules/Script/RealmInfo.cs | 20 +- .../BiDi/Modules/Script/RemoteValue.cs | 9 + .../BiDi/Modules/Script/ScriptModule.cs | 15 +- dotnet/test/common/BiDi/BiDiFixture.cs | 3 +- .../BiDi/{Modules => Browser}/BrowserTest.cs | 2 +- .../BrowsingContextTest.cs | 4 +- .../common/BiDi/{Modules => Log}/LogTest.cs | 4 +- .../{Modules => Network}/NetworkEventsTest.cs | 13 +- .../BiDi/{Modules => Network}/NetworkTest.cs | 19 +- .../BiDi/Script/CallFunctionParameterTest.cs | 204 ++++++++++++++++++ .../BiDi/{Modules => Storage}/StorageTest.cs | 2 +- 19 files changed, 293 insertions(+), 55 deletions(-) rename dotnet/test/common/BiDi/{Modules => Browser}/BrowserTest.cs (96%) rename dotnet/test/common/BiDi/{Modules => BrowsingContext}/BrowsingContextTest.cs (98%) rename dotnet/test/common/BiDi/{Modules => Log}/LogTest.cs (94%) rename dotnet/test/common/BiDi/{Modules => Network}/NetworkEventsTest.cs (92%) rename dotnet/test/common/BiDi/{Modules => Network}/NetworkTest.cs (88%) create mode 100644 dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs rename dotnet/test/common/BiDi/{Modules => Storage}/StorageTest.cs (99%) diff --git a/dotnet/src/webdriver/BiDi/BiDi.cs b/dotnet/src/webdriver/BiDi/BiDi.cs index 973fd2ced99cb..dfc992e233c60 100644 --- a/dotnet/src/webdriver/BiDi/BiDi.cs +++ b/dotnet/src/webdriver/BiDi/BiDi.cs @@ -41,7 +41,7 @@ internal BiDi(string url) public Modules.Browser.BrowserModule Browser => _browserModule.Value; public Modules.Network.NetworkModule Network => _networkModule.Value; internal Modules.Input.InputModule InputModule => _inputModule.Value; - internal Modules.Script.ScriptModule ScriptModule => _scriptModule.Value; + public Modules.Script.ScriptModule Script => _scriptModule.Value; public Modules.Log.LogModule Log => _logModule.Value; public Modules.Storage.StorageModule Storage => _storageModule.Value; 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 3fff1242c6698..c77fed7e976a7 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs @@ -14,14 +14,14 @@ internal class RealmInfoConverter : JsonConverter return jsonDocument.RootElement.GetProperty("type").ToString() switch { - "window" => jsonDocument.Deserialize(options), - "dedicated-worker" => jsonDocument.Deserialize(options), - "shared-worker" => jsonDocument.Deserialize(options), - "service-worker" => jsonDocument.Deserialize(options), - "worker" => jsonDocument.Deserialize(options), - "paint-worklet" => jsonDocument.Deserialize(options), - "audio-worklet" => jsonDocument.Deserialize(options), - "worklet" => jsonDocument.Deserialize(options), + "window" => jsonDocument.Deserialize(options), + "dedicated-worker" => jsonDocument.Deserialize(options), + "shared-worker" => jsonDocument.Deserialize(options), + "service-worker" => jsonDocument.Deserialize(options), + "worker" => jsonDocument.Deserialize(options), + "paint-worklet" => jsonDocument.Deserialize(options), + "audio-worklet" => jsonDocument.Deserialize(options), + "worklet" => jsonDocument.Deserialize(options), _ => 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 9451e541d8f5a..f27d56c379afa 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs @@ -12,13 +12,20 @@ internal class RemoteValueConverter : JsonConverter { var jsonDocument = JsonDocument.ParseValue(ref reader); + if (jsonDocument.RootElement.ValueKind == JsonValueKind.String) + { + return new RemoteValue.String(jsonDocument.RootElement.GetString()); + } + return jsonDocument.RootElement.GetProperty("type").ToString() switch { "number" => jsonDocument.Deserialize(options), + "boolean" => jsonDocument.Deserialize(options), "string" => jsonDocument.Deserialize(options), "null" => jsonDocument.Deserialize(options), "undefined" => jsonDocument.Deserialize(options), "symbol" => jsonDocument.Deserialize(options), + "array" => jsonDocument.Deserialize(options), "object" => jsonDocument.Deserialize(options), "function" => jsonDocument.Deserialize(options), "regexp" => jsonDocument.Deserialize(options), diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs index e0b27bf73d199..0f7aa800a1f7d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs @@ -13,7 +13,7 @@ internal BrowsingContext(BiDi bidi, string id) _logModule = new Lazy(() => new BrowsingContextLogModule(this, BiDi.Log)); _networkModule = new Lazy(() => new BrowsingContextNetworkModule(this, BiDi.Network)); - _scriptModule = new Lazy(() => new BrowsingContextScriptModule(this, BiDi.ScriptModule)); + _scriptModule = new Lazy(() => new BrowsingContextScriptModule(this, BiDi.Script)); _storageModule = new Lazy(() => new BrowsingContextStorageModule(this, BiDi.Storage)); _inputModule = new Lazy(() => new BrowsingContextInputModule(this, BiDi.InputModule)); } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs index 6ba84549f0f33..3d8b2c2519d8a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs @@ -25,7 +25,7 @@ public async Task> GetRealmsAsync(GetRealmsOptions? opt return await scriptModule.GetRealmsAsync(options).ConfigureAwait(false); } - public Task EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null) + public Task EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null) { var contextTarget = new Target.Context(context); @@ -39,12 +39,12 @@ public Task EvaluateAsync(string expression, bool awaitPromise, Eva public async Task EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null) { - var remoteValue = await EvaluateAsync(expression, awaitPromise, options).ConfigureAwait(false); + var result = await EvaluateAsync(expression, awaitPromise, options).ConfigureAwait(false); - return remoteValue.ConvertTo(); + return result.Result.ConvertTo(); } - public Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, CallFunctionOptions? options = null, ContextTargetOptions? targetOptions = null) + public Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, CallFunctionOptions? options = null, ContextTargetOptions? targetOptions = null) { var contextTarget = new Target.Context(context); @@ -55,4 +55,11 @@ public Task CallFunctionAsync(string functionDeclaration, bool awai return scriptModule.CallFunctionAsync(functionDeclaration, awaitPromise, contextTarget, options); } + + public async Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, CallFunctionOptions? options = null, ContextTargetOptions? targetOptions = null) + { + var result = await CallFunctionAsync(functionDeclaration, awaitPromise, options, targetOptions).ConfigureAwait(false); + + return result.Result.ConvertTo(); + } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs index 966b12f18e6ca..266bac742a2b1 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs @@ -28,9 +28,12 @@ public record EvaluateOptions : CommandOptions //[JsonDerivedType(typeof(Exception), "exception")] public abstract record EvaluateResult { - public record Success(RemoteValue Result) : EvaluateResult; + public record Success(RemoteValue Result, Realm Realm) : EvaluateResult + { + public static implicit operator RemoteValue(Success success) => success.Result; + } - public record Exception(ExceptionDetails ExceptionDetails) : EvaluateResult; + public record Exception(ExceptionDetails ExceptionDetails, Realm Realm) : EvaluateResult; } public record ExceptionDetails(long ColumnNumber, long LineNumber, StackTrace StackTrace, string Text); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs index ea5b0ee425c93..00711c18f6813 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs @@ -24,6 +24,8 @@ public static LocalValue ConvertFrom(object? value) { switch (value) { + case LocalValue: + return (LocalValue)value; case null: return new Null(); case int: diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs b/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs index a59b9c099f05d..8533b2ddb494e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs @@ -17,7 +17,7 @@ public PreloadScript(BiDi bidi, string id) public Task RemoveAsync() { - return _bidi.ScriptModule.RemovePreloadScriptAsync(this); + return _bidi.Script.RemovePreloadScriptAsync(this); } public async ValueTask DisposeAsync() diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs index d4844bfb1a881..0bc703d8217db 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs @@ -12,26 +12,24 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; //[JsonDerivedType(typeof(PaintWorklet), "paint-worklet")] //[JsonDerivedType(typeof(AudioWorklet), "audio-worklet")] //[JsonDerivedType(typeof(Worklet), "worklet")] -public abstract record RealmInfo(BiDi BiDi) : EventArgs(BiDi); - -public abstract record BaseRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi) +public abstract record RealmInfo(BiDi BiDi, Realm Realm, string Origin) : EventArgs(BiDi) { - public record Window(BiDi BiDi, Realm Realm, string Origin, BrowsingContext.BrowsingContext Context) : BaseRealmInfo(BiDi, Realm, Origin) + public record Window(BiDi BiDi, Realm Realm, string Origin, BrowsingContext.BrowsingContext Context) : RealmInfo(BiDi, Realm, Origin) { public string? Sandbox { get; set; } } - public record DedicatedWorker(BiDi BiDi, Realm Realm, string Origin, IReadOnlyList Owners) : BaseRealmInfo(BiDi, Realm, Origin); + public record DedicatedWorker(BiDi BiDi, Realm Realm, string Origin, IReadOnlyList Owners) : RealmInfo(BiDi, Realm, Origin); - public record SharedWorker(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record SharedWorker(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin); - public record ServiceWorker(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record ServiceWorker(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin); - public record Worker(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record Worker(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin); - public record PaintWorklet(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record PaintWorklet(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin); - public record AudioWorklet(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record AudioWorklet(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin); - public record Worklet(BiDi BiDi, Realm Realm, string Origin) : BaseRealmInfo(BiDi, Realm, Origin); + public record Worklet(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index c3bef4971cf37..b288b8d83958d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Script; @@ -7,10 +8,12 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] //[JsonDerivedType(typeof(Number), "number")] +//[JsonDerivedType(typeof(Boolean), "boolean")] //[JsonDerivedType(typeof(String), "string")] //[JsonDerivedType(typeof(Null), "null")] //[JsonDerivedType(typeof(Undefined), "undefined")] //[JsonDerivedType(typeof(Symbol), "symbol")] +//[JsonDerivedType(typeof(Array), "array")] //[JsonDerivedType(typeof(Object), "object")] //[JsonDerivedType(typeof(Function), "function")] //[JsonDerivedType(typeof(RegExp), "regexp")] @@ -48,6 +51,10 @@ public static implicit operator string(RemoteValue remoteValue) { var type = typeof(TResult); + if (type == typeof(bool)) + { + return (TResult)(Convert.ToBoolean(((Boolean)this).Value) as object); + } if (type == typeof(int)) { return (TResult)(Convert.ToInt32(((Number)this).Value) as object); @@ -67,6 +74,8 @@ public static implicit operator string(RemoteValue remoteValue) public record Number(long Value) : PrimitiveProtocolRemoteValue; + public record Boolean(bool Value) : PrimitiveProtocolRemoteValue; + public record String(string Value) : PrimitiveProtocolRemoteValue; public record Null : PrimitiveProtocolRemoteValue; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs index f53aaf4f03046..cb33014ff55c5 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs @@ -7,7 +7,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; public sealed class ScriptModule(Broker broker) : Module(broker) { - public async Task EvaluateAsync(string expression, bool awaitPromise, Target target, EvaluateOptions? options = null) + public async Task EvaluateAsync(string expression, bool awaitPromise, Target target, EvaluateOptions? options = null) { var @params = new EvaluateCommandParameters(expression, target, awaitPromise); @@ -25,10 +25,10 @@ public async Task EvaluateAsync(string expression, bool awaitPromis throw new ScriptEvaluateException(exp); } - return ((EvaluateResult.Success)result).Result; + return (EvaluateResult.Success)result; } - public async Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, Target target, CallFunctionOptions? options = null) + public async Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, Target target, CallFunctionOptions? options = null) { var @params = new CallFunctionCommandParameters(functionDeclaration, awaitPromise, target); @@ -48,7 +48,14 @@ public async Task CallFunctionAsync(string functionDeclaration, boo throw new ScriptEvaluateException(exp); } - return ((EvaluateResult.Success)result).Result; + return (EvaluateResult.Success)result; + } + + public async Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, Target target, CallFunctionOptions? options = null) + { + var result = await CallFunctionAsync(functionDeclaration, awaitPromise, target, options).ConfigureAwait(false); + + return result.Result.ConvertTo(); } public async Task> GetRealmsAsync(GetRealmsOptions? options = null) diff --git a/dotnet/test/common/BiDi/BiDiFixture.cs b/dotnet/test/common/BiDi/BiDiFixture.cs index abc4634092cdd..7477d7fbd4d99 100644 --- a/dotnet/test/common/BiDi/BiDiFixture.cs +++ b/dotnet/test/common/BiDi/BiDiFixture.cs @@ -1,5 +1,4 @@ using NUnit.Framework; -using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using OpenQA.Selenium.Environment; using System.Threading.Tasks; @@ -11,7 +10,7 @@ class BiDiFixture { protected IWebDriver driver; protected BiDi bidi; - protected BrowsingContext context; + protected Modules.BrowsingContext.BrowsingContext context; protected UrlBuilder UrlBuilder { get; } = EnvironmentManager.Instance.UrlBuilder; diff --git a/dotnet/test/common/BiDi/Modules/BrowserTest.cs b/dotnet/test/common/BiDi/Browser/BrowserTest.cs similarity index 96% rename from dotnet/test/common/BiDi/Modules/BrowserTest.cs rename to dotnet/test/common/BiDi/Browser/BrowserTest.cs index 9a985bb8d893b..dcf48e71af2a5 100644 --- a/dotnet/test/common/BiDi/Modules/BrowserTest.cs +++ b/dotnet/test/common/BiDi/Browser/BrowserTest.cs @@ -1,7 +1,7 @@ using NUnit.Framework; using System.Threading.Tasks; -namespace OpenQA.Selenium.BiDi.Modules; +namespace OpenQA.Selenium.BiDi.Browser; class BrowserTest : BiDiFixture { diff --git a/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs similarity index 98% rename from dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs rename to dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs index c9212f1d9abbb..cc55f116d6c23 100644 --- a/dotnet/test/common/BiDi/Modules/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Threading.Tasks; -namespace OpenQA.Selenium.BiDi.Modules; +namespace OpenQA.Selenium.BiDi.BrowsingContext; class BrowsingContextTest : BiDiFixture { @@ -270,7 +270,7 @@ public async Task CanCaptureScreenshotOfElement() var screenshot = await context.CaptureScreenshotAsync(new() { - Clip = new ClipRectangle.Element(new Script.SharedReference(elements[0].SharedId)) + Clip = new ClipRectangle.Element(new Modules.Script.SharedReference(elements[0].SharedId)) }); Assert.That(screenshot, Is.Not.Null); diff --git a/dotnet/test/common/BiDi/Modules/LogTest.cs b/dotnet/test/common/BiDi/Log/LogTest.cs similarity index 94% rename from dotnet/test/common/BiDi/Modules/LogTest.cs rename to dotnet/test/common/BiDi/Log/LogTest.cs index 5f2c75decea9d..b031d2c9d113d 100644 --- a/dotnet/test/common/BiDi/Modules/LogTest.cs +++ b/dotnet/test/common/BiDi/Log/LogTest.cs @@ -3,7 +3,7 @@ using System; using System.Threading.Tasks; -namespace OpenQA.Selenium.BiDi.Modules; +namespace OpenQA.Selenium.BiDi.Log; class LogTest : BiDiFixture { @@ -33,7 +33,7 @@ public async Task CanListenToConsoleLog() Assert.That(consoleLogEntry.Args, Is.Not.Null); Assert.That(consoleLogEntry.Args, Has.Count.EqualTo(1)); - Assert.That(consoleLogEntry.Args[0], Is.AssignableFrom()); + Assert.That(consoleLogEntry.Args[0], Is.AssignableFrom()); } [Test] diff --git a/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs similarity index 92% rename from dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs rename to dotnet/test/common/BiDi/Network/NetworkEventsTest.cs index 5a773492f30f0..81b14cd72cc2f 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkEventsTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs @@ -1,9 +1,10 @@ using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using OpenQA.Selenium.BiDi.Modules.Network; using System; using System.Threading.Tasks; -namespace OpenQA.Selenium.BiDi.Modules; +namespace OpenQA.Selenium.BiDi.Network; class NetworkEventsTest : BiDiFixture { @@ -14,7 +15,7 @@ public async Task CanListenToBeforeRequestSentEvent() await using var subscription = await context.Network.OnBeforeRequestSentAsync(tcs.SetResult); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); var req = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); @@ -32,7 +33,7 @@ public async Task CanListenToResponseStartedEvent() await using var subscription = await context.Network.OnResponseStartedAsync(tcs.SetResult); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); @@ -51,7 +52,7 @@ public async Task CanListenToResponseCompletedEvent() await using var subscription = await context.Network.OnResponseCompletedAsync(tcs.SetResult); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); var res = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); @@ -69,7 +70,7 @@ public async Task CanListenToBeforeRequestSentEventWithCookie() { TaskCompletionSource tcs = new(); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); driver.Manage().Cookies.AddCookie(new("foo", "bar")); @@ -114,7 +115,7 @@ public async Task CanListenToFetchError() try { - await context.NavigateAsync("https://not_a_valid_url.test", new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync("https://not_a_valid_url.test", new() { Wait = ReadinessState.Complete }); } catch (Exception) { } diff --git a/dotnet/test/common/BiDi/Modules/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs similarity index 88% rename from dotnet/test/common/BiDi/Modules/NetworkTest.cs rename to dotnet/test/common/BiDi/Network/NetworkTest.cs index 65ac70b35d94d..a274f6b63fb26 100644 --- a/dotnet/test/common/BiDi/Modules/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -1,8 +1,9 @@ using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using OpenQA.Selenium.BiDi.Modules.Network; using System.Threading.Tasks; -namespace OpenQA.Selenium.BiDi.Modules; +namespace OpenQA.Selenium.BiDi.Network; class NetworkTest : BiDiFixture { @@ -54,7 +55,7 @@ public async Task CanContinueRequest() await e.Request.Request.ContinueAsync(); }); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); Assert.That(intercept, Is.Not.Null); Assert.That(times, Is.GreaterThan(0)); @@ -72,7 +73,7 @@ public async Task CanContinueResponse() await e.Request.Request.ContinueResponseAsync(); }); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); Assert.That(intercept, Is.Not.Null); Assert.That(times, Is.GreaterThan(0)); @@ -90,7 +91,7 @@ public async Task CanProvideResponse() await e.Request.Request.ProvideResponseAsync(); }); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); Assert.That(intercept, Is.Not.Null); Assert.That(times, Is.GreaterThan(0)); @@ -116,7 +117,7 @@ await e.Request.Request.ProvideResponseAsync(new() { Body = """ """ }); }); - await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("bidi/logEntryAdded.html"), new() { Wait = ReadinessState.Complete }); Assert.That(intercept, Is.Not.Null); Assert.That(times, Is.GreaterThan(0)); @@ -146,7 +147,7 @@ public async Task CanContinueWithAuthCredentials() await e.Request.Request.ContinueWithAuthAsync(new AuthCredentials.Basic("test", "test")); }); - await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete }); Assert.That(driver.FindElement(By.CssSelector("h1")).Text, Is.EqualTo("authorized")); } @@ -159,7 +160,7 @@ public async Task CanContinueWithDefaultCredentials() await e.Request.Request.ContinueWithAuthAsync(new ContinueWithDefaultAuthOptions()); }); - var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete }); Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_INVALID_AUTH_CREDENTIALS")); } @@ -172,7 +173,7 @@ public async Task CanContinueWithCanceledCredentials() await e.Request.Request.ContinueWithAuthAsync(new ContinueWithCancelledAuthOptions()); }); - var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete }); Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_HTTP_RESPONSE_CODE_FAILURE")); } @@ -185,7 +186,7 @@ public async Task CanFailRequest() await e.Request.Request.FailAsync(); }); - var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = BrowsingContext.ReadinessState.Complete }); + var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete }); Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_FAILED")); } diff --git a/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs new file mode 100644 index 0000000000000..f71b6c67b0ee8 --- /dev/null +++ b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs @@ -0,0 +1,204 @@ +using Castle.DynamicProxy.Generators.Emitters; +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Script; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Script; + +class CallFunctionParameterTest : BiDiFixture +{ + [Test] + public async Task CanCallFunctionWithDeclaration() + { + var res = await context.Script.CallFunctionAsync("()=>{return 1+2;}", false); + + Assert.That(res, Is.Not.Null); + Assert.That(res.Realm, Is.Not.Null); + Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(3)); + } + + [Test] + public async Task CanCallFunctionWithDeclarationImplicitCast() + { + var res = await context.Script.CallFunctionAsync("()=>{return 1+2;}", false); + + Assert.That(res, Is.EqualTo(3)); + } + + [Test] + public async Task CanEvaluateScriptWithUserActivationTrue() + { + await context.Script.EvaluateAsync("window.open();", true, new() { UserActivation = true }); + + var res = await context.Script.CallFunctionAsync(""" + () => navigator.userActivation.isActive && navigator.userActivation.hasBeenActive + """, true, new() { UserActivation = true }); + + Assert.That(res, Is.True); + } + + [Test] + public async Task CanEvaluateScriptWithUserActivationFalse() + { + await context.Script.EvaluateAsync("window.open();", true); + + var res = await context.Script.CallFunctionAsync(""" + () => navigator.userActivation.isActive && navigator.userActivation.hasBeenActive + """, true); + + Assert.That(res, Is.False); + } + + [Test] + public async Task CanCallFunctionWithArguments() + { + var res = await context.Script.CallFunctionAsync("(...args)=>{return args}", false, new() + { + Arguments = ["abc", 42] + }); + + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((string)(res.Result as RemoteValue.Array).Value[0], Is.EqualTo("abc")); + Assert.That((int)(res.Result as RemoteValue.Array).Value[1], Is.EqualTo(42)); + } + + [Test] + public async Task CanCallFunctionToGetIFrameBrowsingContext() + { + driver.Url = UrlBuilder.WhereIs("click_too_big_in_frame.html"); + + var res = await context.Script.CallFunctionAsync(""" + () => document.querySelector('iframe[id="iframe1"]').contentWindow + """, false); + + Assert.That(res, Is.Not.Null); + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as RemoteValue.WindowProxy).Value, Is.Not.Null); + } + + [Test] + public async Task CanCallFunctionToGetElement() + { + driver.Url = UrlBuilder.WhereIs("bidi/logEntryAdded.html"); + + var res = await context.Script.CallFunctionAsync(""" + () => document.getElementById("consoleLog") + """, false); + + Assert.That(res, Is.Not.Null); + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as RemoteValue.Node).Value, Is.Not.Null); + } + + [Test] + public async Task CanCallFunctionWithAwaitPromise() + { + var res = await context.Script.CallFunctionAsync(""" + async function() { + await new Promise(r => setTimeout(() => r(), 0)); + return "SOME_DELAYED_RESULT"; + } + """, awaitPromise: true); + + Assert.That(res, Is.EqualTo("SOME_DELAYED_RESULT")); + } + + [Test] + public async Task CanCallFunctionWithAwaitPromiseFalse() + { + var res = await context.Script.CallFunctionAsync(""" + async function() { + await new Promise(r => setTimeout(() => r(), 0)); + return "SOME_DELAYED_RESULT"; + } + """, awaitPromise: false); + + Assert.That(res, Is.Not.Null); + Assert.That(res.Result, Is.AssignableFrom()); + } + + [Test] + public async Task CanCallFunctionWithThisParameter() + { + var thisParameter = new LocalValue.Object([["some_property", 42]]); + + var res = await context.Script.CallFunctionAsync(""" + function(){return this.some_property} + """, false, new() { This = thisParameter }); + + Assert.That(res, Is.EqualTo(42)); + } + + [Test] + public async Task CanCallFunctionWithOwnershipRoot() + { + var res = await context.Script.CallFunctionAsync("async function(){return {a:1}}", true, new() + { + ResultOwnership = ResultOwnership.Root + }); + + Assert.That(res, Is.Not.Null); + Assert.That((res.Result as RemoteValue.Object).Handle, Is.Not.Null); + Assert.That((string)(res.Result as RemoteValue.Object).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as RemoteValue.Object).Value[0][1], Is.EqualTo(1)); + } + + [Test] + public async Task CanCallFunctionWithOwnershipNone() + { + var res = await context.Script.CallFunctionAsync("async function(){return {a:1}}", true, new() + { + ResultOwnership = ResultOwnership.None + }); + + Assert.That(res, Is.Not.Null); + Assert.That((res.Result as RemoteValue.Object).Handle, Is.Null); + Assert.That((string)(res.Result as RemoteValue.Object).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as RemoteValue.Object).Value[0][1], Is.EqualTo(1)); + } + + [Test] + public void CanCallFunctionThatThrowsException() + { + var action = () => context.Script.CallFunctionAsync("))) !!@@## some invalid JS script (((", false); + + Assert.That(action, Throws.InstanceOf()); + } + + [Test] + public async Task CanCallFunctionInASandBox() + { + // Make changes without sandbox + await context.Script.CallFunctionAsync("() => { window.foo = 1; }", true); + + var res = await context.Script.CallFunctionAsync("() => window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); + + Assert.That(res.Result, Is.AssignableFrom()); + + // Make changes in the sandbox + await context.Script.CallFunctionAsync("() => { window.foo = 2; }", true, targetOptions: new() { Sandbox = "sandbox" }); + + // Check if the changes are present in the sandbox + res = await context.Script.CallFunctionAsync("() => window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); + + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(2)); + } + + [Test] + public async Task CanCallFunctionInARealm() + { + await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Tab); + + var realms = await bidi.Script.GetRealmsAsync(); + + await bidi.Script.CallFunctionAsync("() => { window.foo = 3; }", true, new Target.Realm(realms[0].Realm)); + await bidi.Script.CallFunctionAsync("() => { window.foo = 5; }", true, new Target.Realm(realms[1].Realm)); + + var res1 = await bidi.Script.CallFunctionAsync("() => window.foo", true, new Target.Realm(realms[0].Realm)); + var res2 = await bidi.Script.CallFunctionAsync("() => window.foo", true, new Target.Realm(realms[1].Realm)); + + Assert.That(res1, Is.EqualTo(3)); + Assert.That(res2, Is.EqualTo(5)); + } +} diff --git a/dotnet/test/common/BiDi/Modules/StorageTest.cs b/dotnet/test/common/BiDi/Storage/StorageTest.cs similarity index 99% rename from dotnet/test/common/BiDi/Modules/StorageTest.cs rename to dotnet/test/common/BiDi/Storage/StorageTest.cs index 243cfb7125c72..83e463af9ea02 100644 --- a/dotnet/test/common/BiDi/Modules/StorageTest.cs +++ b/dotnet/test/common/BiDi/Storage/StorageTest.cs @@ -3,7 +3,7 @@ using System; using System.Threading.Tasks; -namespace OpenQA.Selenium.BiDi.Modules; +namespace OpenQA.Selenium.BiDi.Storage; class StorageTest : BiDiFixture { From e96b5462c6b94147f976e9ed18f22cad3a5f1ac6 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:23:52 +0300 Subject: [PATCH 17/60] Evaluate tests --- .../BiDi/Modules/Script/ScriptModule.cs | 7 ++ .../BiDi/Script/CallFunctionParameterTest.cs | 7 +- .../BiDi/Script/EvaluateParametersTest.cs | 109 ++++++++++++++++++ 3 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs index cb33014ff55c5..20b219289aa19 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs @@ -28,6 +28,13 @@ public sealed class ScriptModule(Broker broker) : Module(broker) return (EvaluateResult.Success)result; } + public async Task EvaluateAsync(string expression, bool awaitPromise, Target target, EvaluateOptions? options = null) + { + var result = await EvaluateAsync(expression, awaitPromise, target, options).ConfigureAwait(false); + + return result.Result.ConvertTo(); + } + public async Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, Target target, CallFunctionOptions? options = null) { var @params = new CallFunctionCommandParameters(functionDeclaration, awaitPromise, target); diff --git a/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs index f71b6c67b0ee8..ff19e4fcd4728 100644 --- a/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs +++ b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs @@ -1,4 +1,3 @@ -using Castle.DynamicProxy.Generators.Emitters; using NUnit.Framework; using OpenQA.Selenium.BiDi.Modules.Script; using System.Threading.Tasks; @@ -10,7 +9,7 @@ class CallFunctionParameterTest : BiDiFixture [Test] public async Task CanCallFunctionWithDeclaration() { - var res = await context.Script.CallFunctionAsync("()=>{return 1+2;}", false); + var res = await context.Script.CallFunctionAsync("() => { return 1 + 2; }", false); Assert.That(res, Is.Not.Null); Assert.That(res.Realm, Is.Not.Null); @@ -20,7 +19,7 @@ public async Task CanCallFunctionWithDeclaration() [Test] public async Task CanCallFunctionWithDeclarationImplicitCast() { - var res = await context.Script.CallFunctionAsync("()=>{return 1+2;}", false); + var res = await context.Script.CallFunctionAsync("() => { return 1 + 2; }", false); Assert.That(res, Is.EqualTo(3)); } @@ -162,7 +161,7 @@ public void CanCallFunctionThatThrowsException() { var action = () => context.Script.CallFunctionAsync("))) !!@@## some invalid JS script (((", false); - Assert.That(action, Throws.InstanceOf()); + Assert.That(action, Throws.InstanceOf().And.Message.Contain("SyntaxError:")); } [Test] diff --git a/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs b/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs new file mode 100644 index 0000000000000..c3d94e1b99fa7 --- /dev/null +++ b/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs @@ -0,0 +1,109 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Script; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Script; + +class EvaluateParametersTest : BiDiFixture +{ + [Test] + public async Task CanEvaluateScript() + { + var res = await context.Script.EvaluateAsync("1 + 2", false); + + Assert.That(res, Is.Not.Null); + Assert.That(res.Realm, Is.Not.Null); + Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(3)); + } + + [Test] + public async Task CanEvaluateScriptImplicitCast() + { + var res = await context.Script.EvaluateAsync("1 + 2", false); + + Assert.That(res, Is.EqualTo(3)); + } + + [Test] + public async Task СanEvaluateScriptWithUserActivationTrue() + { + await context.Script.EvaluateAsync("window.open();", true, new() { UserActivation = true }); + + var res = await context.Script.EvaluateAsync(""" + navigator.userActivation.isActive && navigator.userActivation.hasBeenActive + """, true, new() { UserActivation = true }); + + Assert.That(res, Is.True); + } + + [Test] + public async Task СanEvaluateScriptWithUserActivationFalse() + { + await context.Script.EvaluateAsync("window.open();", true, new() { UserActivation = true }); + + var res = await context.Script.EvaluateAsync(""" + navigator.userActivation.isActive && navigator.userActivation.hasBeenActive + """, true, new() { UserActivation = false }); + + Assert.That(res, Is.False); + } + + [Test] + public void CanCallFunctionThatThrowsException() + { + var action = () => context.Script.EvaluateAsync("))) !!@@## some invalid JS script (((", false); + + Assert.That(action, Throws.InstanceOf().And.Message.Contain("SyntaxError:")); + } + + [Test] + public async Task CanEvaluateScriptWithResulWithOwnership() + { + var res = await context.Script.EvaluateAsync("Promise.resolve({a:1})", true, new() + { + ResultOwnership = ResultOwnership.Root + }); + + Assert.That(res, Is.Not.Null); + Assert.That((res.Result as RemoteValue.Object).Handle, Is.Not.Null); + Assert.That((string)(res.Result as RemoteValue.Object).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as RemoteValue.Object).Value[0][1], Is.EqualTo(1)); + } + + [Test] + public async Task CanEvaluateInASandBox() + { + // Make changes without sandbox + await context.Script.EvaluateAsync("window.foo = 1", true); + + var res = await context.Script.EvaluateAsync("window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); + + Assert.That(res.Result, Is.AssignableFrom()); + + // Make changes in the sandbox + await context.Script.EvaluateAsync("window.foo = 2", true, targetOptions: new() { Sandbox = "sandbox" }); + + // Check if the changes are present in the sandbox + res = await context.Script.EvaluateAsync("window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); + + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(2)); + } + + [Test] + public async Task CanEvaluateInARealm() + { + await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Tab); + + var realms = await bidi.Script.GetRealmsAsync(); + + await bidi.Script.EvaluateAsync("window.foo = 3", true, new Target.Realm(realms[0].Realm)); + await bidi.Script.EvaluateAsync("window.foo = 5", true, new Target.Realm(realms[1].Realm)); + + var res1 = await bidi.Script.EvaluateAsync("window.foo", true, new Target.Realm(realms[0].Realm)); + var res2 = await bidi.Script.EvaluateAsync("window.foo", true, new Target.Realm(realms[1].Realm)); + + Assert.That(res1, Is.EqualTo(3)); + Assert.That(res2, Is.EqualTo(5)); + } +} From 2d70508b32c3fc0a5cf2c250237e80fc255cc2e9 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 27 Sep 2024 13:07:00 +0300 Subject: [PATCH 18/60] Script events --- .../webdriver/BiDi/Communication/Broker.cs | 2 +- .../Json/Converters/ChannelConverter.cs | 9 +-- .../BrowsingContextScriptModule.cs | 1 + .../Modules/Script/AddPreloadScriptCommand.cs | 6 +- .../webdriver/BiDi/Modules/Script/Channel.cs | 13 +--- .../BiDi/Modules/Script/ChannelValue.cs | 13 ---- .../BiDi/Modules/Script/LocalValue.cs | 11 ++++ .../BiDi/Modules/Script/MessageEventArgs.cs | 3 + .../Modules/Script/RealmDestroyedEventArgs.cs | 3 + .../BiDi/Modules/Script/ScriptModule.cs | 31 +++++++++ .../common/BiDi/Script/ScriptEventsTest.cs | 64 +++++++++++++++++++ 11 files changed, 119 insertions(+), 37 deletions(-) delete mode 100644 dotnet/src/webdriver/BiDi/Modules/Script/ChannelValue.cs create mode 100644 dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs create mode 100644 dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs create mode 100644 dotnet/test/common/BiDi/Script/ScriptEventsTest.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 2f933fff0dbae..6b0d14138e5db 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -51,7 +51,7 @@ public Broker(BiDi bidi, ITransport transport) new NavigationConverter(), new InterceptConverter(_bidi), new RequestConverter(_bidi), - new ChannelConverter(_bidi), + new ChannelConverter(), new HandleConverter(_bidi), new InternalIdConverter(_bidi), new PreloadScriptConverter(_bidi), diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs index c2a7da0accffd..9771436eb8151 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs @@ -7,18 +7,11 @@ namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class ChannelConverter : JsonConverter { - private readonly BiDi _bidi; - - public ChannelConverter(BiDi bidi) - { - _bidi = bidi; - } - public override Channel? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { var id = reader.GetString(); - return new Channel(_bidi, id!); + return new Channel(id!); } public override void Write(Utf8JsonWriter writer, Channel value, JsonSerializerOptions options) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs index 3d8b2c2519d8a..69c22cbb6d24d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Modules.Script; using System.Collections.Generic; +using System; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs index 516e65b10f45c..4868765895b05 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs @@ -7,7 +7,7 @@ internal class AddPreloadScriptCommand(AddPreloadScriptCommandParameters @params internal record AddPreloadScriptCommandParameters(string FunctionDeclaration) : CommandParameters { - public IEnumerable? Arguments { get; set; } + public IEnumerable? Arguments { get; set; } public IEnumerable? Contexts { get; set; } @@ -24,7 +24,7 @@ internal AddPreloadScriptOptions(BrowsingContextAddPreloadScriptOptions? options Sandbox = options?.Sandbox; } - public IEnumerable? Arguments { get; set; } + public IEnumerable? Arguments { get; set; } public IEnumerable? Contexts { get; set; } @@ -33,7 +33,7 @@ internal AddPreloadScriptOptions(BrowsingContextAddPreloadScriptOptions? options public record BrowsingContextAddPreloadScriptOptions { - public IEnumerable? Arguments { get; set; } + public IEnumerable? Arguments { get; set; } public string? Sandbox { get; set; } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs index a828d9a4caff3..6562ac429655d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs @@ -1,14 +1,3 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; -public class Channel -{ - readonly BiDi _bidi; - - internal Channel(BiDi bidi, string id) - { - _bidi = bidi; - Id = id; - } - - internal string Id { get; } -} +public record Channel(string Id); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ChannelValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ChannelValue.cs deleted file mode 100644 index 4b92a7dc15b96..0000000000000 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ChannelValue.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace OpenQA.Selenium.BiDi.Modules.Script; - -public record ChannelValue : LocalValue -{ - public string Type => "channel"; -} - -public record ChannelProperties(Channel Channel) -{ - public SerializationOptions? SerializationOptions { get; set; } - - public ResultOwnership? Ownership { get; set; } -} diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs index 00711c18f6813..9cec2e620b5d9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs @@ -8,6 +8,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; [JsonDerivedType(typeof(String), "string")] [JsonDerivedType(typeof(Null), "null")] [JsonDerivedType(typeof(Undefined), "undefined")] +[JsonDerivedType(typeof(Channel), "channel")] [JsonDerivedType(typeof(Array), "array")] [JsonDerivedType(typeof(Date), "date")] [JsonDerivedType(typeof(Map), "map")] @@ -66,6 +67,16 @@ public record Null : PrimitiveProtocolLocalValue; public record Undefined : PrimitiveProtocolLocalValue; + public record Channel(Channel.ChannelProperties Value) : LocalValue + { + public record ChannelProperties(Script.Channel Channel) + { + public SerializationOptions? SerializationOptions { get; set; } + + public ResultOwnership? Ownership { get; set; } + } + } + public record Array(IEnumerable Value) : LocalValue; public record Date(string Value) : LocalValue; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs new file mode 100644 index 0000000000000..14dbea46ed3a6 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs @@ -0,0 +1,3 @@ +namespace OpenQA.Selenium.BiDi.Modules.Script; + +public record MessageEventArgs(BiDi BiDi, Channel Channel, RemoteValue Data, Source Source) : EventArgs(BiDi); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs new file mode 100644 index 0000000000000..03f61a744b95b --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs @@ -0,0 +1,3 @@ +namespace OpenQA.Selenium.BiDi.Modules.Script; + +public record RealmDestroyedEventArgs(BiDi BiDi, Realm Realm) : EventArgs(BiDi); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs index 20b219289aa19..1c02551831d8f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs @@ -1,4 +1,5 @@ using OpenQA.Selenium.BiDi.Communication; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -102,4 +103,34 @@ public async Task RemovePreloadScriptAsync(PreloadScript script, RemovePreloadSc await Broker.ExecuteCommandAsync(new RemovePreloadScriptCommand(@params), options).ConfigureAwait(false); } + + public async Task OnMessageAsync(Func handler, SubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("script.message", handler, options).ConfigureAwait(false); + } + + public async Task OnMessageAsync(Action handler, SubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("script.message", handler, options).ConfigureAwait(false); + } + + public async Task OnRealmCreatedAsync(Func handler, SubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("script.realmCreated", handler, options).ConfigureAwait(false); + } + + public async Task OnRealmCreatedAsync(Action handler, SubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("script.realmCreated", handler, options).ConfigureAwait(false); + } + + public async Task OnRealmDestroyedAsync(Func handler, SubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("script.realmDestroyed", handler, options).ConfigureAwait(false); + } + + public async Task OnRealmDestroyedAsync(Action handler, SubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("script.realmDestroyed", handler, options).ConfigureAwait(false); + } } diff --git a/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs b/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs new file mode 100644 index 0000000000000..9e67814dc548e --- /dev/null +++ b/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs @@ -0,0 +1,64 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Script; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Script; + +class ScriptEventsTest : BiDiFixture +{ + [Test] + public async Task CanListenToChannelMessage() + { + TaskCompletionSource tcs = new(); + + await bidi.Script.OnMessageAsync(tcs.SetResult); + + await context.Script.CallFunctionAsync("(channel) => channel('foo')", false, new() + { + Arguments = [new LocalValue.Channel(new(new("channel_name")))] + }); + + var message = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(message, Is.Not.Null); + Assert.That(message.Channel.Id, Is.EqualTo("channel_name")); + Assert.That((string)message.Data, Is.EqualTo("foo")); + Assert.That(message.Source, Is.Not.Null); + Assert.That(message.Source.Realm, Is.Not.Null); + Assert.That(message.Source.Context, Is.EqualTo(context)); + } + + [Test] + public async Task CanListenToRealmCreatedEvent() + { + TaskCompletionSource tcs = new(); + + await bidi.Script.OnRealmCreatedAsync(tcs.SetResult); + + await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Window); + + var realmInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(realmInfo, Is.Not.Null); + Assert.That(realmInfo, Is.AssignableFrom()); + Assert.That(realmInfo.Realm, Is.Not.Null); + } + + [Test] + public async Task CanListenToRealmDestroyedEvent() + { + TaskCompletionSource tcs = new(); + + await bidi.Script.OnRealmDestroyedAsync(tcs.SetResult); + + var ctx = await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Window); + await ctx.CloseAsync(); + + var args = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(args, Is.Not.Null); + Assert.That(args.Realm, Is.Not.Null); + } +} From 61d7fe2ce886e0bae586581dccd0d19ad29c3165 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:40:40 +0300 Subject: [PATCH 19/60] Script commands --- .../Json/Converters/RealmTypeConverter.cs | 15 +- .../BrowsingContextScriptModule.cs | 5 +- .../BiDi/Modules/Script/LocalValue.cs | 3 + .../common/BiDi/Script/ScriptCommandsTest.cs | 150 ++++++++++++++++++ .../common/BiDi/Script/ScriptEventsTest.cs | 1 - 5 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs index f92966b1a3f1f..af9d5c059c310 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs @@ -27,6 +27,19 @@ public override RealmType Read(ref Utf8JsonReader reader, Type typeToConvert, Js public override void Write(Utf8JsonWriter writer, RealmType value, JsonSerializerOptions options) { - throw new NotImplementedException(); + var str = value switch + { + RealmType.Window => "window", + RealmType.DedicatedWorker => "dedicated-worker", + RealmType.SharedWorker => "shared-worker", + RealmType.ServiceWorker => "service-worker", + RealmType.Worker => "worker", + RealmType.PaintWorker => "paint-worker", + RealmType.AudioWorker => "audio-worker", + RealmType.Worklet => "worklet", + _ => throw new JsonException($"Unrecognized '{value}' value of {typeof(RealmType)}."), + }; + + writer.WriteStringValue(str); } } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs index 69c22cbb6d24d..6e4b4f0b8cda8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Modules.Script; using System.Collections.Generic; -using System; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -38,9 +37,9 @@ public async Task> GetRealmsAsync(GetRealmsOptions? opt return scriptModule.EvaluateAsync(expression, awaitPromise, contextTarget, options); } - public async Task EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null) + public async Task EvaluateAsync(string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null) { - var result = await EvaluateAsync(expression, awaitPromise, options).ConfigureAwait(false); + var result = await EvaluateAsync(expression, awaitPromise, options, targetOptions).ConfigureAwait(false); return result.Result.ConvertTo(); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs index 9cec2e620b5d9..30cd1ea0868b5 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs @@ -69,6 +69,9 @@ public record Undefined : PrimitiveProtocolLocalValue; public record Channel(Channel.ChannelProperties Value) : LocalValue { + [JsonInclude] + internal string type = "channel"; + public record ChannelProperties(Script.Channel Channel) { public SerializationOptions? SerializationOptions { get; set; } diff --git a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs new file mode 100644 index 0000000000000..83264a0082e8e --- /dev/null +++ b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs @@ -0,0 +1,150 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Script; +using System; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Script; + +class ScriptCommandsTest : BiDiFixture +{ + [Test] + public async Task CanGetAllRealms() + { + _ = await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Window); + + var realms = await bidi.Script.GetRealmsAsync(); + + Assert.That(realms, Is.Not.Null); + Assert.That(realms.Count, Is.EqualTo(2)); + + Assert.That(realms[0], Is.AssignableFrom()); + Assert.That(realms[0].Realm, Is.Not.Null); + + Assert.That(realms[1], Is.AssignableFrom()); + Assert.That(realms[1].Realm, Is.Not.Null); + } + + [Test] + public async Task CanGetAllRealmsByType() + { + _ = await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Window); + + var realms = await bidi.Script.GetRealmsAsync(new() { Type = RealmType.Window }); + + Assert.That(realms, Is.Not.Null); + Assert.That(realms.Count, Is.EqualTo(2)); + + Assert.That(realms[0], Is.AssignableFrom()); + Assert.That(realms[0].Realm, Is.Not.Null); + + Assert.That(realms[1], Is.AssignableFrom()); + Assert.That(realms[1].Realm, Is.Not.Null); + } + + [Test] + public async Task CanGetRealmInBrowsingContext() + { + var tab = await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Tab); + + var realms = await tab.Script.GetRealmsAsync(); + + var tabRealm = realms[0] as RealmInfo.Window; + + Assert.That(tabRealm, Is.Not.Null); + Assert.That(tabRealm.Context, Is.EqualTo(tab)); + } + + [Test] + public async Task CanGetRealmInBrowsingContextByType() + { + var tab = await bidi.BrowsingContext.CreateAsync(Modules.BrowsingContext.ContextType.Tab); + + var realms = await tab.Script.GetRealmsAsync(new() { Type = RealmType.Window }); + + var tabRealm = realms[0] as RealmInfo.Window; + + Assert.That(tabRealm, Is.Not.Null); + Assert.That(tabRealm.Context, Is.EqualTo(tab)); + } + + [Test] + public async Task CanAddPreloadScript() + { + var preloadScript = await bidi.Script.AddPreloadScriptAsync("() => { console.log('preload_script_console_text') }"); + + Assert.That(preloadScript, Is.Not.Null); + + TaskCompletionSource tcs = new(); + + await context.Log.OnEntryAddedAsync(tcs.SetResult); + + await context.ReloadAsync(); + + var entry = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); + + Assert.That(entry.Level, Is.EqualTo(Modules.Log.Level.Info)); + Assert.That(entry.Text, Is.EqualTo("preload_script_console_text")); + } + + [Test] + public async Task CanAddPreloadScriptWithArguments() + { + var preloadScript = await bidi.Script.AddPreloadScriptAsync("(channel) => channel('will_be_send', 'will_be_ignored')", new() + { + Arguments = [new LocalValue.Channel(new(new("channel_name")))] + }); + + Assert.That(preloadScript, Is.Not.Null); + } + + + [Test] + public async Task CanAddPreloadScriptWithChannelOptions() + { + var preloadScript = await bidi.Script.AddPreloadScriptAsync("(channel) => channel('will_be_send', 'will_be_ignored')", new() + { + Arguments = [new LocalValue.Channel(new(new("channel_name")) + { + SerializationOptions = new() + { + MaxDomDepth = 0 + }, + Ownership = ResultOwnership.Root + })] + }); + + Assert.That(preloadScript, Is.Not.Null); + } + + [Test] + public async Task CanAddPreloadScriptInASandbox() + { + var preloadScript = await bidi.Script.AddPreloadScriptAsync("() => { window.bar = 2; }", new() { Sandbox = "sandbox" }); + + Assert.That(preloadScript, Is.Not.Null); + + await context.ReloadAsync(); + + var bar = await context.Script.EvaluateAsync("window.bar", true, targetOptions: new() { Sandbox = "sandbox" }); + + Assert.That(bar, Is.EqualTo(2)); + } + + [Test] + public async Task CanRemovePreloadedScript() + { + var preloadScript = await context.Script.AddPreloadScriptAsync("() => { window.bar = 2; }"); + + await context.ReloadAsync(); + + var bar = await context.Script.EvaluateAsync("window.bar", true); + + Assert.That(bar, Is.EqualTo(2)); + + await preloadScript.RemoveAsync(); + + var resultAfterRemoval = await context.Script.EvaluateAsync("window.bar", true, targetOptions: new() { Sandbox = "sandbox" }); + + Assert.That(resultAfterRemoval.Result, Is.AssignableFrom()); + } +} diff --git a/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs b/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs index 9e67814dc548e..4f995b54ced26 100644 --- a/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs +++ b/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs @@ -1,7 +1,6 @@ using NUnit.Framework; using OpenQA.Selenium.BiDi.Modules.Script; using System; -using System.Threading; using System.Threading.Tasks; namespace OpenQA.Selenium.BiDi.Script; From dd5eac519d390d373baf2575e3d9011cf4faa394 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:43:02 +0300 Subject: [PATCH 20/60] Temp input --- .../Modules/Input/PerformActionsCommand.cs | 58 ------------------- .../BiDi/Modules/Input/SourceActions.cs | 57 ++++++++++++++++++ .../common/BiDi/Input/DefaultMouseTest.cs | 26 +++++++++ 3 files changed, 83 insertions(+), 58 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs create mode 100644 dotnet/test/common/BiDi/Input/DefaultMouseTest.cs diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs index 0a719c7513ce7..8c8ccd21bc7c6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs @@ -1,7 +1,5 @@ using OpenQA.Selenium.BiDi.Communication; -using System; using System.Collections.Generic; -using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Input; @@ -16,59 +14,3 @@ public record PerformActionsOptions : CommandOptions { public IEnumerable? Actions { get; set; } = []; } - -[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(KeySourceActions), "key")] -public abstract record SourceActions -{ - public static KeySourceActions Press(string text) - { - var keySourceActions = new KeySourceActions(); - - foreach (var character in text) - { - keySourceActions.Actions.AddRange([ - new KeyDownAction(character.ToString()), - new KeyUpAction(character.ToString()) - ]); - } - - return keySourceActions; - } -} - -public record KeySourceActions : SourceActions -{ - public string Id { get; set; } = Guid.NewGuid().ToString(); - - public List Actions { get; set; } = []; - - public new KeySourceActions Press(string text) - { - Actions.AddRange(SourceActions.Press(text).Actions); - - return this; - } - - public KeySourceActions Pause(long? duration = null) - { - Actions.Add(new KeyPauseAction { Duration = duration }); - - return this; - } -} - -[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(KeyPauseAction), "pause")] -[JsonDerivedType(typeof(KeyDownAction), "keyDown")] -[JsonDerivedType(typeof(KeyUpAction), "keyUp")] -public abstract record KeySourceAction; - -public record KeyPauseAction : KeySourceAction -{ - public long? Duration { get; set; } -} - -public record KeyDownAction(string Value) : KeySourceAction; - -public record KeyUpAction(string Value) : KeySourceAction; diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs new file mode 100644 index 0000000000000..6d468e68c5c2f --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Modules.Input; + +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Keys), "key")] +[JsonDerivedType(typeof(Pointers), "pointer")] +public abstract record SourceActions +{ + public record Keys : SourceActions + { + public string Id { get; set; } = Guid.NewGuid().ToString(); + + public List Actions { get; set; } = []; + + [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] + [JsonDerivedType(typeof(Pause), "pause")] + [JsonDerivedType(typeof(Down), "keyDown")] + [JsonDerivedType(typeof(Up), "keyUp")] + public abstract record Key + { + public record Pause : Key + { + public long? Duration { get; set; } + } + + public record Down(string Value) : Key; + + public record Up(string Value) : Key; + } + } + + public record Pointers : SourceActions + { + public string Id { get; set; } = Guid.NewGuid().ToString(); + + public List Actions { get; set; } = []; + + [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] + [JsonDerivedType(typeof(Pause), "pause")] + [JsonDerivedType(typeof(Down), "pointerDown")] + [JsonDerivedType(typeof(Up), "pointerUp")] + public abstract record Pointer + { + public record Pause : Pointer + { + public long? Duration { get; set; } + } + + public record Down(string Value) : Pointer; + + public record Up(string Value) : Pointer; + } + } +} diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs new file mode 100644 index 0000000000000..fc5f649a261ae --- /dev/null +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.Input; +using System.Threading.Tasks; + +using Key = OpenQA.Selenium.BiDi.Modules.Input.SourceActions.Keys.Key; + +namespace OpenQA.Selenium.BiDi.Input; + +class DefaultMouseTest : BiDiFixture +{ + [Test] + public async Task PerformDragAndDropWithMouse() + { + driver.Url = UrlBuilder.WhereIs("draggableLists.html"); + + await context.Input.PerformActionsAsync([ + new SourceActions.Keys() + { + Actions = + { + new Key.Down("A") + } + } + ]); + } +} From e80ea94240c804c93b8539a626179ac80e1a7e0a Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:07:08 +0300 Subject: [PATCH 21/60] Temp input tests --- .../webdriver/BiDi/Communication/Broker.cs | 1 + .../Enumerable/GetCookiesResultConverter.cs | 25 +++++---- .../Enumerable/InputSourceActionsConverter.cs | 48 +++++++++++++++++ .../BiDi/Modules/Input/SourceActions.cs | 53 +++++++++++++++---- .../BiDi/Input/CombinedInputActionsTest.cs | 25 +++++++++ .../common/BiDi/Input/DefaultMouseTest.cs | 15 +++++- 6 files changed, 144 insertions(+), 23 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs create mode 100644 dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 6b0d14138e5db..b29eddd75b0ad 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -71,6 +71,7 @@ public Broker(BiDi bidi, ITransport transport) // Enumerable new Json.Converters.Enumerable.GetCookiesResultConverter(), + new Json.Converters.Enumerable.InputSourceActionsConverter(), } }; } 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 c50b3b9c0f268..56beaa1d38d50 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs @@ -4,22 +4,21 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; + +internal class GetCookiesResultConverter : JsonConverter { - internal class GetCookiesResultConverter : JsonConverter + public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - var doc = JsonDocument.ParseValue(ref reader); - var cookies = doc.RootElement.GetProperty("cookies").Deserialize>(options); - var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize(options); + var doc = JsonDocument.ParseValue(ref reader); + var cookies = doc.RootElement.GetProperty("cookies").Deserialize>(options); + var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize(options); - return new GetCookiesResult(cookies, partitionKey); - } + return new GetCookiesResult(cookies, partitionKey); + } - public override void Write(Utf8JsonWriter writer, GetCookiesResult value, JsonSerializerOptions options) - { - throw new NotImplementedException(); - } + public override void Write(Utf8JsonWriter writer, GetCookiesResult value, JsonSerializerOptions options) + { + throw new NotImplementedException(); } } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs new file mode 100644 index 0000000000000..d8bd1cfb1de0d --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -0,0 +1,48 @@ +using OpenQA.Selenium.BiDi.Modules.Input; +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; + +internal class InputSourceActionsConverter : JsonConverter +{ + public override SourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + + public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSerializerOptions options) + { + if (value is SourceActions.Keys keyActions) + { + writer.WriteStartObject(); + + writer.WriteString("type", "key"); + writer.WriteString("id", keyActions.Id); + writer.WritePropertyName("actions"); + JsonSerializer.Serialize(writer, keyActions.Actions, options); + + writer.WriteEndObject(); + } + else if (value is SourceActions.Pointers pointerActions) + { + writer.WriteStartObject(); + + writer.WriteString("type", "pointer"); + writer.WriteString("id", pointerActions.Id); + + if (pointerActions.Options is not null) + { + writer.WritePropertyName("parameters"); + JsonSerializer.Serialize(writer, pointerActions.Options, options); + } + + writer.WritePropertyName("actions"); + JsonSerializer.Serialize(writer, pointerActions.Actions, options); + + writer.WriteEndObject(); + } + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 6d468e68c5c2f..2cb8f5b4f79e3 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -1,19 +1,26 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Text.Json.Serialization; namespace OpenQA.Selenium.BiDi.Modules.Input; -[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(Keys), "key")] -[JsonDerivedType(typeof(Pointers), "pointer")] +//[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +//[JsonDerivedType(typeof(Keys), "key")] +//[JsonDerivedType(typeof(Pointers), "pointer")] public abstract record SourceActions { - public record Keys : SourceActions + public record Keys : SourceActions, IEnumerable { public string Id { get; set; } = Guid.NewGuid().ToString(); - public List Actions { get; set; } = []; + public IList Actions { get; set; } = []; + + public void Add(Key key) => Actions.Add(key); + + public IEnumerator GetEnumerator() => Actions.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Pause), "pause")] @@ -32,11 +39,27 @@ public record Up(string Value) : Key; } } - public record Pointers : SourceActions + public record Pointers : SourceActions, IEnumerable { public string Id { get; set; } = Guid.NewGuid().ToString(); - public List Actions { get; set; } = []; + public Parameters? Options { get; set; } + + public IList Actions { get; set; } = []; + + public void Add(Pointer pointer) => Actions.Add(pointer); + + public IEnumerator GetEnumerator() => Actions.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); + + public Pointers Click() + { + Add(new Pointer.Down(1)); + Add(new Pointer.Up(1)); + + return this; + } [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Pause), "pause")] @@ -49,9 +72,21 @@ public record Pause : Pointer public long? Duration { get; set; } } - public record Down(string Value) : Pointer; + public record Down(int Button) : Pointer; + + public record Up(int Button) : Pointer; + } + + public record Parameters + { + public Type? PointerType { get; set; } + } - public record Up(string Value) : Pointer; + public enum Type + { + Mouse, + Pen, + Touch } } } diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs new file mode 100644 index 0000000000000..20358c3193a12 --- /dev/null +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -0,0 +1,25 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.BrowsingContext; +using OpenQA.Selenium.BiDi.Modules.Input; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Input; + +class CombinedInputActionsTest : BiDiFixture +{ + [Test] + public async Task TestShiftClickingOnMultiSelectionList() + { + driver.Url = UrlBuilder.WhereIs("formSelectionPage.html"); + + var options = await context.LocateNodesAsync(new Locator.Css("option")); + + await context.Input.PerformActionsAsync([ + new SourceActions.Pointers + { + new SourceActions.Pointers.Pointer.Down(1), + new SourceActions.Pointers.Pointer.Up(1), + } + ]); + } +} diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index fc5f649a261ae..e374d910e0900 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -14,7 +14,7 @@ public async Task PerformDragAndDropWithMouse() driver.Url = UrlBuilder.WhereIs("draggableLists.html"); await context.Input.PerformActionsAsync([ - new SourceActions.Keys() + new SourceActions.Keys { Actions = { @@ -22,5 +22,18 @@ await context.Input.PerformActionsAsync([ } } ]); + + await context.Input.PerformActionsAsync([new SourceActions.Keys + { + new Key.Down("A"), + new Key.Down("B"), + new Key.Pause() + }]); + + await context.Input.PerformActionsAsync([new SourceActions.Pointers + { + new SourceActions.Pointers.Pointer.Down(1), + new SourceActions.Pointers.Pointer.Up(1), + }.Click().Click()]); } } From 6f68c21c2c01fb462d811ba3321a588306c42631 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 29 Sep 2024 23:42:17 +0300 Subject: [PATCH 22/60] Experimenting input via paint --- .../BiDi/Modules/Input/SourceActions.cs | 10 +++++-- .../BiDi/Input/CombinedInputActionsTest.cs | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 2cb8f5b4f79e3..0e2d833f48f28 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -55,8 +55,8 @@ public record Pointers : SourceActions, IEnumerable public Pointers Click() { - Add(new Pointer.Down(1)); - Add(new Pointer.Up(1)); + Add(new Pointer.Down(0)); + Add(new Pointer.Up(0)); return this; } @@ -65,6 +65,7 @@ public Pointers Click() [JsonDerivedType(typeof(Pause), "pause")] [JsonDerivedType(typeof(Down), "pointerDown")] [JsonDerivedType(typeof(Up), "pointerUp")] + [JsonDerivedType(typeof(Move), "pointerMove")] public abstract record Pointer { public record Pause : Pointer @@ -75,6 +76,11 @@ public record Pause : Pointer public record Down(int Button) : Pointer; public record Up(int Button) : Pointer; + + public record Move(int X, int Y) : Pointer + { + public int? Duration { get; set; } + } } public record Parameters diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index 20358c3193a12..41884c71d5332 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -7,6 +7,35 @@ namespace OpenQA.Selenium.BiDi.Input; class CombinedInputActionsTest : BiDiFixture { + [Test] + public async Task Paint() + { + driver.Url = "https://kleki.com/"; + + await Task.Delay(3000); + + await context.Input.PerformActionsAsync([new SourceActions.Pointers { + new SourceActions.Pointers.Pointer.Move(300, 300), + new SourceActions.Pointers.Pointer.Down(0), + new SourceActions.Pointers.Pointer.Move(400, 400) { Duration = 2000 }, + new SourceActions.Pointers.Pointer.Up(0), + }]); + + await context.Input.PerformActionsAsync([new SourceActions.Keys { + new SourceActions.Keys.Key.Down("U"), + new SourceActions.Keys.Key.Up("U") + }]); + + await context.Input.PerformActionsAsync([new SourceActions.Pointers { + new SourceActions.Pointers.Pointer.Move(300, 300), + new SourceActions.Pointers.Pointer.Down(0), + new SourceActions.Pointers.Pointer.Move(400, 400) { Duration = 2000 }, + new SourceActions.Pointers.Pointer.Up(0), + }]); + + await Task.Delay(3000); + } + [Test] public async Task TestShiftClickingOnMultiSelectionList() { From d711bd8260dc8200c20ba18beadc3043eaa10032 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:50:52 +0300 Subject: [PATCH 23/60] Update DefaultMouseTest.cs --- dotnet/test/common/BiDi/Input/DefaultMouseTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index e374d910e0900..f41535f082e17 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -32,8 +32,8 @@ await context.Input.PerformActionsAsync([new SourceActions.Keys await context.Input.PerformActionsAsync([new SourceActions.Pointers { - new SourceActions.Pointers.Pointer.Down(1), - new SourceActions.Pointers.Pointer.Up(1), + new SourceActions.Pointers.Pointer.Down(0), + new SourceActions.Pointers.Pointer.Up(0), }.Click().Click()]); } } From 88be3553e572c2974dfc4cfb7c636779083529df Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:11:31 +0300 Subject: [PATCH 24/60] Make actions required --- .../BrowsingContext/BrowsingContextInputModule.cs | 9 +++++---- dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs | 10 +++------- .../BiDi/Modules/Input/PerformActionsCommand.cs | 10 ++-------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs index ceae616cb2378..d0c51b8f1584b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs @@ -8,10 +8,11 @@ public class BrowsingContextInputModule(BrowsingContext context, InputModule inp { public Task PerformActionsAsync(IEnumerable actions, PerformActionsOptions? options = null) { - options ??= new(); - - options.Actions = actions; + return inputModule.PerformActionsAsync(context, actions, options); + } - return inputModule.PerformActionsAsync(context, options); + public Task ReleaseActionsAsync(ReleaseActionsOptions? options = null) + { + return inputModule.ReleaseActionsAsync(context, options); } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs index 2626be49d179f..94764ba1cd9b8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs @@ -1,18 +1,14 @@ using OpenQA.Selenium.BiDi.Communication; +using System.Collections.Generic; using System.Threading.Tasks; namespace OpenQA.Selenium.BiDi.Modules.Input; public sealed class InputModule(Broker broker) : Module(broker) { - public async Task PerformActionsAsync(BrowsingContext.BrowsingContext context, PerformActionsOptions? options = null) + public async Task PerformActionsAsync(BrowsingContext.BrowsingContext context, IEnumerable actions, PerformActionsOptions? options = null) { - var @params = new PerformActionsCommandParameters(context); - - if (options is not null) - { - @params.Actions = options.Actions; - } + var @params = new PerformActionsCommandParameters(context, actions); await Broker.ExecuteCommandAsync(new PerformActionsCommand(@params), options).ConfigureAwait(false); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs index 8c8ccd21bc7c6..8d427d42be58d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs @@ -5,12 +5,6 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; internal class PerformActionsCommand(PerformActionsCommandParameters @params) : Command(@params); -internal record PerformActionsCommandParameters(BrowsingContext.BrowsingContext Context) : CommandParameters -{ - public IEnumerable? Actions { get; set; } -} +internal record PerformActionsCommandParameters(BrowsingContext.BrowsingContext Context, IEnumerable Actions) : CommandParameters; -public record PerformActionsOptions : CommandOptions -{ - public IEnumerable? Actions { get; set; } = []; -} +public record PerformActionsOptions : CommandOptions; From de74098795d0076616d9c7abb868f4f29249fde4 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:32:06 +0300 Subject: [PATCH 25/60] Don't introduce any helpers --- dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs | 8 -------- dotnet/test/common/BiDi/Input/DefaultMouseTest.cs | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 0e2d833f48f28..cda3ccb763473 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -53,14 +53,6 @@ public record Pointers : SourceActions, IEnumerable IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - public Pointers Click() - { - Add(new Pointer.Down(0)); - Add(new Pointer.Up(0)); - - return this; - } - [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Pause), "pause")] [JsonDerivedType(typeof(Down), "pointerDown")] diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index f41535f082e17..61b983c9ed898 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -34,6 +34,6 @@ await context.Input.PerformActionsAsync([new SourceActions.Pointers { new SourceActions.Pointers.Pointer.Down(0), new SourceActions.Pointers.Pointer.Up(0), - }.Click().Click()]); + }]); } } From 2124ef8663abecedb41db96d0876598fd726cbc0 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:57:14 +0300 Subject: [PATCH 26/60] Input wheel --- .../webdriver/BiDi/Communication/Broker.cs | 1 + .../Enumerable/InputSourceActionsConverter.cs | 11 +++ .../Json/Converters/InputOriginConverter.cs | 34 +++++++++ .../webdriver/BiDi/Modules/Input/Origin.cs | 18 +++++ .../BiDi/Modules/Input/SourceActions.cs | 72 ++++++++++++++++++- .../BiDi/Input/CombinedInputActionsTest.cs | 2 +- 6 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs create mode 100644 dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index b29eddd75b0ad..a7f426cba8329 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -59,6 +59,7 @@ public Broker(BiDi bidi, ITransport transport) new RealmTypeConverter(), new DateTimeOffsetConverter(), new PrintPageRangeConverter(), + new InputOriginConverter(), new JsonStringEnumConverter(JsonNamingPolicy.CamelCase), // https://github.com/dotnet/runtime/issues/72604 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 d8bd1cfb1de0d..49cf9eec538c1 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -42,6 +42,17 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria writer.WritePropertyName("actions"); JsonSerializer.Serialize(writer, pointerActions.Actions, options); + writer.WriteEndObject(); + } + else if (value is SourceActions.Wheels wheelActions) + { + writer.WriteStartObject(); + + writer.WriteString("type", "wheel"); + writer.WriteString("id", wheelActions.Id); + writer.WritePropertyName("actions"); + JsonSerializer.Serialize(writer, wheelActions.Actions, options); + writer.WriteEndObject(); } } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs new file mode 100644 index 0000000000000..48d40367b0603 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs @@ -0,0 +1,34 @@ +using OpenQA.Selenium.BiDi.Modules.Input; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; + +internal class InputOriginConverter : JsonConverter +{ + public override Origin Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + + public override void Write(Utf8JsonWriter writer, Origin value, JsonSerializerOptions options) + { + if (value is Origin.Viewport) + { + writer.WriteStringValue("viewport"); + } + else if (value is Origin.Pointer) + { + writer.WriteStringValue("pointer"); + } + else if (value is Origin.Element element) + { + writer.WriteStartObject(); + writer.WriteString("type", "element"); + writer.WritePropertyName("element"); + JsonSerializer.Serialize(writer, element.SharedReference, options); + writer.WriteEndObject(); + } + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs b/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs new file mode 100644 index 0000000000000..d611f9769c7e3 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs @@ -0,0 +1,18 @@ +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Modules.Input; + +public abstract record Origin +{ + public record Viewport() : Origin; + + public record Pointer() : Origin; + + public record Element(Script.SharedReference SharedReference) : Origin + { + public string Type { get; } = "element"; + + [JsonPropertyName("element")] + public Script.SharedReference SharedReference { get; } = SharedReference; + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index cda3ccb763473..d55572531c595 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -8,6 +8,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] //[JsonDerivedType(typeof(Keys), "key")] //[JsonDerivedType(typeof(Pointers), "pointer")] +//[JsonDerivedType(typeof(Wheels), "wheel")] public abstract record SourceActions { public record Keys : SourceActions, IEnumerable @@ -65,13 +66,32 @@ public record Pause : Pointer public long? Duration { get; set; } } - public record Down(int Button) : Pointer; + public record Down(int Button) : Pointer, IPointerCommonProperties + { + public int? Width { get; set; } + public int? Height { get; set; } + public double? Pressure { get; set; } + public double? TangentialPressure { get; set; } + public int? Twist { get; set; } + public double? AltitudeAngle { get; set; } + public double? AzimuthAngle { get; set; } + } public record Up(int Button) : Pointer; - public record Move(int X, int Y) : Pointer + public record Move(int X, int Y) : Pointer, IPointerCommonProperties { public int? Duration { get; set; } + + public Origin? Origin { get; set; } + + public int? Width { get; set; } + public int? Height { get; set; } + public double? Pressure { get; set; } + public double? TangentialPressure { get; set; } + public int? Twist { get; set; } + public double? AltitudeAngle { get; set; } + public double? AzimuthAngle { get; set; } } } @@ -86,5 +106,53 @@ public enum Type Pen, Touch } + + public interface IPointerCommonProperties + { + public int? Width { get; set; } + + public int? Height { get; set; } + + public double? Pressure { get; set; } + + public double? TangentialPressure { get; set; } + + public int? Twist { get; set; } + + public double? AltitudeAngle { get; set; } + + public double? AzimuthAngle { get; set; } + } + } + + public record Wheels : SourceActions, IEnumerable + { + public string Id { get; set; } = Guid.NewGuid().ToString(); + + public IList Actions { get; set; } = []; + + public void Add(Wheel wheel) => Actions.Add(wheel); + + public IEnumerator GetEnumerator() => Actions.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); + + [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] + [JsonDerivedType(typeof(Pause), "pause")] + [JsonDerivedType(typeof(Scroll), "scroll")] + public abstract record Wheel + { + public record Pause : Wheel + { + public long? Duration { get; set; } + } + + public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel + { + public int? Duration { get; set; } + + public Origin? Origin { get; set; } + } + } } } diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index 41884c71d5332..67d4940d192eb 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -17,7 +17,7 @@ public async Task Paint() await context.Input.PerformActionsAsync([new SourceActions.Pointers { new SourceActions.Pointers.Pointer.Move(300, 300), new SourceActions.Pointers.Pointer.Down(0), - new SourceActions.Pointers.Pointer.Move(400, 400) { Duration = 2000 }, + new SourceActions.Pointers.Pointer.Move(400, 400) { Duration = 2000, Width = 1, Twist = 1 }, new SourceActions.Pointers.Pointer.Up(0), }]); From 91325cebea47b267cc821ddfee1b7c40baebb1c0 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 4 Oct 2024 20:25:20 +0300 Subject: [PATCH 27/60] Simplify hierarchy --- .../BiDi/Modules/Input/SourceActions.cs | 176 +++++++++--------- .../BiDi/Input/CombinedInputActionsTest.cs | 24 +-- .../common/BiDi/Input/DefaultMouseTest.cs | 14 +- 3 files changed, 106 insertions(+), 108 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index d55572531c595..0a4ae81363ae2 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -11,7 +11,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; //[JsonDerivedType(typeof(Wheels), "wheel")] public abstract record SourceActions { - public record Keys : SourceActions, IEnumerable + public record Keys : SourceActions, IEnumerable { public string Id { get; set; } = Guid.NewGuid().ToString(); @@ -22,25 +22,9 @@ public record Keys : SourceActions, IEnumerable public IEnumerator GetEnumerator() => Actions.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - - [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] - [JsonDerivedType(typeof(Pause), "pause")] - [JsonDerivedType(typeof(Down), "keyDown")] - [JsonDerivedType(typeof(Up), "keyUp")] - public abstract record Key - { - public record Pause : Key - { - public long? Duration { get; set; } - } - - public record Down(string Value) : Key; - - public record Up(string Value) : Key; - } } - public record Pointers : SourceActions, IEnumerable + public record Pointers : SourceActions, IEnumerable { public string Id { get; set; } = Guid.NewGuid().ToString(); @@ -53,106 +37,122 @@ public record Pointers : SourceActions, IEnumerable public IEnumerator GetEnumerator() => Actions.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); + } + + public record Wheels : SourceActions, IEnumerable + { + public string Id { get; set; } = Guid.NewGuid().ToString(); + + public IList Actions { get; set; } = []; + + public void Add(Wheel wheel) => Actions.Add(wheel); + + public IEnumerator GetEnumerator() => Actions.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); + } - [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] - [JsonDerivedType(typeof(Pause), "pause")] - [JsonDerivedType(typeof(Down), "pointerDown")] - [JsonDerivedType(typeof(Up), "pointerUp")] - [JsonDerivedType(typeof(Move), "pointerMove")] - public abstract record Pointer + [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] + [JsonDerivedType(typeof(Pause), "pause")] + [JsonDerivedType(typeof(Down), "keyDown")] + [JsonDerivedType(typeof(Up), "keyUp")] + public abstract record Key + { + public record Pause : Key { - public record Pause : Pointer - { - public long? Duration { get; set; } - } - - public record Down(int Button) : Pointer, IPointerCommonProperties - { - public int? Width { get; set; } - public int? Height { get; set; } - public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } - public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } - } - - public record Up(int Button) : Pointer; - - public record Move(int X, int Y) : Pointer, IPointerCommonProperties - { - public int? Duration { get; set; } - - public Origin? Origin { get; set; } - - public int? Width { get; set; } - public int? Height { get; set; } - public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } - public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } - } + public long? Duration { get; set; } } - public record Parameters + public record Down(string Value) : Key; + + public record Up(string Value) : Key; + } + + [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] + [JsonDerivedType(typeof(Pause), "pause")] + [JsonDerivedType(typeof(Down), "pointerDown")] + [JsonDerivedType(typeof(Up), "pointerUp")] + [JsonDerivedType(typeof(Move), "pointerMove")] + public abstract record Pointer + { + public record Pause : Pointer { - public Type? PointerType { get; set; } + public long? Duration { get; set; } } - public enum Type + public record Down(int Button) : Pointer, IPointerCommonProperties { - Mouse, - Pen, - Touch + public int? Width { get; set; } + public int? Height { get; set; } + public double? Pressure { get; set; } + public double? TangentialPressure { get; set; } + public int? Twist { get; set; } + public double? AltitudeAngle { get; set; } + public double? AzimuthAngle { get; set; } } - public interface IPointerCommonProperties + public record Up(int Button) : Pointer; + + public record Move(int X, int Y) : Pointer, IPointerCommonProperties { - public int? Width { get; set; } + public int? Duration { get; set; } - public int? Height { get; set; } + public Origin? Origin { get; set; } + public int? Width { get; set; } + public int? Height { get; set; } public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } - public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } } } - public record Wheels : SourceActions, IEnumerable + public record Parameters { - public string Id { get; set; } = Guid.NewGuid().ToString(); + public PointerType? PointerType { get; set; } + } - public IList Actions { get; set; } = []; + public enum PointerType + { + Mouse, + Pen, + Touch + } - public void Add(Wheel wheel) => Actions.Add(wheel); + public interface IPointerCommonProperties + { + public int? Width { get; set; } - public IEnumerator GetEnumerator() => Actions.GetEnumerator(); + public int? Height { get; set; } - IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); + public double? Pressure { get; set; } + + public double? TangentialPressure { get; set; } - [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] - [JsonDerivedType(typeof(Pause), "pause")] - [JsonDerivedType(typeof(Scroll), "scroll")] - public abstract record Wheel + public int? Twist { get; set; } + + public double? AltitudeAngle { get; set; } + + public double? AzimuthAngle { get; set; } + } + + [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] + [JsonDerivedType(typeof(Pause), "pause")] + [JsonDerivedType(typeof(Scroll), "scroll")] + public abstract record Wheel + { + public record Pause : Wheel { - public record Pause : Wheel - { - public long? Duration { get; set; } - } + public long? Duration { get; set; } + } - public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel - { - public int? Duration { get; set; } + public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel + { + public int? Duration { get; set; } - public Origin? Origin { get; set; } - } + public Origin? Origin { get; set; } } } } diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index 67d4940d192eb..3d8df277d2ded 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -15,22 +15,22 @@ public async Task Paint() await Task.Delay(3000); await context.Input.PerformActionsAsync([new SourceActions.Pointers { - new SourceActions.Pointers.Pointer.Move(300, 300), - new SourceActions.Pointers.Pointer.Down(0), - new SourceActions.Pointers.Pointer.Move(400, 400) { Duration = 2000, Width = 1, Twist = 1 }, - new SourceActions.Pointers.Pointer.Up(0), + new SourceActions.Pointer.Move(300, 300), + new SourceActions.Pointer.Down(0), + new SourceActions.Pointer.Move(400, 400) { Duration = 2000, Width = 1, Twist = 1 }, + new SourceActions.Pointer.Up(0), }]); await context.Input.PerformActionsAsync([new SourceActions.Keys { - new SourceActions.Keys.Key.Down("U"), - new SourceActions.Keys.Key.Up("U") + new SourceActions.Key.Down("U"), + new SourceActions.Key.Up("U") }]); await context.Input.PerformActionsAsync([new SourceActions.Pointers { - new SourceActions.Pointers.Pointer.Move(300, 300), - new SourceActions.Pointers.Pointer.Down(0), - new SourceActions.Pointers.Pointer.Move(400, 400) { Duration = 2000 }, - new SourceActions.Pointers.Pointer.Up(0), + new SourceActions.Pointer.Move(300, 300), + new SourceActions.Pointer.Down(0), + new SourceActions.Pointer.Move(400, 400) { Duration = 2000 }, + new SourceActions.Pointer.Up(0), }]); await Task.Delay(3000); @@ -46,8 +46,8 @@ public async Task TestShiftClickingOnMultiSelectionList() await context.Input.PerformActionsAsync([ new SourceActions.Pointers { - new SourceActions.Pointers.Pointer.Down(1), - new SourceActions.Pointers.Pointer.Up(1), + new SourceActions.Pointer.Down(1), + new SourceActions.Pointer.Up(1), } ]); } diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index 61b983c9ed898..967cbb26d78c1 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -2,8 +2,6 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System.Threading.Tasks; -using Key = OpenQA.Selenium.BiDi.Modules.Input.SourceActions.Keys.Key; - namespace OpenQA.Selenium.BiDi.Input; class DefaultMouseTest : BiDiFixture @@ -18,22 +16,22 @@ await context.Input.PerformActionsAsync([ { Actions = { - new Key.Down("A") + new SourceActions.Key.Down("A") } } ]); await context.Input.PerformActionsAsync([new SourceActions.Keys { - new Key.Down("A"), - new Key.Down("B"), - new Key.Pause() + new SourceActions.Key.Down("A"), + new SourceActions.Key.Down("B"), + new SourceActions.Key.Pause() }]); await context.Input.PerformActionsAsync([new SourceActions.Pointers { - new SourceActions.Pointers.Pointer.Down(0), - new SourceActions.Pointers.Pointer.Up(0), + new SourceActions.Pointer.Down(0), + new SourceActions.Pointer.Up(0), }]); } } From a93b2b502b6a4ca2ae75092f2f62e3d883d5e5ef Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:04:28 +0300 Subject: [PATCH 28/60] Better --- .../Enumerable/InputSourceActionsConverter.cs | 64 ++++++++----------- .../BiDi/Modules/Input/SourceActions.cs | 56 +++++++--------- 2 files changed, 52 insertions(+), 68 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 49cf9eec538c1..204eb5d7f216f 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -1,6 +1,5 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System; -using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; @@ -15,45 +14,38 @@ public override SourceActions Read(ref Utf8JsonReader reader, Type typeToConvert public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSerializerOptions options) { - if (value is SourceActions.Keys keyActions) - { - writer.WriteStartObject(); + writer.WriteStartObject(); - writer.WriteString("type", "key"); - writer.WriteString("id", keyActions.Id); - writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, keyActions.Actions, options); + writer.WriteString("id", value.Id); - writer.WriteEndObject(); - } - else if (value is SourceActions.Pointers pointerActions) + switch (value) { - writer.WriteStartObject(); - - writer.WriteString("type", "pointer"); - writer.WriteString("id", pointerActions.Id); - - if (pointerActions.Options is not null) - { - writer.WritePropertyName("parameters"); - JsonSerializer.Serialize(writer, pointerActions.Options, options); - } - - writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, pointerActions.Actions, options); - - writer.WriteEndObject(); + case SourceActions.Keys keys: + writer.WriteString("type", "key"); + writer.WritePropertyName("actions"); + JsonSerializer.Serialize(writer, keys.Actions, options); + + break; + case SourceActions.Pointers pointers: + writer.WriteString("type", "pointer"); + if (pointers.Options is not null) + { + writer.WritePropertyName("parameters"); + JsonSerializer.Serialize(writer, pointers.Options, options); + } + + writer.WritePropertyName("actions"); + JsonSerializer.Serialize(writer, pointers.Actions, options); + + break; + case SourceActions.Wheels wheels: + writer.WriteString("type", "wheel"); + writer.WritePropertyName("actions"); + JsonSerializer.Serialize(writer, wheels.Actions, options); + + break; } - else if (value is SourceActions.Wheels wheelActions) - { - writer.WriteStartObject(); - writer.WriteString("type", "wheel"); - writer.WriteString("id", wheelActions.Id); - writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, wheelActions.Actions, options); - - writer.WriteEndObject(); - } + writer.WriteEndObject(); } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 0a4ae81363ae2..8de0b3cae326d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -5,16 +5,12 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; -//[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(Keys), "key")] -//[JsonDerivedType(typeof(Pointers), "pointer")] -//[JsonDerivedType(typeof(Wheels), "wheel")] public abstract record SourceActions { + public string Id { get; } = Guid.NewGuid().ToString(); + public record Keys : SourceActions, IEnumerable { - public string Id { get; set; } = Guid.NewGuid().ToString(); - public IList Actions { get; set; } = []; public void Add(Key key) => Actions.Add(key); @@ -26,8 +22,6 @@ public record Keys : SourceActions, IEnumerable public record Pointers : SourceActions, IEnumerable { - public string Id { get; set; } = Guid.NewGuid().ToString(); - public Parameters? Options { get; set; } public IList Actions { get; set; } = []; @@ -37,12 +31,22 @@ public record Pointers : SourceActions, IEnumerable public IEnumerator GetEnumerator() => Actions.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); + + public record Parameters + { + public Type? PointerType { get; set; } + } + + public enum Type + { + Mouse, + Pen, + Touch + } } public record Wheels : SourceActions, IEnumerable { - public string Id { get; set; } = Guid.NewGuid().ToString(); - public IList Actions { get; set; } = []; public void Add(Wheel wheel) => Actions.Add(wheel); @@ -107,35 +111,23 @@ public record Move(int X, int Y) : Pointer, IPointerCommonProperties public double? AltitudeAngle { get; set; } public double? AzimuthAngle { get; set; } } - } - - public record Parameters - { - public PointerType? PointerType { get; set; } - } - public enum PointerType - { - Mouse, - Pen, - Touch - } - - public interface IPointerCommonProperties - { - public int? Width { get; set; } + public interface IPointerCommonProperties + { + public int? Width { get; set; } - public int? Height { get; set; } + public int? Height { get; set; } - public double? Pressure { get; set; } + public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } + public double? TangentialPressure { get; set; } - public int? Twist { get; set; } + public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } + public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } + public double? AzimuthAngle { get; set; } + } } [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] From 33a88b65f64390b8fc5fd6a4a3dec84771d9546f Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:55:43 +0300 Subject: [PATCH 29/60] GetUserContextsResult as enumerable --- .../webdriver/BiDi/Communication/Broker.cs | 1 + .../GetUserContextsResultConverter.cs | 23 +++++++++++++++++++ .../BiDi/Modules/Browser/BrowserModule.cs | 6 ++--- .../Modules/Browser/GetUserContextsCommand.cs | 19 ++++++++++++++- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index a7f426cba8329..4ef01829094bf 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -73,6 +73,7 @@ public Broker(BiDi bidi, ITransport transport) // Enumerable new Json.Converters.Enumerable.GetCookiesResultConverter(), new Json.Converters.Enumerable.InputSourceActionsConverter(), + new Json.Converters.Enumerable.GetUserContextsResultConverter(), } }; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs new file mode 100644 index 0000000000000..f31cc6c1eb5f0 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs @@ -0,0 +1,23 @@ +using OpenQA.Selenium.BiDi.Modules.Browser; +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; + +internal class GetUserContextsResultConverter : JsonConverter +{ + public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var doc = JsonDocument.ParseValue(ref reader); + var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize>(options); + + return new GetUserContextsResult(userContexts); + } + + public override void Write(Utf8JsonWriter writer, GetUserContextsResult value, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs index e42982b773d8c..de8a8dbce9c18 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs @@ -16,11 +16,9 @@ public async Task CreateUserContextAsync(CreateUserContextOptio return await Broker.ExecuteCommandAsync(new CreateUserContextCommand(), options).ConfigureAwait(false); } - public async Task> GetUserContextsAsync(GetUserContextsOptions? options = null) + public async Task GetUserContextsAsync(GetUserContextsOptions? options = null) { - var result = await Broker.ExecuteCommandAsync(new GetUserContextsCommand(), options).ConfigureAwait(false); - - return result.UserContexts; + return await Broker.ExecuteCommandAsync(new GetUserContextsCommand(), options).ConfigureAwait(false); } public async Task RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null) diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs index 5a1a0a211cf1c..9c86f614f3c51 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs @@ -1,4 +1,5 @@ using OpenQA.Selenium.BiDi.Communication; +using System.Collections; using System.Collections.Generic; namespace OpenQA.Selenium.BiDi.Modules.Browser; @@ -7,4 +8,20 @@ internal class GetUserContextsCommand() : Command(CommandPara public record GetUserContextsOptions : CommandOptions; -public record GetUserContextsResult(IReadOnlyList UserContexts); +public record GetUserContextsResult : IReadOnlyList +{ + private readonly IReadOnlyList _userContexts; + + internal GetUserContextsResult(IReadOnlyList userContexts) + { + _userContexts = userContexts; + } + + public UserContextInfo this[int index] => _userContexts[index]; + + public int Count => _userContexts.Count; + + public IEnumerator GetEnumerator() => _userContexts.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => (_userContexts as IEnumerable).GetEnumerator(); +} From 38531193a0a90bce630dc25970e8ab8c90eae02a Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 4 Oct 2024 23:32:41 +0300 Subject: [PATCH 30/60] LocateNodesResult as enumerable --- .../webdriver/BiDi/Communication/Broker.cs | 1 + .../Enumerable/LocateNodesResultConverter.cs | 24 +++++++++++++++++++ .../BrowsingContext/BrowsingContext.cs | 2 +- .../BrowsingContext/BrowsingContextModule.cs | 6 ++--- .../BrowsingContext/LocateNodesCommand.cs | 19 ++++++++++++++- 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 4ef01829094bf..11e90618742b8 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -72,6 +72,7 @@ public Broker(BiDi bidi, ITransport transport) // Enumerable new Json.Converters.Enumerable.GetCookiesResultConverter(), + new Json.Converters.Enumerable.LocateNodesResultConverter(), new Json.Converters.Enumerable.InputSourceActionsConverter(), new Json.Converters.Enumerable.GetUserContextsResultConverter(), } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs new file mode 100644 index 0000000000000..a8e8328d31a27 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs @@ -0,0 +1,24 @@ +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; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; + +internal class LocateNodesResultConverter : JsonConverter +{ + public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var doc = JsonDocument.ParseValue(ref reader); + var nodes = doc.RootElement.GetProperty("nodes").Deserialize>(options); + + return new LocateNodesResult(nodes); + } + + public override void Write(Utf8JsonWriter writer, LocateNodesResult value, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs index 0f7aa800a1f7d..6d8e17103b965 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs @@ -53,7 +53,7 @@ public Task ActivateAsync(ActivateOptions? options = null) return BiDi.BrowsingContext.ActivateAsync(this, options); } - public Task> LocateNodesAsync(Locator locator, LocateNodesOptions? options = null) + public Task LocateNodesAsync(Locator locator, LocateNodesOptions? options = null) { return BiDi.BrowsingContext.LocateNodesAsync(this, locator, options); } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs index fbba82c5e1dc7..77c77c535d89d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs @@ -42,7 +42,7 @@ public async Task ActivateAsync(BrowsingContext context, ActivateOptions? option await Broker.ExecuteCommandAsync(new ActivateCommand(@params), options).ConfigureAwait(false); } - public async Task> LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null) + public async Task LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null) { var @params = new LocateNodesCommandParameters(context, locator); @@ -53,9 +53,7 @@ public async Task ActivateAsync(BrowsingContext context, ActivateOptions? option @params.StartNodes = options.StartNodes; } - var result = await Broker.ExecuteCommandAsync(new LocateNodesCommand(@params), options).ConfigureAwait(false); - - return result.Nodes; + return await Broker.ExecuteCommandAsync(new LocateNodesCommand(@params), options).ConfigureAwait(false); } public async Task CaptureScreenshotAsync(BrowsingContext context, CaptureScreenshotOptions? options = null) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs index 9abc7708fd6cd..1e3fd34e14fc3 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs @@ -1,4 +1,5 @@ using OpenQA.Selenium.BiDi.Communication; +using System.Collections; using System.Collections.Generic; namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; @@ -23,4 +24,20 @@ public record LocateNodesOptions : CommandOptions public IEnumerable? StartNodes { get; set; } } -public record LocateNodesResult(IReadOnlyList Nodes); +public record LocateNodesResult : IReadOnlyList +{ + private readonly IReadOnlyList _nodes; + + internal LocateNodesResult(IReadOnlyList nodes) + { + _nodes = nodes; + } + + public Script.RemoteValue.Node this[int index] => _nodes[index]; + + public int Count => _nodes.Count; + + public IEnumerator GetEnumerator() => _nodes.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => (_nodes as IEnumerable).GetEnumerator(); +} From 5bc7a3ce992ecbf63ac70a0628604d7aeabb6cf3 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 00:04:53 +0300 Subject: [PATCH 31/60] GetRealmsResult as Enumerable --- .../webdriver/BiDi/Communication/Broker.cs | 1 + .../Enumerable/GetRealmsResultConverter.cs | 23 +++++++++++++++++++ .../BiDi/Modules/Script/GetRealmsCommand.cs | 19 ++++++++++++++- .../BiDi/Modules/Script/ScriptModule.cs | 6 ++--- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 11e90618742b8..690bfc573c023 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -75,6 +75,7 @@ public Broker(BiDi bidi, ITransport transport) new Json.Converters.Enumerable.LocateNodesResultConverter(), new Json.Converters.Enumerable.InputSourceActionsConverter(), new Json.Converters.Enumerable.GetUserContextsResultConverter(), + new Json.Converters.Enumerable.GetRealmsResultConverter(), } }; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs new file mode 100644 index 0000000000000..06fa5b5f3cc4a --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs @@ -0,0 +1,23 @@ +using OpenQA.Selenium.BiDi.Modules.Script; +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; + +internal class GetRealmsResultConverter : JsonConverter +{ + public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var doc = JsonDocument.ParseValue(ref reader); + var realms = doc.RootElement.GetProperty("realms").Deserialize>(options); + + return new GetRealmsResult(realms); + } + + public override void Write(Utf8JsonWriter writer, GetRealmsResult value, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs index 98d4a03ba785f..6aeb9a076d9dc 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs @@ -1,4 +1,5 @@ using OpenQA.Selenium.BiDi.Communication; +using System.Collections; using System.Collections.Generic; namespace OpenQA.Selenium.BiDi.Modules.Script; @@ -19,4 +20,20 @@ public record GetRealmsOptions : CommandOptions public RealmType? Type { get; set; } } -internal record GetRealmsResult(IReadOnlyList Realms); +public record GetRealmsResult : IReadOnlyList +{ + private readonly IReadOnlyList _realms; + + internal GetRealmsResult(IReadOnlyList realms) + { + _realms = realms; + } + + public RealmInfo this[int index] => _realms[index]; + + public int Count => _realms.Count; + + public IEnumerator GetEnumerator() => _realms.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => (_realms as IEnumerable).GetEnumerator(); +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs index 1c02551831d8f..43cfe42075e01 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs @@ -66,7 +66,7 @@ public sealed class ScriptModule(Broker broker) : Module(broker) return result.Result.ConvertTo(); } - public async Task> GetRealmsAsync(GetRealmsOptions? options = null) + public async Task GetRealmsAsync(GetRealmsOptions? options = null) { var @params = new GetRealmsCommandParameters(); @@ -76,9 +76,7 @@ public async Task> GetRealmsAsync(GetRealmsOptions? opt @params.Type = options.Type; } - var result = await Broker.ExecuteCommandAsync(new GetRealmsCommand(@params), options).ConfigureAwait(false); - - return result.Realms; + return await Broker.ExecuteCommandAsync(new GetRealmsCommand(@params), options).ConfigureAwait(false); } public async Task AddPreloadScriptAsync(string functionDeclaration, AddPreloadScriptOptions? options = null) From 497a265cae131480ed5ffe6bb6cc63b36e8441b9 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 01:13:04 +0300 Subject: [PATCH 32/60] Better? --- dotnet/test/common/BiDi/BiDiFixture.cs | 1 + dotnet/test/common/Environment/DriverFactory.cs | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/dotnet/test/common/BiDi/BiDiFixture.cs b/dotnet/test/common/BiDi/BiDiFixture.cs index 7477d7fbd4d99..2253f299828e9 100644 --- a/dotnet/test/common/BiDi/BiDiFixture.cs +++ b/dotnet/test/common/BiDi/BiDiFixture.cs @@ -20,6 +20,7 @@ public async Task BiDiSetUp() var options = new BiDiEnabledDriverOptions() { UseWebSocketUrl = true, + UnhandledPromptBehavior = UnhandledPromptBehavior.Ignore, }; driver = EnvironmentManager.Instance.CreateDriverInstance(options); diff --git a/dotnet/test/common/Environment/DriverFactory.cs b/dotnet/test/common/Environment/DriverFactory.cs index 1451631971997..5708ebda6495d 100644 --- a/dotnet/test/common/Environment/DriverFactory.cs +++ b/dotnet/test/common/Environment/DriverFactory.cs @@ -67,11 +67,6 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO { browser = Browser.Chrome; options = GetDriverOptions(driverType, driverOptions); - //options.UseWebSocketUrl = true; - - // If BiDi is enabled above then the undhandler prompt behaviour needs to set accordingly. - // Reasoning : https://github.com/SeleniumHQ/selenium/pull/14429#issuecomment-2311614822 - options.UnhandledPromptBehavior = UnhandledPromptBehavior.Ignore; var chromeOptions = (ChromeOptions)options; chromeOptions.AddArguments("--no-sandbox", "--disable-dev-shm-usage"); From 54daefa4fc6c8572f8895aaffdbe628180ed5c8e Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:36:20 +0300 Subject: [PATCH 33/60] Should be TestFixture? --- dotnet/test/common/BiDi/BiDiFixture.cs | 2 +- dotnet/test/common/BiDi/Browser/BrowserTest.cs | 2 +- dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs | 2 +- dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs | 2 +- dotnet/test/common/BiDi/Input/DefaultMouseTest.cs | 2 +- dotnet/test/common/BiDi/Log/LogTest.cs | 2 +- dotnet/test/common/BiDi/Network/NetworkEventsTest.cs | 2 +- dotnet/test/common/BiDi/Network/NetworkTest.cs | 2 +- dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs | 2 +- dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs | 2 +- dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs | 2 +- dotnet/test/common/BiDi/Script/ScriptEventsTest.cs | 2 +- dotnet/test/common/BiDi/Storage/StorageTest.cs | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dotnet/test/common/BiDi/BiDiFixture.cs b/dotnet/test/common/BiDi/BiDiFixture.cs index 2253f299828e9..e5c6deece45cb 100644 --- a/dotnet/test/common/BiDi/BiDiFixture.cs +++ b/dotnet/test/common/BiDi/BiDiFixture.cs @@ -6,7 +6,7 @@ namespace OpenQA.Selenium.BiDi; [Parallelizable(ParallelScope.All)] [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] -class BiDiFixture +class BiDiTestFixture { protected IWebDriver driver; protected BiDi bidi; diff --git a/dotnet/test/common/BiDi/Browser/BrowserTest.cs b/dotnet/test/common/BiDi/Browser/BrowserTest.cs index dcf48e71af2a5..74bbd956848a1 100644 --- a/dotnet/test/common/BiDi/Browser/BrowserTest.cs +++ b/dotnet/test/common/BiDi/Browser/BrowserTest.cs @@ -3,7 +3,7 @@ namespace OpenQA.Selenium.BiDi.Browser; -class BrowserTest : BiDiFixture +class BrowserTest : BiDiTestFixture { [Test] public async Task CanCreateUserContext() diff --git a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs index cc55f116d6c23..dba6acad7d37b 100644 --- a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -class BrowsingContextTest : BiDiFixture +class BrowsingContextTest : BiDiTestFixture { [Test] public async Task CanCreateNewTab() diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index 3d8df277d2ded..7f8f194ee2226 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.Input; -class CombinedInputActionsTest : BiDiFixture +class CombinedInputActionsTest : BiDiTestFixture { [Test] public async Task Paint() diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index 967cbb26d78c1..38f6422fbf4b4 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -4,7 +4,7 @@ namespace OpenQA.Selenium.BiDi.Input; -class DefaultMouseTest : BiDiFixture +class DefaultMouseTest : BiDiTestFixture { [Test] public async Task PerformDragAndDropWithMouse() diff --git a/dotnet/test/common/BiDi/Log/LogTest.cs b/dotnet/test/common/BiDi/Log/LogTest.cs index b031d2c9d113d..f67621bfc3b43 100644 --- a/dotnet/test/common/BiDi/Log/LogTest.cs +++ b/dotnet/test/common/BiDi/Log/LogTest.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.Log; -class LogTest : BiDiFixture +class LogTest : BiDiTestFixture { [Test] public async Task CanListenToConsoleLog() diff --git a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs index 81b14cd72cc2f..757cfacab6b79 100644 --- a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs @@ -6,7 +6,7 @@ namespace OpenQA.Selenium.BiDi.Network; -class NetworkEventsTest : BiDiFixture +class NetworkEventsTest : BiDiTestFixture { [Test] public async Task CanListenToBeforeRequestSentEvent() diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index a274f6b63fb26..3c462b4410309 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.Network; -class NetworkTest : BiDiFixture +class NetworkTest : BiDiTestFixture { [Test] public async Task CanAddIntercept() diff --git a/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs index ff19e4fcd4728..3fc11764fca2e 100644 --- a/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs +++ b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs @@ -4,7 +4,7 @@ namespace OpenQA.Selenium.BiDi.Script; -class CallFunctionParameterTest : BiDiFixture +class CallFunctionParameterTest : BiDiTestFixture { [Test] public async Task CanCallFunctionWithDeclaration() diff --git a/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs b/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs index c3d94e1b99fa7..bb526ff9a4d89 100644 --- a/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs +++ b/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs @@ -4,7 +4,7 @@ namespace OpenQA.Selenium.BiDi.Script; -class EvaluateParametersTest : BiDiFixture +class EvaluateParametersTest : BiDiTestFixture { [Test] public async Task CanEvaluateScript() diff --git a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs index 83264a0082e8e..f98e44409de02 100644 --- a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs +++ b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.Script; -class ScriptCommandsTest : BiDiFixture +class ScriptCommandsTest : BiDiTestFixture { [Test] public async Task CanGetAllRealms() diff --git a/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs b/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs index 4f995b54ced26..48fc3b5686371 100644 --- a/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs +++ b/dotnet/test/common/BiDi/Script/ScriptEventsTest.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.Script; -class ScriptEventsTest : BiDiFixture +class ScriptEventsTest : BiDiTestFixture { [Test] public async Task CanListenToChannelMessage() diff --git a/dotnet/test/common/BiDi/Storage/StorageTest.cs b/dotnet/test/common/BiDi/Storage/StorageTest.cs index 83e463af9ea02..2f9877c4ca1aa 100644 --- a/dotnet/test/common/BiDi/Storage/StorageTest.cs +++ b/dotnet/test/common/BiDi/Storage/StorageTest.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.Storage; -class StorageTest : BiDiFixture +class StorageTest : BiDiTestFixture { [Test] public async Task CanGetCookieByName() From 0135519827ffa8ab0cdf5c119c229e2df2e6528d Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:47:10 +0300 Subject: [PATCH 34/60] And make fixture public magically --- dotnet/test/common/BiDi/BiDiFixture.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/common/BiDi/BiDiFixture.cs b/dotnet/test/common/BiDi/BiDiFixture.cs index e5c6deece45cb..b7bf01de81b52 100644 --- a/dotnet/test/common/BiDi/BiDiFixture.cs +++ b/dotnet/test/common/BiDi/BiDiFixture.cs @@ -6,7 +6,7 @@ namespace OpenQA.Selenium.BiDi; [Parallelizable(ParallelScope.All)] [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] -class BiDiTestFixture +public class BiDiTestFixture { protected IWebDriver driver; protected BiDi bidi; From 2ff0b5c4a8077d7c8a8f7be016dd0afa6f883e35 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:20:40 +0300 Subject: [PATCH 35/60] Fix CanListenToFetchError test --- dotnet/test/common/BiDi/Network/NetworkEventsTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs index 757cfacab6b79..f5a92ed3f6344 100644 --- a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs @@ -127,6 +127,6 @@ public async Task CanListenToFetchError() Assert.That(res.Request.Url, Does.Contain("https://not_a_valid_url.test")); Assert.That(res.Request.Headers.Count, Is.GreaterThanOrEqualTo(1)); Assert.That(res.Navigation, Is.Not.Null); - Assert.That(res.ErrorText, Does.Contain("net::ERR_NAME_NOT_RESOLVED")); + Assert.That(res.ErrorText, Does.Contain("net::ERR_NAME_NOT_RESOLVED").Or.Contain("NS_ERROR_UNKNOWN_HOST")); } } From 40653422d7c8f74536ae9789b845df2b0f2c810b Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:24:30 +0300 Subject: [PATCH 36/60] Fix CanListenToOnAuthRequiredEvent test --- dotnet/test/common/BiDi/Network/NetworkEventsTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs index f5a92ed3f6344..230351ba436df 100644 --- a/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkEventsTest.cs @@ -102,7 +102,7 @@ public async Task CanListenToOnAuthRequiredEvent() Assert.That(res.Request, Is.Not.Null); Assert.That(res.Request.Method, Is.EqualTo("GET")); Assert.That(res.Request.Url, Does.Contain("basicAuth")); - Assert.That(res.Response.Headers, Is.GreaterThanOrEqualTo(1)); + Assert.That(res.Response.Headers, Is.Not.Null.And.Count.GreaterThanOrEqualTo(1)); Assert.That(res.Response.Status, Is.EqualTo(401)); } From 042fd7c680c8e5adf343df1dc3062cd546c2280e Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:25:37 +0300 Subject: [PATCH 37/60] Remove demo test --- dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index 7f8f194ee2226..6dfcfa90324d6 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -7,7 +7,7 @@ namespace OpenQA.Selenium.BiDi.Input; class CombinedInputActionsTest : BiDiTestFixture { - [Test] + //[Test] public async Task Paint() { driver.Url = "https://kleki.com/"; From a295033ff4fc44fd7ff71b9d9c5de39ab29a0054 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:28:29 +0300 Subject: [PATCH 38/60] Fix CanFailRequest test --- dotnet/test/common/BiDi/Network/NetworkTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index 3c462b4410309..8c9836f1a404b 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -188,6 +188,6 @@ public async Task CanFailRequest() var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete }); - Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_FAILED")); + Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_FAILED").Or.Contain("NS_ERROR_ABORT")); } } From 19edb164abff9b57bd12ef5c8f140ab026c62f7a Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:33:01 +0300 Subject: [PATCH 39/60] Update ScriptCommandsTest.cs --- dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs index f98e44409de02..c013fbbbed2d4 100644 --- a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs +++ b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs @@ -78,7 +78,7 @@ public async Task CanAddPreloadScript() await context.Log.OnEntryAddedAsync(tcs.SetResult); - await context.ReloadAsync(); + await context.ReloadAsync(new() { Wait = Modules.BrowsingContext.ReadinessState.Interactive }); var entry = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5)); @@ -123,7 +123,7 @@ public async Task CanAddPreloadScriptInASandbox() Assert.That(preloadScript, Is.Not.Null); - await context.ReloadAsync(); + await context.ReloadAsync(new() { Wait = Modules.BrowsingContext.ReadinessState.Interactive }); var bar = await context.Script.EvaluateAsync("window.bar", true, targetOptions: new() { Sandbox = "sandbox" }); @@ -135,7 +135,7 @@ public async Task CanRemovePreloadedScript() { var preloadScript = await context.Script.AddPreloadScriptAsync("() => { window.bar = 2; }"); - await context.ReloadAsync(); + await context.ReloadAsync(new() { Wait = Modules.BrowsingContext.ReadinessState.Interactive }); var bar = await context.Script.EvaluateAsync("window.bar", true); From 7b7552a5b94a4868f5cb38120056d6e64b0ee4dc Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:41:55 +0300 Subject: [PATCH 40/60] Fix CanFailRequest test --- dotnet/test/common/BiDi/Network/NetworkTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index 8c9836f1a404b..d5e6c8abdf06c 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -188,6 +188,6 @@ public async Task CanFailRequest() var action = async () => await context.NavigateAsync(UrlBuilder.WhereIs("basicAuth"), new() { Wait = ReadinessState.Complete }); - Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_FAILED").Or.Contain("NS_ERROR_ABORT")); + Assert.That(action, Throws.TypeOf().With.Message.Contain("net::ERR_FAILED").Or.Message.Contain("NS_ERROR_ABORT")); } } From 8705113316d5f42f3f2729955030cf3c2abcd6c6 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:56:10 +0300 Subject: [PATCH 41/60] Ignore auth req continue for firefox --- dotnet/test/common/BiDi/Network/NetworkTest.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index d5e6c8abdf06c..b743378c385ea 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -153,6 +153,7 @@ public async Task CanContinueWithAuthCredentials() } [Test] + [IgnoreBrowser(Selenium.Browser.Firefox)] public async Task CanContinueWithDefaultCredentials() { await using var intercept = await bidi.Network.InterceptAuthAsync(async e => @@ -166,6 +167,7 @@ public async Task CanContinueWithDefaultCredentials() } [Test] + [IgnoreBrowser(Selenium.Browser.Firefox)] public async Task CanContinueWithCanceledCredentials() { await using var intercept = await bidi.Network.InterceptAuthAsync(async e => From c760369e3ec7e677602475416038c0fce5e55e62 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:49:14 +0300 Subject: [PATCH 42/60] Don't output command length in logs --- .../BiDi/Communication/Transport/WebSocketTransport.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs b/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs index 52cd5c0ffa7f2..2d3c427bf7d2b 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs @@ -59,7 +59,7 @@ public async Task SendAsJsonAsync(Command command, JsonSerializerOptions jsonSer { if (_logger.IsEnabled(LogEventLevel.Trace)) { - _logger.Trace($"BiDi SND >> {buffer.Length} > {Encoding.UTF8.GetString(buffer)}"); + _logger.Trace($"BiDi SND >> {Encoding.UTF8.GetString(buffer)}"); } await _webSocket.SendAsync(new ArraySegment(buffer), WebSocketMessageType.Text, true, cancellationToken).ConfigureAwait(false); From e4d91caf31f8826d91c3f11b236c184a087eb369 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:53:15 +0300 Subject: [PATCH 43/60] Hide transport --- dotnet/src/webdriver/BiDi/Communication/Broker.cs | 2 +- dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs | 2 +- .../BiDi/Communication/Transport/WebSocketTransport.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 690bfc573c023..259e66962c2b7 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -34,7 +34,7 @@ public class Broker : IAsyncDisposable private readonly JsonSerializerOptions _jsonSerializerOptions; - public Broker(BiDi bidi, ITransport transport) + internal Broker(BiDi bidi, ITransport transport) { _bidi = bidi; _transport = transport; diff --git a/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs b/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs index 404d62734f9d2..dfa24da5738ec 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs @@ -5,7 +5,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Transport; -public interface ITransport : IDisposable +interface ITransport : IDisposable { Task ConnectAsync(CancellationToken cancellationToken); diff --git a/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs b/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs index 2d3c427bf7d2b..ff338c9ea13ed 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs @@ -9,7 +9,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Transport; -public class WebSocketTransport(Uri _uri) : ITransport, IDisposable +class WebSocketTransport(Uri _uri) : ITransport, IDisposable { private readonly static ILogger _logger = Log.GetLogger(); From b64ea0447b3d7f7e42a8846741c85ed81e3d1f2b Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 19:15:09 +0300 Subject: [PATCH 44/60] Enable nullable context for bidi namespace --- dotnet/src/webdriver/BiDi/BiDi.cs | 2 ++ dotnet/src/webdriver/BiDi/BiDiException.cs | 2 ++ dotnet/src/webdriver/BiDi/Communication/Broker.cs | 2 ++ dotnet/src/webdriver/BiDi/Communication/Command.cs | 2 ++ dotnet/src/webdriver/BiDi/Communication/CommandOptions.cs | 2 ++ dotnet/src/webdriver/BiDi/Communication/EventHandler.cs | 2 ++ .../Json/Converters/BrowserUserContextConverter.cs | 2 ++ .../Communication/Json/Converters/BrowsingContextConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/ChannelConverter.cs | 2 ++ .../Communication/Json/Converters/DateTimeOffsetConverter.cs | 2 ++ .../Json/Converters/Enumerable/GetCookiesResultConverter.cs | 2 ++ .../Json/Converters/Enumerable/GetRealmsResultConverter.cs | 2 ++ .../Converters/Enumerable/GetUserContextsResultConverter.cs | 2 ++ .../Json/Converters/Enumerable/InputSourceActionsConverter.cs | 2 ++ .../Json/Converters/Enumerable/LocateNodesResultConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/HandleConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/InputOriginConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/InterceptConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/InternalIdConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/NavigationConverter.cs | 2 ++ .../Json/Converters/Polymorphic/EvaluateResultConverter.cs | 2 ++ .../Json/Converters/Polymorphic/LogEntryConverter.cs | 2 ++ .../Json/Converters/Polymorphic/MessageConverter.cs | 2 ++ .../Json/Converters/Polymorphic/RealmInfoConverter.cs | 2 ++ .../Json/Converters/Polymorphic/RemoteValueConverter.cs | 2 ++ .../Communication/Json/Converters/PreloadScriptConverter.cs | 2 ++ .../Communication/Json/Converters/PrintPageRangeConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/RealmConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/RealmTypeConverter.cs | 2 ++ .../BiDi/Communication/Json/Converters/RequestConverter.cs | 2 ++ dotnet/src/webdriver/BiDi/Communication/Message.cs | 2 ++ dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs | 2 ++ .../BiDi/Communication/Transport/WebSocketTransport.cs | 2 ++ dotnet/src/webdriver/BiDi/EventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Browser/CloseCommand.cs | 2 ++ .../webdriver/BiDi/Modules/Browser/CreateUserContextCommand.cs | 2 ++ .../webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs | 2 ++ .../webdriver/BiDi/Modules/Browser/RemoveUserContextCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs | 2 ++ .../webdriver/BiDi/Modules/BrowsingContext/ActivateCommand.cs | 2 ++ .../webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs | 2 ++ .../BiDi/Modules/BrowsingContext/BrowsingContextInfo.cs | 2 ++ .../BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs | 2 ++ .../BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs | 2 ++ .../BiDi/Modules/BrowsingContext/BrowsingContextModule.cs | 2 ++ .../Modules/BrowsingContext/BrowsingContextNetworkModule.cs | 2 ++ .../BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs | 2 ++ .../Modules/BrowsingContext/BrowsingContextStorageModule.cs | 2 ++ .../BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs | 2 ++ .../src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs | 2 ++ .../src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs | 2 ++ .../webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs | 2 ++ .../BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs | 2 ++ .../BiDi/Modules/BrowsingContext/LocateNodesCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs | 2 ++ .../webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Navigation.cs | 2 ++ .../webdriver/BiDi/Modules/BrowsingContext/NavigationInfo.cs | 2 ++ .../src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs | 2 ++ .../src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs | 2 ++ .../BiDi/Modules/BrowsingContext/SetViewportCommand.cs | 2 ++ .../BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs | 2 ++ .../BiDi/Modules/BrowsingContext/UserPromptClosedEventArgs.cs | 2 ++ .../BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs | 2 ++ .../src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs | 2 ++ .../src/webdriver/BiDi/Modules/Input/ReleaseActionsCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Module.cs | 2 ++ .../src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/AuthChallenge.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs | 2 ++ .../src/webdriver/BiDi/Modules/Network/AuthRequiredEventArgs.cs | 2 ++ .../webdriver/BiDi/Modules/Network/BaseParametersEventArgs.cs | 2 ++ .../BiDi/Modules/Network/BeforeRequestSentEventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs | 2 ++ .../webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs | 2 ++ .../webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs | 2 ++ .../webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/CookieHeader.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/FailRequestCommand.cs | 2 ++ .../src/webdriver/BiDi/Modules/Network/FetchErrorEventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/FetchTimingInfo.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/Header.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs | 2 ++ .../webdriver/BiDi/Modules/Network/ProvideResponseCommand.cs | 2 ++ .../webdriver/BiDi/Modules/Network/RemoveInterceptCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/Request.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/RequestData.cs | 2 ++ .../BiDi/Modules/Network/ResponseCompletedEventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/ResponseContent.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/ResponseData.cs | 2 ++ .../webdriver/BiDi/Modules/Network/ResponseStartedEventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/SetCookieHeader.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs | 2 ++ .../webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/DisownCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/Handle.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/InternalId.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/Realm.cs | 2 ++ .../webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/RemoteReference.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs | 2 ++ .../webdriver/BiDi/Modules/Script/RemovePreloadScriptCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs | 2 ++ .../webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs | 2 ++ .../src/webdriver/BiDi/Modules/Script/SerializationOptions.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/Source.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/StackFrame.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/StackTrace.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Script/Target.cs | 2 ++ .../src/webdriver/BiDi/Modules/Session/CapabilitiesRequest.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/CapabilityRequest.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/EndCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs | 2 ++ .../src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs | 2 ++ dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs | 2 ++ dotnet/src/webdriver/BiDi/Subscription.cs | 2 ++ dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs | 2 ++ 146 files changed, 292 insertions(+) diff --git a/dotnet/src/webdriver/BiDi/BiDi.cs b/dotnet/src/webdriver/BiDi/BiDi.cs index dfc992e233c60..34a9452dec144 100644 --- a/dotnet/src/webdriver/BiDi/BiDi.cs +++ b/dotnet/src/webdriver/BiDi/BiDi.cs @@ -3,6 +3,8 @@ using OpenQA.Selenium.BiDi.Communication; using OpenQA.Selenium.BiDi.Communication.Transport; +#nullable enable + namespace OpenQA.Selenium.BiDi; public class BiDi : IAsyncDisposable diff --git a/dotnet/src/webdriver/BiDi/BiDiException.cs b/dotnet/src/webdriver/BiDi/BiDiException.cs index 7f2ddd5b59cbc..6959645111b01 100644 --- a/dotnet/src/webdriver/BiDi/BiDiException.cs +++ b/dotnet/src/webdriver/BiDi/BiDiException.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace OpenQA.Selenium.BiDi; public class BiDiException : Exception diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 259e66962c2b7..5f8a0983846c9 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -10,6 +10,8 @@ using System.Threading; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication; public class Broker : IAsyncDisposable diff --git a/dotnet/src/webdriver/BiDi/Communication/Command.cs b/dotnet/src/webdriver/BiDi/Communication/Command.cs index bfa7113512068..729b319cc03ec 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Command.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Command.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication; [JsonPolymorphic(TypeDiscriminatorPropertyName = "method")] diff --git a/dotnet/src/webdriver/BiDi/Communication/CommandOptions.cs b/dotnet/src/webdriver/BiDi/Communication/CommandOptions.cs index 93cc63fc2ebfc..ffb6616ae9cef 100644 --- a/dotnet/src/webdriver/BiDi/Communication/CommandOptions.cs +++ b/dotnet/src/webdriver/BiDi/Communication/CommandOptions.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication; public record CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Communication/EventHandler.cs b/dotnet/src/webdriver/BiDi/Communication/EventHandler.cs index 4aab8620e3f2b..ce5444eb0d9fd 100644 --- a/dotnet/src/webdriver/BiDi/Communication/EventHandler.cs +++ b/dotnet/src/webdriver/BiDi/Communication/EventHandler.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication; public abstract class EventHandler(string eventName, Type eventArgsType, IEnumerable? contexts = null) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowserUserContextConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowserUserContextConverter.cs index 7997f7c0f1541..3d478cf5d9f69 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowserUserContextConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowserUserContextConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class BrowserUserContextConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowsingContextConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowsingContextConverter.cs index 2718700f3ffac..8c1a928ef19ad 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowsingContextConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/BrowsingContextConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class BrowsingContextConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs index 9771436eb8151..ac35a22fcc2c4 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class ChannelConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs index 9d87f0f17342e..ff9b6258d3a69 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs @@ -2,6 +2,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class DateTimeOffsetConverter : JsonConverter 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 56beaa1d38d50..4f914058057f2 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs @@ -4,6 +4,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; internal class GetCookiesResultConverter : JsonConverter 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 06fa5b5f3cc4a..810a816dce247 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs @@ -4,6 +4,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; internal class GetRealmsResultConverter : JsonConverter 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 f31cc6c1eb5f0..00b2d561c65a9 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs @@ -4,6 +4,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; internal class GetUserContextsResultConverter : JsonConverter 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 204eb5d7f216f..46e1f7ce48ae8 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; internal class InputSourceActionsConverter : JsonConverter 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 a8e8328d31a27..b2a8bcb36e965 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs @@ -5,6 +5,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; internal class LocateNodesResultConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/HandleConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/HandleConverter.cs index 71e0ed6e5ae51..2117bb72fa519 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/HandleConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/HandleConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class HandleConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs index 48d40367b0603..c544362ccccd8 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class InputOriginConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InterceptConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InterceptConverter.cs index 3a207a89116c2..3fd062b22fae3 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InterceptConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InterceptConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class InterceptConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InternalIdConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InternalIdConverter.cs index 9271a1877be71..7edcaa7543464 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InternalIdConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InternalIdConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class InternalIdConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/NavigationConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/NavigationConverter.cs index 040e7fb723919..e61d300f18f56 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/NavigationConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/NavigationConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class NavigationConverter : JsonConverter 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 3d8669c372ebf..ac0fd1a7bbfcc 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 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 edcfd2446b691..e5ccbac46f326 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 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 6164dcc04690d..b9d86ae634902 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/MessageConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/MessageConverter.cs @@ -2,6 +2,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 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 c77fed7e976a7..9824377ca47ac 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 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 f27d56c379afa..4635954026afc 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic; // https://github.com/dotnet/runtime/issues/72604 diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PreloadScriptConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PreloadScriptConverter.cs index 53dba4b424388..4b68ce22c52ff 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PreloadScriptConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PreloadScriptConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class PreloadScriptConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PrintPageRangeConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PrintPageRangeConverter.cs index afd375d078a59..76ffd9b34ad4e 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PrintPageRangeConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/PrintPageRangeConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class PrintPageRangeConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmConverter.cs index ab2baedc6fd28..60cde6d1152db 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class RealmConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs index af9d5c059c310..048250fd526d5 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class RealmTypeConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RequestConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RequestConverter.cs index 7a15a569faa06..0524246d6b3b3 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RequestConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/RequestConverter.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; internal class RequestConverter : JsonConverter diff --git a/dotnet/src/webdriver/BiDi/Communication/Message.cs b/dotnet/src/webdriver/BiDi/Communication/Message.cs index 75925ed4d7592..c00a2777a33f4 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Message.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Message.cs @@ -1,5 +1,7 @@ using System.Text.Json; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication; // https://github.com/dotnet/runtime/issues/72604 diff --git a/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs b/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs index dfa24da5738ec..3ed6d2e32a4cf 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs @@ -3,6 +3,8 @@ using System.Threading; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Transport; interface ITransport : IDisposable diff --git a/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs b/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs index ff338c9ea13ed..76384f51b1261 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs @@ -7,6 +7,8 @@ using System.Text; using OpenQA.Selenium.Internal.Logging; +#nullable enable + namespace OpenQA.Selenium.BiDi.Communication.Transport; class WebSocketTransport(Uri _uri) : ITransport, IDisposable diff --git a/dotnet/src/webdriver/BiDi/EventArgs.cs b/dotnet/src/webdriver/BiDi/EventArgs.cs index 01d5cd3280acf..30361ca95e6cb 100644 --- a/dotnet/src/webdriver/BiDi/EventArgs.cs +++ b/dotnet/src/webdriver/BiDi/EventArgs.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi; public abstract record EventArgs(BiDi BiDi) diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs index de8a8dbce9c18..ba7fb0496dd6d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Browser; public sealed class BrowserModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/CloseCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/CloseCommand.cs index 345a3c5a22935..59f9db7374929 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/CloseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/CloseCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Browser; internal class CloseCommand() : Command(CommandParameters.Empty); diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/CreateUserContextCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/CreateUserContextCommand.cs index 9b84d1ee11532..ce44e5ae2f367 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/CreateUserContextCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/CreateUserContextCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Browser; internal class CreateUserContextCommand() : Command(CommandParameters.Empty); diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs index 9c86f614f3c51..161a1bf286f1e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Browser; internal class GetUserContextsCommand() : Command(CommandParameters.Empty); diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/RemoveUserContextCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/RemoveUserContextCommand.cs index b937ad48ffc80..7877eb0f710ff 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/RemoveUserContextCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/RemoveUserContextCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Browser; internal class RemoveUserContextCommand(RemoveUserContextCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs index 49ba71eef3f1d..a2e689d494aaa 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs @@ -1,6 +1,8 @@ using System; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Browser; public class UserContext : IAsyncDisposable diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs index 7f4949b49a2fa..99b7e59a486b2 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Browser; public record UserContextInfo(UserContext UserContext); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ActivateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ActivateCommand.cs index f05354060e89a..4934e51b815bd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ActivateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ActivateCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class ActivateCommand(ActivateCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs index 6d8e17103b965..e83f671ae227e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContext diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInfo.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInfo.cs index 52f2edeb972e0..f2303915feb90 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInfo.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; // TODO: Split it to separate class with just info and event args diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs index d0c51b8f1584b..919758b14ba79 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs @@ -2,6 +2,8 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextInputModule(BrowsingContext context, InputModule inputModule) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs index d95422f0c04e8..031b579f4b7f5 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextLogModule(BrowsingContext context, LogModule logModule) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs index 77c77c535d89d..690df63f7ab2d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs index 72fd7c2e3daa9..e25f255f423c7 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs @@ -2,6 +2,8 @@ using System; using OpenQA.Selenium.BiDi.Modules.Network; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextNetworkModule(BrowsingContext context, NetworkModule networkModule) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs index 6e4b4f0b8cda8..f6f8b77e43c55 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs @@ -2,6 +2,8 @@ using OpenQA.Selenium.BiDi.Modules.Script; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextScriptModule(BrowsingContext context, ScriptModule scriptModule) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs index 1c425302f5f00..d89343d1ab0f9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs @@ -1,6 +1,8 @@ using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Modules.Storage; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextStorageModule(BrowsingContext context, StorageModule storageModule) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 3774716518d29..e71311da58f23 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class CaptureScreenshotCommand(CaptureScreenshotCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs index ac531a28699ac..e3f3279a97955 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class CloseCommand(CloseCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs index 86a81bcada46a..a70f89726c364 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class CreateCommand(CreateCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs index fe6a38c1fe0bc..eb03c29856266 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class GetTreeCommand(GetTreeCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs index 2dd2888d19a87..a566ef6edf963 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; class HandleUserPromptCommand(HandleUserPromptCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs index 1e3fd34e14fc3..d32188ae7cce3 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class LocateNodesCommand(LocateNodesCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index ada22f9d6f331..6a52079e6d155 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs index 401c0ec2093d4..7481a6141e430 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class NavigateCommand(NavigateCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Navigation.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Navigation.cs index 0b56229ade1de..3ce169d0f40c6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Navigation.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Navigation.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public record Navigation(string Id); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigationInfo.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigationInfo.cs index fe7a83399bf11..e934e3030d305 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigationInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigationInfo.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public record NavigationInfo(BiDi BiDi, BrowsingContext Context, Navigation Navigation, DateTimeOffset Timestamp, string Url) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs index 66c270c12dd97..70fa6bcdd1f2a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class PrintCommand(PrintCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs index fea265ce15200..1dd805fd0a00b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class ReloadCommand(ReloadCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs index 0ed6e869e85a7..a43cb30157e15 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class SetViewportCommand(SetViewportCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs index 65797e0164cd0..b8c78b2601adb 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class TraverseHistoryCommand(TraverseHistoryCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptClosedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptClosedEventArgs.cs index fa59f7262fcc2..c7123e89f76be 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptClosedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptClosedEventArgs.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public record UserPromptClosedEventArgs(BiDi BiDi, BrowsingContext Context, bool Accepted) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs index 8e6658bd79523..03dd37be8cbeb 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public record UserPromptOpenedEventArgs(BiDi BiDi, BrowsingContext Context, UserPromptType Type, string Message) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs index 94764ba1cd9b8..53f913132c758 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Input; public sealed class InputModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs b/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs index d611f9769c7e3..f6716336dcc2a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Input; public abstract record Origin diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs index 8d427d42be58d..878b576417fba 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Input; internal class PerformActionsCommand(PerformActionsCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/ReleaseActionsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Input/ReleaseActionsCommand.cs index 0ee6d6345d21b..2331e1bec6c49 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/ReleaseActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/ReleaseActionsCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Input; internal class ReleaseActionsCommand(ReleaseActionsCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 8de0b3cae326d..025bde9c82965 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Input; public abstract record SourceActions diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs index 3cfbb52857641..dba3714e27403 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Log; // https://github.com/dotnet/runtime/issues/72604 diff --git a/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs b/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs index 1e89279912ea1..aeb09a08754bd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs @@ -2,6 +2,8 @@ using System; using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Log; public sealed class LogModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/Module.cs b/dotnet/src/webdriver/BiDi/Modules/Module.cs index a6ac7d1719c43..a7c2491349750 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Module.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Module.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules; public abstract class Module(Broker broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs index 4856193d512d9..219f3640ca466 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; internal class AddInterceptCommand(AddInterceptCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AuthChallenge.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AuthChallenge.cs index b304cbacf3f1e..f85da002f189e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AuthChallenge.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AuthChallenge.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record AuthChallenge(string Scheme, string Realm); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs index 51725de887f40..8f78b5465f969 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AuthRequiredEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AuthRequiredEventArgs.cs index 6e3e8626e8b5f..dca341b07b4da 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AuthRequiredEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AuthRequiredEventArgs.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record AuthRequiredEventArgs(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, BrowsingContext.Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, ResponseData Response) : diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/BaseParametersEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Network/BaseParametersEventArgs.cs index d632e433e137d..e8e721d033ca5 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/BaseParametersEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/BaseParametersEventArgs.cs @@ -2,6 +2,8 @@ using System.Text.Json.Serialization; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public abstract record BaseParametersEventArgs(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, BrowsingContext.Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/BeforeRequestSentEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Network/BeforeRequestSentEventArgs.cs index 0ca4994bd7bae..53f4b85aa3669 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/BeforeRequestSentEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/BeforeRequestSentEventArgs.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record BeforeRequestSentEventArgs(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, Initiator Initiator) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs b/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs index 355324d621cee..6c5d88a930d66 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs index bdf572ece2c08..447dfa41baa70 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; internal class ContinueRequestCommand(ContinueRequestCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs index 6762035e94e38..ba2e4e60a1bed 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; internal class ContinueResponseCommand(ContinueResponseCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs index f592c399d7404..fd1fbc38f76ea 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; internal class ContinueWithAuthCommand(ContinueWithAuthParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs index 0c615762e7044..f3a4bedc8f926 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs @@ -1,6 +1,8 @@ using System; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record Cookie(string Name, BytesValue Value, string Domain, string Path, long Size, bool HttpOnly, bool Secure, SameSite SameSite) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/CookieHeader.cs b/dotnet/src/webdriver/BiDi/Modules/Network/CookieHeader.cs index dac9bd7b8260a..e588a87d0acb8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/CookieHeader.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/CookieHeader.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record CookieHeader(string Name, BytesValue Value); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/FailRequestCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/FailRequestCommand.cs index fe25e4904e34f..f3b01ee692743 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/FailRequestCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/FailRequestCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; internal class FailRequestCommand(FailRequestCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/FetchErrorEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Network/FetchErrorEventArgs.cs index ce77fbed5216c..6c911e0009fa7 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/FetchErrorEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/FetchErrorEventArgs.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record FetchErrorEventArgs(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, string ErrorText) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/FetchTimingInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Network/FetchTimingInfo.cs index d1b8caf24e5ca..d5980cc2ca141 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/FetchTimingInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/FetchTimingInfo.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record FetchTimingInfo(double TimeOrigin, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Header.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Header.cs index d32397f88dbd3..0804a1919dec0 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Header.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Header.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record Header(string Name, BytesValue Value); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs index 128b69f5097cf..a1449e77928a2 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record Initiator(InitiatorType Type) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs index 26d71006cc03f..65ff717b08349 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs @@ -3,6 +3,8 @@ using System.Linq; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public class Intercept : IAsyncDisposable diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs index 3df8b5de3d01b..7d4eac19a673f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public sealed class NetworkModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ProvideResponseCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ProvideResponseCommand.cs index 317ac4474b4fa..6dae6fc24556f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ProvideResponseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ProvideResponseCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; internal class ProvideResponseCommand(ProvideResponseCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/RemoveInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/RemoveInterceptCommand.cs index de64aa1200fb7..c592b74e13a1a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/RemoveInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/RemoveInterceptCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; internal class RemoveInterceptCommand(RemoveInterceptCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Request.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Request.cs index 1b68df0768897..f7b93fbebff19 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Request.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Request.cs @@ -1,5 +1,7 @@ using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public class Request diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/RequestData.cs b/dotnet/src/webdriver/BiDi/Modules/Network/RequestData.cs index 442db03520234..01cc77f040e79 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/RequestData.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/RequestData.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record RequestData(Request Request, string Url, string Method, IReadOnlyList
Headers, IReadOnlyList Cookies, long HeadersSize, long? BodySize, FetchTimingInfo Timings); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseCompletedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseCompletedEventArgs.cs index 81fec792efdfd..75c9aa21332bd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseCompletedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseCompletedEventArgs.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record ResponseCompletedEventArgs(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, ResponseData Response) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseContent.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseContent.cs index 9647356e7b052..5511c4b24129f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseContent.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseContent.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record ResponseContent(long Size); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseData.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseData.cs index 5ac779301b9ab..6096bda7fd8a6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseData.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseData.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record ResponseData(string Url, diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseStartedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseStartedEventArgs.cs index 0c80739bf4c72..aa3aff6fd5cf9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ResponseStartedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ResponseStartedEventArgs.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record ResponseStartedEventArgs(BiDi BiDi, BrowsingContext.BrowsingContext Context, bool IsBlocked, Navigation Navigation, long RedirectCount, RequestData Request, DateTimeOffset Timestamp, ResponseData Response) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/SetCookieHeader.cs b/dotnet/src/webdriver/BiDi/Modules/Network/SetCookieHeader.cs index d11d8ee8a21e5..a73c9171419f0 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/SetCookieHeader.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/SetCookieHeader.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; public record SetCookieHeader(string Name, BytesValue Value) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs b/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs index 97bdba38e8302..ceda0487aae01 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Network; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs index 4868765895b05..512d79a86900e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; internal class AddPreloadScriptCommand(AddPreloadScriptCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs index 08c9800911044..9ff03a72896f4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; internal class CallFunctionCommand(CallFunctionCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs index 6562ac429655d..6518aee1d5388 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public record Channel(string Id); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/DisownCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/DisownCommand.cs index dfe04fc14e0be..b09ab31da07b3 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/DisownCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/DisownCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; internal class DisownCommand(DisownCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs index 266bac742a2b1..8ccba001543af 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; internal class EvaluateCommand(EvaluateCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs index 6aeb9a076d9dc..e5730a9d21a06 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; internal class GetRealmsCommand(GetRealmsCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Handle.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Handle.cs index 2e2649af926cf..8323bea292827 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Handle.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Handle.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public class Handle diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/InternalId.cs b/dotnet/src/webdriver/BiDi/Modules/Script/InternalId.cs index 89e08f58f9121..1a34d8bd61bb5 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/InternalId.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/InternalId.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public class InternalId diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs index 30cd1ea0868b5..2b162c438dd3d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs index 14dbea46ed3a6..e6062a76262c1 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/MessageEventArgs.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public record MessageEventArgs(BiDi BiDi, Channel Channel, RemoteValue Data, Source Source) : EventArgs(BiDi); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs b/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs index dd695a171128b..5cc214fcd225c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public record NodeProperties(long NodeType, long ChildNodeCount) diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs b/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs index 8533b2ddb494e..1b9027f21cf39 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs @@ -1,6 +1,8 @@ using System; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public class PreloadScript : IAsyncDisposable diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Realm.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Realm.cs index 0b8bf28fdf994..a690df5eabd91 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Realm.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Realm.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public class Realm diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs index 03f61a744b95b..b5d30f09c5fd3 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmDestroyedEventArgs.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public record RealmDestroyedEventArgs(BiDi BiDi, Realm Realm) : EventArgs(BiDi); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs index 0bc703d8217db..4715be57392a7 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; // https://github.com/dotnet/runtime/issues/72604 diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs index 0db521054c4d9..08444b2666830 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RealmType.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public enum RealmType diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteReference.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteReference.cs index f936501b0cb14..ac64940070e7e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteReference.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteReference.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public abstract record RemoteReference : LocalValue; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index b288b8d83958d..074ab2570b43e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -3,6 +3,8 @@ using System.Text.Json; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; // https://github.com/dotnet/runtime/issues/72604 diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemovePreloadScriptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemovePreloadScriptCommand.cs index a64d5dd42775c..850ab9ecc0f6c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemovePreloadScriptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemovePreloadScriptCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; internal class RemovePreloadScriptCommand(RemovePreloadScriptCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs index 68e77e72a1f01..c69595bc3293c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ResultOwnership.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public enum ResultOwnership diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs index a4a3dcaef76f7..4daa2cc704b1c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public class ScriptEvaluateException(EvaluateResult.Exception evaluateResultException) : Exception diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs index 43cfe42075e01..fee6e4a10dcfc 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public sealed class ScriptModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs index 57659570eaaf4..bbb275cc08c2f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public class SerializationOptions diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Source.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Source.cs index 309ac31a0ba75..27bdbcad6f695 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Source.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Source.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public record Source(Realm Realm) diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/StackFrame.cs b/dotnet/src/webdriver/BiDi/Modules/Script/StackFrame.cs index 7e3694e9a5e68..208485e0bd636 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/StackFrame.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/StackFrame.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public record StackFrame(long LineNumber, long ColumnNumber, string Url, string FunctionName); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/StackTrace.cs b/dotnet/src/webdriver/BiDi/Modules/Script/StackTrace.cs index b9ec5c6bf1d0a..15bbfd829bb1e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/StackTrace.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/StackTrace.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; public record StackTrace(IReadOnlyCollection CallFrames); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs index efbb1191fe7ab..667bfe873880f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Script; [JsonDerivedType(typeof(Realm))] diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/CapabilitiesRequest.cs b/dotnet/src/webdriver/BiDi/Modules/Session/CapabilitiesRequest.cs index be4c7ac6d69db..542f9e1c3f076 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/CapabilitiesRequest.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/CapabilitiesRequest.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; public class CapabilitiesRequest diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/CapabilityRequest.cs b/dotnet/src/webdriver/BiDi/Modules/Session/CapabilityRequest.cs index 1cd33a08be0ad..b449e984bb540 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/CapabilityRequest.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/CapabilityRequest.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; public class CapabilityRequest diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/EndCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/EndCommand.cs index 73180d2cd6bda..a41d0be7c2ded 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/EndCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/EndCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; internal class EndCommand() : Command(CommandParameters.Empty); diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs index 3c965e0f1d505..97759165116a2 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; internal class NewCommand(NewCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs b/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs index dee625079b837..4243dbbaf69c1 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs @@ -1,5 +1,7 @@ using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; [JsonPolymorphic(TypeDiscriminatorPropertyName = "proxyType")] diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs b/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs index 3a1ec251a2956..88503bf894cd8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; internal sealed class SessionModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs index 2c25c17e60313..8ab6de213b138 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; internal class StatusCommand() : Command(CommandParameters.Empty); diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs index 1d33180d1e3b7..607e5c69944c6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Collections.Generic; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; internal class SubscribeCommand(SubscribeCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs index e96f6b4cf828d..6ca1f7517b439 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Session; internal class UnsubscribeCommand(SubscribeCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs index bcc27fdf9f8b3..13dcf2f30d3ba 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Communication; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Storage; internal class DeleteCookiesCommand(DeleteCookiesCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs index cd9e6441bbba9..0f1e450dcbbf4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Storage; internal class GetCookiesCommand(GetCookiesCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs index fd2798be0ae03..30200db4b5f60 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/PartitionKey.cs @@ -1,3 +1,5 @@ +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Storage; public class PartitionKey diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs index f0dcf22904eba..7e7cb79824cbc 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Storage; internal class SetCookieCommand(SetCookieCommandParameters @params) : Command(@params); diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs index 249d7d37634d1..71969d9914c2a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Communication; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi.Modules.Storage; public class StorageModule(Broker broker) : Module(broker) diff --git a/dotnet/src/webdriver/BiDi/Subscription.cs b/dotnet/src/webdriver/BiDi/Subscription.cs index a271fb6b9d5cd..8870b07fb18bf 100644 --- a/dotnet/src/webdriver/BiDi/Subscription.cs +++ b/dotnet/src/webdriver/BiDi/Subscription.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi; public class Subscription : IAsyncDisposable diff --git a/dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs b/dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs index c039dd4087740..a3e7df31cec50 100644 --- a/dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs +++ b/dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs @@ -1,6 +1,8 @@ using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using System.Threading.Tasks; +#nullable enable + namespace OpenQA.Selenium.BiDi; public static class WebDriverExtensions From 3557645a05415946e3bc6b5f58d66de2de1a7064 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 19:57:46 +0300 Subject: [PATCH 45/60] Even more warnings --- .../Json/Converters/Enumerable/GetCookiesResultConverter.cs | 2 +- .../Json/Converters/Enumerable/GetRealmsResultConverter.cs | 2 +- .../Converters/Enumerable/GetUserContextsResultConverter.cs | 2 +- .../Json/Converters/Enumerable/LocateNodesResultConverter.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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 4f914058057f2..bd92fa36eb119 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs @@ -16,7 +16,7 @@ public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConv var cookies = doc.RootElement.GetProperty("cookies").Deserialize>(options); var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize(options); - return new GetCookiesResult(cookies, partitionKey); + return new GetCookiesResult(cookies!, partitionKey!); } public override void Write(Utf8JsonWriter writer, GetCookiesResult value, 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 810a816dce247..34c5a979c02c6 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs @@ -15,7 +15,7 @@ public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConve var doc = JsonDocument.ParseValue(ref reader); var realms = doc.RootElement.GetProperty("realms").Deserialize>(options); - return new GetRealmsResult(realms); + return new GetRealmsResult(realms!); } public override void Write(Utf8JsonWriter writer, GetRealmsResult value, 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 00b2d561c65a9..123c415c9bcd1 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs @@ -15,7 +15,7 @@ public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeT var doc = JsonDocument.ParseValue(ref reader); var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize>(options); - return new GetUserContextsResult(userContexts); + return new GetUserContextsResult(userContexts!); } public override void Write(Utf8JsonWriter writer, GetUserContextsResult value, 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 b2a8bcb36e965..307433c7be023 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs @@ -16,7 +16,7 @@ public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToCon var doc = JsonDocument.ParseValue(ref reader); var nodes = doc.RootElement.GetProperty("nodes").Deserialize>(options); - return new LocateNodesResult(nodes); + return new LocateNodesResult(nodes!); } public override void Write(Utf8JsonWriter writer, LocateNodesResult value, JsonSerializerOptions options) From 661c52ee39981b860fc5d6f451369f02de494895 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 20:07:32 +0300 Subject: [PATCH 46/60] Intercept is cls compliant --- .../BiDi/Modules/Network/Intercept.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs b/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs index 65ff717b08349..4fd55a7d14b0f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs @@ -11,33 +11,33 @@ public class Intercept : IAsyncDisposable { private readonly BiDi _bidi; - protected readonly IList _onBeforeRequestSentSubscriptions = []; - protected readonly IList _onResponseStartedSubscriptions = []; - protected readonly IList _onAuthRequiredSubscriptions = []; - internal Intercept(BiDi bidi, string id) { _bidi = bidi; Id = id; } - public string Id { get; } + internal string Id { get; } + + protected IList OnBeforeRequestSentSubscriptions { get; } = []; + protected IList OnResponseStartedSubscriptions { get; } = []; + protected IList OnAuthRequiredSubscriptions { get; } = []; public async Task RemoveAsync() { await _bidi.Network.RemoveInterceptAsync(this).ConfigureAwait(false); - foreach (var subscription in _onBeforeRequestSentSubscriptions) + foreach (var subscription in OnBeforeRequestSentSubscriptions) { await subscription.UnsubscribeAsync().ConfigureAwait(false); } - foreach (var subscription in _onResponseStartedSubscriptions) + foreach (var subscription in OnResponseStartedSubscriptions) { await subscription.UnsubscribeAsync().ConfigureAwait(false); } - foreach (var subscription in _onAuthRequiredSubscriptions) + foreach (var subscription in OnAuthRequiredSubscriptions) { await subscription.UnsubscribeAsync().ConfigureAwait(false); } @@ -47,21 +47,21 @@ public async Task OnBeforeRequestSentAsync(Func await Filter(args, handler), options).ConfigureAwait(false); - _onBeforeRequestSentSubscriptions.Add(subscription); + OnBeforeRequestSentSubscriptions.Add(subscription); } public async Task OnResponseStartedAsync(Func handler, SubscriptionOptions? options = null) { var subscription = await _bidi.Network.OnResponseStartedAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); - _onResponseStartedSubscriptions.Add(subscription); + OnResponseStartedSubscriptions.Add(subscription); } public async Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null) { var subscription = await _bidi.Network.OnAuthRequiredAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); - _onAuthRequiredSubscriptions.Add(subscription); + OnAuthRequiredSubscriptions.Add(subscription); } private async Task Filter(BeforeRequestSentEventArgs args, Func handler) From 15ef32fb64edf38377a19e7cd471a64fe437b3bd Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 20:11:30 +0300 Subject: [PATCH 47/60] String remote value not null? --- .../Json/Converters/Polymorphic/RemoteValueConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4635954026afc..3f19d2a18c56c 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs @@ -16,7 +16,7 @@ internal class RemoteValueConverter : JsonConverter if (jsonDocument.RootElement.ValueKind == JsonValueKind.String) { - return new RemoteValue.String(jsonDocument.RootElement.GetString()); + return new RemoteValue.String(jsonDocument.RootElement.GetString()!); } return jsonDocument.RootElement.GetProperty("type").ToString() switch From e142fe911dc5a6412c566c80f6ca71109d7fbcd6 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 5 Oct 2024 21:27:39 +0300 Subject: [PATCH 48/60] Options in browsing context log as optional --- .../BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs index 031b579f4b7f5..a085bb07de630 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextLogModule.cs @@ -8,7 +8,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 => { @@ -19,7 +19,7 @@ public Task OnEntryAddedAsync(Func handler, Subsc }, options); } - public Task OnEntryAddedAsync(Action handler, SubscriptionOptions options = null) + public Task OnEntryAddedAsync(Action handler, SubscriptionOptions? options = null) { return logModule.OnEntryAddedAsync(args => { From b777ead500d40a44bc2f10fcae391b3602b34388 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:25:14 +0300 Subject: [PATCH 49/60] Fix warnings for UrlPattern and Locator --- dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs | 4 +++- dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index 6a52079e6d155..8e6a3cca13e49 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -11,6 +11,8 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; [JsonDerivedType(typeof(XPath), "xpath")] public abstract record Locator { + public static InnerText InnerTextFFF(string value) => new InnerText(value); + public record Accessibility(Accessibility.AccessibilityValue Value) : Locator { public record AccessibilityValue @@ -26,7 +28,7 @@ public record InnerText(string Value) : Locator { public bool? IgnoreCase { get; set; } - public MatchType? MatchType { get; set; } + public new MatchType? MatchType { get; set; } public long? MaxDepth { get; set; } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs b/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs index ceda0487aae01..30a034fbee4d0 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs @@ -26,6 +26,6 @@ public record Pattern : UrlPattern public record String(string Pattern) : UrlPattern { - public string Pattern { get; } = Pattern; + public new string Pattern { get; } = Pattern; } } From 25f1a5b3615f013de0539e5a5b41b2c377d561f4 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:30:36 +0300 Subject: [PATCH 50/60] Remove extra experiment --- dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index 8e6a3cca13e49..c03744b105858 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -11,8 +11,6 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; [JsonDerivedType(typeof(XPath), "xpath")] public abstract record Locator { - public static InnerText InnerTextFFF(string value) => new InnerText(value); - public record Accessibility(Accessibility.AccessibilityValue Value) : Locator { public record AccessibilityValue From 588e3582fcae2bc73305a3e260cf1f166268e7bb Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 6 Oct 2024 16:01:17 +0300 Subject: [PATCH 51/60] Make sure unions don't contain extra nested classes --- .../BiDi/Modules/BrowsingContext/Locator.cs | 12 ++-- .../BiDi/Modules/Input/SourceActions.cs | 60 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs index c03744b105858..d22215f5f6d92 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs @@ -26,16 +26,16 @@ public record InnerText(string Value) : Locator { public bool? IgnoreCase { get; set; } - public new MatchType? MatchType { get; set; } + public MatchType? MatchType { get; set; } public long? MaxDepth { get; set; } } public record XPath(string Value) : Locator; +} - public enum MatchType - { - Full, - Partial - } +public enum MatchType +{ + Full, + Partial } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 025bde9c82965..119692154418b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -24,7 +24,7 @@ public record Keys : SourceActions, IEnumerable public record Pointers : SourceActions, IEnumerable { - public Parameters? Options { get; set; } + public PointerParameters? Options { get; set; } public IList Actions { get; set; } = []; @@ -33,18 +33,6 @@ public record Pointers : SourceActions, IEnumerable public IEnumerator GetEnumerator() => Actions.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - - public record Parameters - { - public Type? PointerType { get; set; } - } - - public enum Type - { - Mouse, - Pen, - Touch - } } public record Wheels : SourceActions, IEnumerable @@ -113,23 +101,6 @@ public record Move(int X, int Y) : Pointer, IPointerCommonProperties public double? AltitudeAngle { get; set; } public double? AzimuthAngle { get; set; } } - - public interface IPointerCommonProperties - { - public int? Width { get; set; } - - public int? Height { get; set; } - - public double? Pressure { get; set; } - - public double? TangentialPressure { get; set; } - - public int? Twist { get; set; } - - public double? AltitudeAngle { get; set; } - - public double? AzimuthAngle { get; set; } - } } [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] @@ -150,3 +121,32 @@ public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel } } } + +public record PointerParameters +{ + public PointerType? PointerType { get; set; } +} + +public enum PointerType +{ + Mouse, + Pen, + Touch +} + +public interface IPointerCommonProperties +{ + public int? Width { get; set; } + + public int? Height { get; set; } + + public double? Pressure { get; set; } + + public double? TangentialPressure { get; set; } + + public int? Twist { get; set; } + + public double? AltitudeAngle { get; set; } + + public double? AzimuthAngle { get; set; } +} From a3aa07ed9dde3940115a611b723ce99ceaf63b36 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 6 Oct 2024 16:16:05 +0300 Subject: [PATCH 52/60] None input action --- .../Enumerable/InputSourceActionsConverter.cs | 6 + .../BiDi/Modules/Input/SourceActions.cs | 145 ++++++++++-------- .../BiDi/Input/CombinedInputActionsTest.cs | 24 +-- .../common/BiDi/Input/DefaultMouseTest.cs | 12 +- 4 files changed, 107 insertions(+), 80 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 46e1f7ce48ae8..76a326e262acc 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -45,6 +45,12 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria writer.WritePropertyName("actions"); JsonSerializer.Serialize(writer, wheels.Actions, options); + break; + case SourceActions.None none: + writer.WriteString("type", "none"); + writer.WritePropertyName("actions"); + JsonSerializer.Serialize(writer, none.Actions, options); + break; } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 119692154418b..fdc6cdc022203 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -46,79 +46,100 @@ public record Wheels : SourceActions, IEnumerable IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); } - [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] - [JsonDerivedType(typeof(Pause), "pause")] - [JsonDerivedType(typeof(Down), "keyDown")] - [JsonDerivedType(typeof(Up), "keyUp")] - public abstract record Key + public record None : SourceActions, IEnumerable { - public record Pause : Key - { - public long? Duration { get; set; } - } + public IList Actions { get; set; } = []; - public record Down(string Value) : Key; + public void Add(Input.None none) => Actions.Add(none); - public record Up(string Value) : Key; + public IEnumerator GetEnumerator() => Actions.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); } +} - [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] - [JsonDerivedType(typeof(Pause), "pause")] - [JsonDerivedType(typeof(Down), "pointerDown")] - [JsonDerivedType(typeof(Up), "pointerUp")] - [JsonDerivedType(typeof(Move), "pointerMove")] - public abstract record Pointer +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Pause), "pause")] +[JsonDerivedType(typeof(Down), "keyDown")] +[JsonDerivedType(typeof(Up), "keyUp")] +public abstract record Key +{ + public record Pause : Key { - public record Pause : Pointer - { - public long? Duration { get; set; } - } - - public record Down(int Button) : Pointer, IPointerCommonProperties - { - public int? Width { get; set; } - public int? Height { get; set; } - public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } - public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } - } - - public record Up(int Button) : Pointer; - - public record Move(int X, int Y) : Pointer, IPointerCommonProperties - { - public int? Duration { get; set; } - - public Origin? Origin { get; set; } - - public int? Width { get; set; } - public int? Height { get; set; } - public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } - public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } - } + public long? Duration { get; set; } } - [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] - [JsonDerivedType(typeof(Pause), "pause")] - [JsonDerivedType(typeof(Scroll), "scroll")] - public abstract record Wheel + public record Down(string Value) : Key; + + public record Up(string Value) : Key; +} + +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Pause), "pause")] +[JsonDerivedType(typeof(Down), "pointerDown")] +[JsonDerivedType(typeof(Up), "pointerUp")] +[JsonDerivedType(typeof(Move), "pointerMove")] +public abstract record Pointer +{ + public record Pause : Pointer + { + public long? Duration { get; set; } + } + + public record Down(int Button) : Pointer, IPointerCommonProperties + { + public int? Width { get; set; } + public int? Height { get; set; } + public double? Pressure { get; set; } + public double? TangentialPressure { get; set; } + public int? Twist { get; set; } + public double? AltitudeAngle { get; set; } + public double? AzimuthAngle { get; set; } + } + + public record Up(int Button) : Pointer; + + public record Move(int X, int Y) : Pointer, IPointerCommonProperties { - public record Pause : Wheel - { - public long? Duration { get; set; } - } + public int? Duration { get; set; } - public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel - { - public int? Duration { get; set; } + public Origin? Origin { get; set; } - public Origin? Origin { get; set; } - } + public int? Width { get; set; } + public int? Height { get; set; } + public double? Pressure { get; set; } + public double? TangentialPressure { get; set; } + public int? Twist { get; set; } + public double? AltitudeAngle { get; set; } + public double? AzimuthAngle { get; set; } + } +} + +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Pause), "pause")] +[JsonDerivedType(typeof(Scroll), "scroll")] +public abstract record Wheel +{ + public record Pause : Wheel + { + public long? Duration { get; set; } + } + + public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel + { + public int? Duration { get; set; } + + public Origin? Origin { get; set; } + } +} + +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Pause), "pause")] +public abstract record None +{ + public record Pause : None + { + public long? Duration { get; set; } } } diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index 6dfcfa90324d6..f0895355fa8a0 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -15,22 +15,22 @@ public async Task Paint() await Task.Delay(3000); await context.Input.PerformActionsAsync([new SourceActions.Pointers { - new SourceActions.Pointer.Move(300, 300), - new SourceActions.Pointer.Down(0), - new SourceActions.Pointer.Move(400, 400) { Duration = 2000, Width = 1, Twist = 1 }, - new SourceActions.Pointer.Up(0), + new Pointer.Move(300, 300), + new Pointer.Down(0), + new Pointer.Move(400, 400) { Duration = 2000, Width = 1, Twist = 1 }, + new Pointer.Up(0), }]); await context.Input.PerformActionsAsync([new SourceActions.Keys { - new SourceActions.Key.Down("U"), - new SourceActions.Key.Up("U") + new Key.Down("U"), + new Key.Up("U") }]); await context.Input.PerformActionsAsync([new SourceActions.Pointers { - new SourceActions.Pointer.Move(300, 300), - new SourceActions.Pointer.Down(0), - new SourceActions.Pointer.Move(400, 400) { Duration = 2000 }, - new SourceActions.Pointer.Up(0), + new Pointer.Move(300, 300), + new Pointer.Down(0), + new Pointer.Move(400, 400) { Duration = 2000 }, + new Pointer.Up(0), }]); await Task.Delay(3000); @@ -46,8 +46,8 @@ public async Task TestShiftClickingOnMultiSelectionList() await context.Input.PerformActionsAsync([ new SourceActions.Pointers { - new SourceActions.Pointer.Down(1), - new SourceActions.Pointer.Up(1), + new Pointer.Down(1), + new Pointer.Up(1), } ]); } diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index 38f6422fbf4b4..b8221b03f9c6a 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -16,22 +16,22 @@ await context.Input.PerformActionsAsync([ { Actions = { - new SourceActions.Key.Down("A") + new Key.Down("A") } } ]); await context.Input.PerformActionsAsync([new SourceActions.Keys { - new SourceActions.Key.Down("A"), - new SourceActions.Key.Down("B"), - new SourceActions.Key.Pause() + new Key.Down("A"), + new Key.Down("B"), + new Key.Pause() }]); await context.Input.PerformActionsAsync([new SourceActions.Pointers { - new SourceActions.Pointer.Down(0), - new SourceActions.Pointer.Up(0), + new Pointer.Down(0), + new Pointer.Up(0), }]); } } From 55afa4fc7666b21fcb837e0677ffe86077c3dce6 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 6 Oct 2024 17:57:26 +0300 Subject: [PATCH 53/60] Source input actions as interface --- .../Enumerable/InputSourceActionsConverter.cs | 25 ++++--- .../BrowsingContextInputModule.cs | 2 +- .../BiDi/Modules/Input/InputModule.cs | 2 +- .../Modules/Input/PerformActionsCommand.cs | 2 +- .../BiDi/Modules/Input/SourceActions.cs | 67 +++++++------------ .../BiDi/Input/CombinedInputActionsTest.cs | 8 +-- .../common/BiDi/Input/DefaultMouseTest.cs | 9 +-- 7 files changed, 51 insertions(+), 64 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 76a326e262acc..96b07c4d5bff6 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -1,5 +1,7 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System; +using System.Collections.Generic; +using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; @@ -7,14 +9,14 @@ namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -internal class InputSourceActionsConverter : JsonConverter +internal class InputSourceActionsConverter : JsonConverter { - public override SourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override ISourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { throw new NotImplementedException(); } - public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, ISourceActions value, JsonSerializerOptions options) { writer.WriteStartObject(); @@ -22,13 +24,13 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria switch (value) { - case SourceActions.Keys keys: + case KeyActions keys: writer.WriteString("type", "key"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, keys.Actions, options); + JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as Key), options); break; - case SourceActions.Pointers pointers: + case PointerActions pointers: writer.WriteString("type", "pointer"); if (pointers.Options is not null) { @@ -37,19 +39,19 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria } writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, pointers.Actions, options); + JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as Pointer), options); break; - case SourceActions.Wheels wheels: + case WheelActions wheels: writer.WriteString("type", "wheel"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, wheels.Actions, options); + JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as Wheel), options); break; - case SourceActions.None none: + case NoneActions none: writer.WriteString("type", "none"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, none.Actions, options); + JsonSerializer.Serialize(writer, none.Actions.Select(a => a as None), options); break; } @@ -57,3 +59,4 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria writer.WriteEndObject(); } } + diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs index 919758b14ba79..e7cb84c2985fa 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs @@ -8,7 +8,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextInputModule(BrowsingContext context, InputModule inputModule) { - public Task PerformActionsAsync(IEnumerable actions, PerformActionsOptions? options = null) + public Task PerformActionsAsync(IEnumerable actions, PerformActionsOptions? options = null) { return inputModule.PerformActionsAsync(context, actions, options); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs index 53f913132c758..00095407a5697 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs @@ -8,7 +8,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; public sealed class InputModule(Broker broker) : Module(broker) { - public async Task PerformActionsAsync(BrowsingContext.BrowsingContext context, IEnumerable actions, PerformActionsOptions? options = null) + public async Task PerformActionsAsync(BrowsingContext.BrowsingContext context, IEnumerable actions, PerformActionsOptions? options = null) { var @params = new PerformActionsCommandParameters(context, actions); diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs index 878b576417fba..5575bb2ae4ba6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs @@ -7,6 +7,6 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; internal class PerformActionsCommand(PerformActionsCommandParameters @params) : Command(@params); -internal record PerformActionsCommandParameters(BrowsingContext.BrowsingContext Context, IEnumerable Actions) : CommandParameters; +internal record PerformActionsCommandParameters(BrowsingContext.BrowsingContext Context, IEnumerable Actions) : CommandParameters; public record PerformActionsOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index fdc6cdc022203..2291b1ffc2436 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -7,62 +7,45 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; -public abstract record SourceActions +public interface ISourceActions { - public string Id { get; } = Guid.NewGuid().ToString(); - - public record Keys : SourceActions, IEnumerable - { - public IList Actions { get; set; } = []; + string Id { get; } - public void Add(Key key) => Actions.Add(key); - - public IEnumerator GetEnumerator() => Actions.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - } - - public record Pointers : SourceActions, IEnumerable - { - public PointerParameters? Options { get; set; } - - public IList Actions { get; set; } = []; - - public void Add(Pointer pointer) => Actions.Add(pointer); + IList Actions { get; } +} - public IEnumerator GetEnumerator() => Actions.GetEnumerator(); +public abstract record SourceActions : ISourceActions, IEnumerable +{ + public string Id { get; } = Guid.NewGuid().ToString(); - IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - } + [JsonPropertyName("actions")] + public IList Actions { get; } = []; - public record Wheels : SourceActions, IEnumerable - { - public IList Actions { get; set; } = []; + public IEnumerator GetEnumerator() => Actions.GetEnumerator(); - public void Add(Wheel wheel) => Actions.Add(wheel); + IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - public IEnumerator GetEnumerator() => Actions.GetEnumerator(); + public void Add(ISourceAction action) => Actions.Add(action); +} - IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - } +public record KeyActions : SourceActions, ISourceActions; - public record None : SourceActions, IEnumerable - { - public IList Actions { get; set; } = []; +public record PointerActions : SourceActions, ISourceActions +{ + public PointerParameters? Options { get; set; } +} - public void Add(Input.None none) => Actions.Add(none); +public record WheelActions : SourceActions; - public IEnumerator GetEnumerator() => Actions.GetEnumerator(); +public record NoneActions : SourceActions; - IEnumerator IEnumerable.GetEnumerator() => Actions.GetEnumerator(); - } -} +public interface ISourceAction; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Pause), "pause")] [JsonDerivedType(typeof(Down), "keyDown")] [JsonDerivedType(typeof(Up), "keyUp")] -public abstract record Key +public abstract record Key : ISourceAction { public record Pause : Key { @@ -79,7 +62,7 @@ public record Up(string Value) : Key; [JsonDerivedType(typeof(Down), "pointerDown")] [JsonDerivedType(typeof(Up), "pointerUp")] [JsonDerivedType(typeof(Move), "pointerMove")] -public abstract record Pointer +public abstract record Pointer : ISourceAction { public record Pause : Pointer { @@ -118,7 +101,7 @@ public record Move(int X, int Y) : Pointer, IPointerCommonProperties [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Pause), "pause")] [JsonDerivedType(typeof(Scroll), "scroll")] -public abstract record Wheel +public abstract record Wheel : ISourceAction { public record Pause : Wheel { @@ -135,7 +118,7 @@ public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Pause), "pause")] -public abstract record None +public abstract record None : ISourceAction { public record Pause : None { diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index f0895355fa8a0..06d5f9cec497c 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -14,19 +14,19 @@ public async Task Paint() await Task.Delay(3000); - await context.Input.PerformActionsAsync([new SourceActions.Pointers { + await context.Input.PerformActionsAsync([new PointerActions { new Pointer.Move(300, 300), new Pointer.Down(0), new Pointer.Move(400, 400) { Duration = 2000, Width = 1, Twist = 1 }, new Pointer.Up(0), }]); - await context.Input.PerformActionsAsync([new SourceActions.Keys { + await context.Input.PerformActionsAsync([new KeyActions { new Key.Down("U"), new Key.Up("U") }]); - await context.Input.PerformActionsAsync([new SourceActions.Pointers { + await context.Input.PerformActionsAsync([new PointerActions { new Pointer.Move(300, 300), new Pointer.Down(0), new Pointer.Move(400, 400) { Duration = 2000 }, @@ -44,7 +44,7 @@ public async Task TestShiftClickingOnMultiSelectionList() var options = await context.LocateNodesAsync(new Locator.Css("option")); await context.Input.PerformActionsAsync([ - new SourceActions.Pointers + new PointerActions { new Pointer.Down(1), new Pointer.Up(1), diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index b8221b03f9c6a..94b6cca5d664e 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -12,23 +12,24 @@ public async Task PerformDragAndDropWithMouse() driver.Url = UrlBuilder.WhereIs("draggableLists.html"); await context.Input.PerformActionsAsync([ - new SourceActions.Keys + new KeyActions { Actions = { - new Key.Down("A") + new Key.Down("A"), + new Key.Up("B") } } ]); - await context.Input.PerformActionsAsync([new SourceActions.Keys + await context.Input.PerformActionsAsync([new KeyActions { new Key.Down("A"), new Key.Down("B"), new Key.Pause() }]); - await context.Input.PerformActionsAsync([new SourceActions.Pointers + await context.Input.PerformActionsAsync([new PointerActions { new Pointer.Down(0), new Pointer.Up(0), From 013d2b3cdef8f57df0e29efcf512d874b27e7fa5 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 6 Oct 2024 18:38:59 +0300 Subject: [PATCH 54/60] Update SourceActions.cs --- dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 2291b1ffc2436..594f7a4539023 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -18,7 +18,6 @@ public abstract record SourceActions : ISourceActions, IEnumerable Actions { get; } = []; public IEnumerator GetEnumerator() => Actions.GetEnumerator(); From 3cd459c2b76554c73b9eb0a78aa9c16b4b98294f Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Mon, 7 Oct 2024 01:13:49 +0300 Subject: [PATCH 55/60] Open door to sequential input actions --- .../Enumerable/InputSourceActionsConverter.cs | 6 +- .../BrowsingContextInputModule.cs | 2 +- .../BiDi/Modules/Input/InputModule.cs | 2 +- .../src/webdriver/BiDi/Modules/Input/Key.cs | 6 ++ .../Modules/Input/PerformActionsCommand.cs | 2 +- .../Modules/Input/SequentialSourceActions.cs | 68 +++++++++++++++++++ .../BiDi/Modules/Input/SourceActions.cs | 34 ++++++---- .../BiDi/Input/CombinedInputActionsTest.cs | 4 +- .../common/BiDi/Input/DefaultMouseTest.cs | 19 ++++-- 9 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 dotnet/src/webdriver/BiDi/Modules/Input/Key.cs create mode 100644 dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs 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 96b07c4d5bff6..877fad6d828ef 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -9,14 +9,14 @@ namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable; -internal class InputSourceActionsConverter : JsonConverter +internal class InputSourceActionsConverter : JsonConverter { - public override ISourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override SourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { throw new NotImplementedException(); } - public override void Write(Utf8JsonWriter writer, ISourceActions value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSerializerOptions options) { writer.WriteStartObject(); diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs index e7cb84c2985fa..919758b14ba79 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs @@ -8,7 +8,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; public class BrowsingContextInputModule(BrowsingContext context, InputModule inputModule) { - public Task PerformActionsAsync(IEnumerable actions, PerformActionsOptions? options = null) + public Task PerformActionsAsync(IEnumerable actions, PerformActionsOptions? options = null) { return inputModule.PerformActionsAsync(context, actions, options); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs index 00095407a5697..53f913132c758 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/InputModule.cs @@ -8,7 +8,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; public sealed class InputModule(Broker broker) : Module(broker) { - public async Task PerformActionsAsync(BrowsingContext.BrowsingContext context, IEnumerable actions, PerformActionsOptions? options = null) + public async Task PerformActionsAsync(BrowsingContext.BrowsingContext context, IEnumerable actions, PerformActionsOptions? options = null) { var @params = new PerformActionsCommandParameters(context, actions); diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs b/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs new file mode 100644 index 0000000000000..ec9c40a51a7e9 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs @@ -0,0 +1,6 @@ +namespace OpenQA.Selenium.BiDi.Modules.Input; + +partial record Key +{ + public static char Shift { get; } = '\xE008'; +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs index 5575bb2ae4ba6..878b576417fba 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs @@ -7,6 +7,6 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; internal class PerformActionsCommand(PerformActionsCommandParameters @params) : Command(@params); -internal record PerformActionsCommandParameters(BrowsingContext.BrowsingContext Context, IEnumerable Actions) : CommandParameters; +internal record PerformActionsCommandParameters(BrowsingContext.BrowsingContext Context, IEnumerable Actions) : CommandParameters; public record PerformActionsOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs new file mode 100644 index 0000000000000..4632bce5a37ad --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs @@ -0,0 +1,68 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace OpenQA.Selenium.BiDi.Modules.Input; + +public interface ISequentialSourceActions : IEnumerable +{ + public SequentialSourceActions Type(string text); + + public SequentialSourceActions KeyDown(char key); +} + +public record SequentialSourceActions : ISequentialSourceActions +{ + private readonly KeyActions _keyActions = []; + private readonly PointerActions _pointerActions = []; + private readonly WheelActions _wheelActions = []; + + public SequentialSourceActions Type(string text) + { + _keyActions.Type(text); + + return Normalized(); + } + + public SequentialSourceActions KeyDown(char key) + { + _keyActions.Add(new Key.Down(key)); + + return Normalized(); + } + + private SequentialSourceActions Normalized() + { + var max = new[] { _keyActions.Count(), _pointerActions.Count(), _wheelActions.Count() }.Max(); + + for (int i = _keyActions.Count(); i < max; i++) + { + _keyActions.Add(new Key.Pause()); + } + + for (int i = _pointerActions.Count(); i < max; i++) + { + _pointerActions.Add(new Pointer.Pause()); + } + + for (int i = _wheelActions.Count(); i < max; i++) + { + _wheelActions.Add(new Pointer.Pause()); + } + + return this; + } + + public IEnumerator GetEnumerator() + { + var sourceActions = new List + { + _keyActions, + _pointerActions, + _wheelActions + }; + return sourceActions.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); +} diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 594f7a4539023..0f116004d63bd 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -7,18 +7,14 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; -public interface ISourceActions +public abstract record SourceActions { - string Id { get; } - - IList Actions { get; } + public string Id { get; } = Guid.NewGuid().ToString(); } -public abstract record SourceActions : ISourceActions, IEnumerable +public record SourceActions : SourceActions, IEnumerable where T : ISourceAction { - public string Id { get; } = Guid.NewGuid().ToString(); - - public IList Actions { get; } = []; + public IList Actions { get; set; } = []; public IEnumerator GetEnumerator() => Actions.GetEnumerator(); @@ -27,9 +23,21 @@ public abstract record SourceActions : ISourceActions, IEnumerable Actions.Add(action); } -public record KeyActions : SourceActions, ISourceActions; +public record KeyActions : SourceActions +{ + public KeyActions Type(string text) + { + foreach (var character in text) + { + Add(new Key.Down(character)); + Add(new Key.Up(character)); + } + + return this; + } +} -public record PointerActions : SourceActions, ISourceActions +public record PointerActions : SourceActions { public PointerParameters? Options { get; set; } } @@ -44,16 +52,16 @@ public interface ISourceAction; [JsonDerivedType(typeof(Pause), "pause")] [JsonDerivedType(typeof(Down), "keyDown")] [JsonDerivedType(typeof(Up), "keyUp")] -public abstract record Key : ISourceAction +public abstract partial record Key : ISourceAction { public record Pause : Key { public long? Duration { get; set; } } - public record Down(string Value) : Key; + public record Down(char Value) : Key; - public record Up(string Value) : Key; + public record Up(char Value) : Key; } [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index 06d5f9cec497c..a3d36c3df22a0 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -22,8 +22,8 @@ await context.Input.PerformActionsAsync([new PointerActions { }]); await context.Input.PerformActionsAsync([new KeyActions { - new Key.Down("U"), - new Key.Up("U") + new Key.Down('U'), + new Key.Up('U') }]); await context.Input.PerformActionsAsync([new PointerActions { diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index 94b6cca5d664e..e424f6bfb56e2 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.BrowsingContext; using OpenQA.Selenium.BiDi.Modules.Input; using System.Threading.Tasks; @@ -16,16 +17,16 @@ await context.Input.PerformActionsAsync([ { Actions = { - new Key.Down("A"), - new Key.Up("B") + new Key.Down('A'), + new Key.Up('B') } } ]); await context.Input.PerformActionsAsync([new KeyActions { - new Key.Down("A"), - new Key.Down("B"), + new Key.Down('A'), + new Key.Down('B'), new Key.Pause() }]); @@ -35,4 +36,14 @@ await context.Input.PerformActionsAsync([new PointerActions new Pointer.Up(0), }]); } + + //[Test] + public async Task PerformCombined() + { + await context.NavigateAsync("https://nuget.org", new() { Wait = ReadinessState.Complete }); + + await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("Hello").KeyDown(Key.Shift).Type("World")); + + await Task.Delay(3000); + } } From 762648cdda990d5182ac4e41eae98a8df7661d9c Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:51:36 +0300 Subject: [PATCH 56/60] Pause as ISourceAction --- .../Enumerable/InputSourceActionsConverter.cs | 9 +-- .../src/webdriver/BiDi/Modules/Input/Key.cs | 4 +- .../Modules/Input/SequentialSourceActions.cs | 34 ++++++--- .../BiDi/Modules/Input/SourceActions.cs | 74 +++++++++---------- .../BiDi/Input/CombinedInputActionsTest.cs | 3 +- .../common/BiDi/Input/DefaultMouseTest.cs | 4 +- 6 files changed, 69 insertions(+), 59 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 877fad6d828ef..4e4c72c91fbe9 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/InputSourceActionsConverter.cs @@ -1,6 +1,5 @@ using OpenQA.Selenium.BiDi.Modules.Input; using System; -using System.Collections.Generic; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; @@ -27,7 +26,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 Key), options); + JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), options); break; case PointerActions pointers: @@ -39,19 +38,19 @@ public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSeria } writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as Pointer), options); + JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), options); break; case WheelActions wheels: writer.WriteString("type", "wheel"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as Wheel), options); + JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), options); break; case NoneActions none: writer.WriteString("type", "none"); writer.WritePropertyName("actions"); - JsonSerializer.Serialize(writer, none.Actions.Select(a => a as None), options); + JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), options); break; } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs b/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs index ec9c40a51a7e9..c42f701f29862 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs @@ -2,5 +2,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; partial record Key { - public static char Shift { get; } = '\xE008'; + public const char Shift = '\uE008'; + + public const char Pause = '\uE00B'; } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs index 4632bce5a37ad..f1e961a6b96b7 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs @@ -6,9 +6,11 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; public interface ISequentialSourceActions : IEnumerable { - public SequentialSourceActions Type(string text); + public ISequentialSourceActions Pause(int duration); - public SequentialSourceActions KeyDown(char key); + public ISequentialSourceActions Type(string text); + + public ISequentialSourceActions KeyDown(char key); } public record SequentialSourceActions : ISequentialSourceActions @@ -16,15 +18,23 @@ public record SequentialSourceActions : ISequentialSourceActions private readonly KeyActions _keyActions = []; private readonly PointerActions _pointerActions = []; private readonly WheelActions _wheelActions = []; + private readonly WheelActions _noneActions = []; - public SequentialSourceActions Type(string text) + public ISequentialSourceActions Pause(int duration) + { + _noneActions.Add(new Pause { Duration = duration }); + + return Normalized(); + } + + public ISequentialSourceActions Type(string text) { _keyActions.Type(text); return Normalized(); } - public SequentialSourceActions KeyDown(char key) + public ISequentialSourceActions KeyDown(char key) { _keyActions.Add(new Key.Down(key)); @@ -33,21 +43,26 @@ public SequentialSourceActions KeyDown(char key) private SequentialSourceActions Normalized() { - var max = new[] { _keyActions.Count(), _pointerActions.Count(), _wheelActions.Count() }.Max(); + var max = new[] { _keyActions.Count(), _pointerActions.Count(), _wheelActions.Count(), _noneActions.Count() }.Max(); for (int i = _keyActions.Count(); i < max; i++) { - _keyActions.Add(new Key.Pause()); + _keyActions.Add(new Pause()); } for (int i = _pointerActions.Count(); i < max; i++) { - _pointerActions.Add(new Pointer.Pause()); + _pointerActions.Add(new Pause()); } for (int i = _wheelActions.Count(); i < max; i++) { - _wheelActions.Add(new Pointer.Pause()); + _wheelActions.Add(new Pause()); + } + + for (int i = _noneActions.Count(); i < max; i++) + { + _noneActions.Add(new Pause()); } return this; @@ -59,7 +74,8 @@ public IEnumerator GetEnumerator() { _keyActions, _pointerActions, - _wheelActions + _wheelActions, + _noneActions }; return sourceActions.GetEnumerator(); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs index 0f116004d63bd..a9b7ed3f7001f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SourceActions.cs @@ -12,6 +12,8 @@ public abstract record SourceActions public string Id { get; } = Guid.NewGuid().ToString(); } +public interface ISourceAction; + public record SourceActions : SourceActions, IEnumerable where T : ISourceAction { public IList Actions { get; set; } = []; @@ -23,7 +25,13 @@ public record SourceActions : SourceActions, IEnumerable where public void Add(ISourceAction action) => Actions.Add(action); } -public record KeyActions : SourceActions +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Pause), "pause")] +[JsonDerivedType(typeof(Key.Down), "keyDown")] +[JsonDerivedType(typeof(Key.Up), "keyUp")] +public interface IKeySourceAction : ISourceAction; + +public record KeyActions : SourceActions { public KeyActions Type(string text) { @@ -37,45 +45,40 @@ public KeyActions Type(string text) } } -public record PointerActions : SourceActions +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Pause), "pause")] +[JsonDerivedType(typeof(Pointer.Down), "pointerDown")] +[JsonDerivedType(typeof(Pointer.Up), "pointerUp")] +[JsonDerivedType(typeof(Pointer.Move), "pointerMove")] +public interface IPointerSourceAction : ISourceAction; + +public record PointerActions : SourceActions { public PointerParameters? Options { get; set; } } -public record WheelActions : SourceActions; - -public record NoneActions : SourceActions; +[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] +[JsonDerivedType(typeof(Pause), "pause")] +[JsonDerivedType(typeof(Wheel.Scroll), "scroll")] +public interface IWheelSourceAction : ISourceAction; -public interface ISourceAction; +public record WheelActions : SourceActions; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(Pause), "pause")] -[JsonDerivedType(typeof(Down), "keyDown")] -[JsonDerivedType(typeof(Up), "keyUp")] -public abstract partial record Key : ISourceAction -{ - public record Pause : Key - { - public long? Duration { get; set; } - } +public interface INoneSourceAction : ISourceAction; + +public record NoneActions : SourceActions; +public abstract partial record Key : IKeySourceAction +{ public record Down(char Value) : Key; public record Up(char Value) : Key; } -[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(Pause), "pause")] -[JsonDerivedType(typeof(Down), "pointerDown")] -[JsonDerivedType(typeof(Up), "pointerUp")] -[JsonDerivedType(typeof(Move), "pointerMove")] -public abstract record Pointer : ISourceAction +public abstract record Pointer : IPointerSourceAction { - public record Pause : Pointer - { - public long? Duration { get; set; } - } - public record Down(int Button) : Pointer, IPointerCommonProperties { public int? Width { get; set; } @@ -105,16 +108,8 @@ public record Move(int X, int Y) : Pointer, IPointerCommonProperties } } -[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(Pause), "pause")] -[JsonDerivedType(typeof(Scroll), "scroll")] -public abstract record Wheel : ISourceAction +public abstract record Wheel : IWheelSourceAction { - public record Pause : Wheel - { - public long? Duration { get; set; } - } - public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel { public int? Duration { get; set; } @@ -123,14 +118,11 @@ public record Scroll(int X, int Y, int DeltaX, int DeltaY) : Wheel } } -[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(Pause), "pause")] -public abstract record None : ISourceAction +public abstract record None : INoneSourceAction; + +public record Pause : ISourceAction, IKeySourceAction, IPointerSourceAction, IWheelSourceAction, INoneSourceAction { - public record Pause : None - { - public long? Duration { get; set; } - } + public long? Duration { get; set; } } public record PointerParameters diff --git a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs index a3d36c3df22a0..cb832cdeb9e41 100644 --- a/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs +++ b/dotnet/test/common/BiDi/Input/CombinedInputActionsTest.cs @@ -23,7 +23,8 @@ await context.Input.PerformActionsAsync([new PointerActions { await context.Input.PerformActionsAsync([new KeyActions { new Key.Down('U'), - new Key.Up('U') + new Key.Up('U'), + new Pause { Duration = 3000 } }]); await context.Input.PerformActionsAsync([new PointerActions { diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index e424f6bfb56e2..0e682571399d0 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -27,7 +27,7 @@ await context.Input.PerformActionsAsync([new KeyActions { new Key.Down('A'), new Key.Down('B'), - new Key.Pause() + new Pause() }]); await context.Input.PerformActionsAsync([new PointerActions @@ -42,7 +42,7 @@ public async Task PerformCombined() { await context.NavigateAsync("https://nuget.org", new() { Wait = ReadinessState.Complete }); - await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("Hello").KeyDown(Key.Shift).Type("World")); + await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("Hello").Pause(2000).KeyDown(Key.Shift).Type("World")); await Task.Delay(3000); } From 9b1b6d0b8ad8249f7c61e4a44722aa76c01a9077 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:29:21 +0300 Subject: [PATCH 57/60] TODO Node as shared reference --- .../test/common/BiDi/BrowsingContext/BrowsingContextTest.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs index dba6acad7d37b..510daceddfb11 100644 --- a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs @@ -266,11 +266,12 @@ public async Task CanCaptureScreenshotOfElement() { await context.NavigateAsync(UrlBuilder.WhereIs("formPage.html"), new() { Wait = ReadinessState.Complete }); - var elements = await context.LocateNodesAsync(new Locator.Css("#checky")); + var nodes = await context.LocateNodesAsync(new Locator.Css("#checky")); var screenshot = await context.CaptureScreenshotAsync(new() { - Clip = new ClipRectangle.Element(new Modules.Script.SharedReference(elements[0].SharedId)) + // TODO: Seems Node implements ISharedReference + Clip = new ClipRectangle.Element(new Modules.Script.SharedReference(nodes[0].SharedId)) }); Assert.That(screenshot, Is.Not.Null); From 7681685716a780b5eb9d982bd8984ceb88f175e2 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Mon, 14 Oct 2024 01:07:07 +0300 Subject: [PATCH 58/60] Add input tests --- .../Modules/Input/SequentialSourceActions.cs | 83 ++++++++++++++++- .../common/BiDi/Input/DefaultKeyboardTest.cs | 88 +++++++++++++++++++ 2 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs index f1e961a6b96b7..6ed1d0899ec7e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs @@ -6,11 +6,15 @@ namespace OpenQA.Selenium.BiDi.Modules.Input; public interface ISequentialSourceActions : IEnumerable { - public ISequentialSourceActions Pause(int duration); + ISequentialSourceActions Pause(int duration); - public ISequentialSourceActions Type(string text); + ISequentialSourceActions Type(string text); + ISequentialSourceActions KeyDown(char key); + ISequentialSourceActions KeyUp(char key); - public ISequentialSourceActions KeyDown(char key); + ISequentialSourceActions PointerDown(int button, PointerDownOptions? options = null); + ISequentialSourceActions PointerUp(int button); + ISequentialSourceActions PointerMove(int x, int y, PointerMoveOptions? options = null); } public record SequentialSourceActions : ISequentialSourceActions @@ -41,6 +45,54 @@ public ISequentialSourceActions KeyDown(char key) return Normalized(); } + public ISequentialSourceActions KeyUp(char key) + { + _keyActions.Add(new Key.Up(key)); + + return Normalized(); + } + + public ISequentialSourceActions PointerDown(int button, PointerDownOptions? options = null) + { + _pointerActions.Add(new Pointer.Down(button) + { + Width = options?.Width, + Height = options?.Height, + Pressure = options?.Pressure, + TangentialPressure = options?.TangentialPressure, + Twist = options?.Twist, + AltitudeAngle = options?.AltitudeAngle, + AzimuthAngle = options?.AzimuthAngle + }); + + return Normalized(); + } + + public ISequentialSourceActions PointerUp(int button) + { + _pointerActions.Add(new Pointer.Up(button)); + + return Normalized(); + } + + public ISequentialSourceActions PointerMove(int x, int y, PointerMoveOptions? options = null) + { + _pointerActions.Add(new Pointer.Move(x, y) + { + Duration = options?.Duration, + Origin = options?.Origin, + Width = options?.Width, + Height = options?.Height, + Pressure = options?.Pressure, + TangentialPressure = options?.TangentialPressure, + Twist = options?.Twist, + AltitudeAngle = options?.AltitudeAngle, + AzimuthAngle = options?.AzimuthAngle + }); + + return Normalized(); + } + private SequentialSourceActions Normalized() { var max = new[] { _keyActions.Count(), _pointerActions.Count(), _wheelActions.Count(), _noneActions.Count() }.Max(); @@ -82,3 +134,28 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } + +public record PointerDownOptions : IPointerCommonProperties +{ + public int? Width { get; set; } + public int? Height { get; set; } + public double? Pressure { get; set; } + public double? TangentialPressure { get; set; } + public int? Twist { get; set; } + public double? AltitudeAngle { get; set; } + public double? AzimuthAngle { get; set; } +} + +public record PointerMoveOptions : IPointerCommonProperties +{ + public int? Duration { get; set; } + public Origin? Origin { get; set; } + + public int? Width { get; set; } + public int? Height { get; set; } + public double? Pressure { get; set; } + public double? TangentialPressure { get; set; } + public int? Twist { get; set; } + public double? AltitudeAngle { get; set; } + public double? AzimuthAngle { get; set; } +} diff --git a/dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs b/dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs new file mode 100644 index 0000000000000..33800788d191d --- /dev/null +++ b/dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs @@ -0,0 +1,88 @@ +using NUnit.Framework; +using OpenQA.Selenium.BiDi.Modules.BrowsingContext; +using OpenQA.Selenium.BiDi.Modules.Input; +using System.Threading.Tasks; + +namespace OpenQA.Selenium.BiDi.Input; + +class DefaultKeyboardTest : BiDiTestFixture +{ + [Test] + public async Task TestBasicKeyboardInput() + { + driver.Url = UrlBuilder.WhereIs("single_text_input.html"); + + var input = (await context.LocateNodesAsync(new Locator.Css("#textInput")))[0]; + + await context.Input.PerformActionsAsync(new SequentialSourceActions() + .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) + .PointerDown(0) + .PointerUp(0) + .Type("abc def")); + + Assert.That(driver.FindElement(By.Id("textInput")).GetAttribute("value"), Is.EqualTo("abc def")); + } + + [Test] + public async Task TestSendingKeyDownOnly() + { + driver.Url = UrlBuilder.WhereIs("key_logger.html"); + + var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; + + await context.Input.PerformActionsAsync(new SequentialSourceActions() + .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) + .PointerDown(0) + .PointerUp(0) + .KeyDown(Key.Shift)); + + Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keydown")); + } + + [Test] + public async Task TestSendingKeyUp() + { + driver.Url = UrlBuilder.WhereIs("key_logger.html"); + + var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; + + await context.Input.PerformActionsAsync(new SequentialSourceActions() + .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) + .PointerDown(0) + .PointerUp(0) + .KeyDown(Key.Shift) + .KeyUp(Key.Shift)); + + Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keyup")); + } + + [Test] + public async Task TestSendingKeysWithShiftPressed() + { + driver.Url = UrlBuilder.WhereIs("key_logger.html"); + + var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; + + await context.Input.PerformActionsAsync(new SequentialSourceActions() + .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) + .PointerDown(0) + .PointerUp(0) + .KeyDown(Key.Shift) + .Type("ab") + .KeyUp(Key.Shift)); + + Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keydown keydown keypress keyup keydown keypress keyup keyup")); + Assert.That(driver.FindElement(By.Id("theworks")).GetAttribute("value"), Is.EqualTo("AB")); + } + + [Test] + public async Task TestSendingKeysToActiveElement() + { + driver.Url = UrlBuilder.WhereIs("bodyTypingTest.html"); + + await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("ab")); + + Assert.That(driver.FindElement(By.Id("body_result")).Text, Does.EndWith("keypress keypress")); + Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo(" ")); + } +} From de2075fc77dddff5c7b341d8757913aeb5e4e29a Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Fri, 25 Oct 2024 01:09:03 +0300 Subject: [PATCH 59/60] Simplified required properties dto --- .../BrowsingContext/CaptureScreenshotCommand.cs | 6 +----- dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs | 5 +---- .../BiDi/Modules/Network/ContinueWithAuthCommand.cs | 6 +----- dotnet/src/webdriver/BiDi/Modules/Script/Target.cs | 11 ++--------- .../BiDi/Modules/Storage/GetCookiesCommand.cs | 6 +----- 5 files changed, 6 insertions(+), 28 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index e71311da58f23..df5f203c1d3fc 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -43,11 +43,7 @@ public abstract record ClipRectangle { public record Box(double X, double Y, double Width, double Height) : ClipRectangle; - public record Element(Script.SharedReference SharedReference) : ClipRectangle - { - [JsonPropertyName("element")] - public Script.SharedReference SharedReference { get; } = SharedReference; - } + public record Element([property: JsonPropertyName("element")] Script.SharedReference SharedReference) : ClipRectangle; } public record CaptureScreenshotResult(string Data) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs b/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs index f6716336dcc2a..5cc909cd6aabe 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/Origin.cs @@ -10,11 +10,8 @@ public record Viewport() : Origin; public record Pointer() : Origin; - public record Element(Script.SharedReference SharedReference) : Origin + public record Element([property: JsonPropertyName("element")] Script.SharedReference SharedReference) : Origin { public string Type { get; } = "element"; - - [JsonPropertyName("element")] - public Script.SharedReference SharedReference { get; } = SharedReference; } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs index fd1fbc38f76ea..c486066015ec4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs @@ -13,11 +13,7 @@ internal class ContinueWithAuthCommand(ContinueWithAuthParameters @params) : Com [JsonDerivedType(typeof(Cancel), "cancel")] internal abstract record ContinueWithAuthParameters(Request Request) : CommandParameters { - internal record Credentials(Request Request, AuthCredentials AuthCredentials) : ContinueWithAuthParameters(Request) - { - [JsonPropertyName("credentials")] - public AuthCredentials AuthCredentials { get; } = AuthCredentials; - } + internal record Credentials(Request Request, [property: JsonPropertyName("credentials")] AuthCredentials AuthCredentials) : ContinueWithAuthParameters(Request); internal record Default(Request Request) : ContinueWithAuthParameters(Request); diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs b/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs index 667bfe873880f..a05849a62c8b9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/Target.cs @@ -8,17 +8,10 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; [JsonDerivedType(typeof(Context))] public abstract record Target { - public record Realm(Script.Realm Target) : Target - { - [JsonPropertyName("realm")] - public Script.Realm Target { get; } = Target; - } + public record Realm([property: JsonPropertyName("realm")] Script.Realm Target) : Target; - public record Context(BrowsingContext.BrowsingContext Target) : Target + public record Context([property: JsonPropertyName("context")] BrowsingContext.BrowsingContext Target) : Target { - [JsonPropertyName("context")] - public BrowsingContext.BrowsingContext Target { get; } = Target; - public string? Sandbox { get; set; } } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs index 0f1e450dcbbf4..06cd0c09f6925 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs @@ -71,11 +71,7 @@ public class CookieFilter [JsonDerivedType(typeof(StorageKey), "storageKey")] public abstract record PartitionDescriptor { - public record Context(BrowsingContext.BrowsingContext Descriptor) : PartitionDescriptor - { - [JsonPropertyName("context")] - public BrowsingContext.BrowsingContext Descriptor { get; } = Descriptor; - } + public record Context([property: JsonPropertyName("context")] BrowsingContext.BrowsingContext Descriptor) : PartitionDescriptor; public record StorageKey : PartitionDescriptor { From a6ca10a69bea33a181e6612022e607334dedf2b6 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:43:38 +0300 Subject: [PATCH 60/60] Tests for Input module temporary are out --- .../src/webdriver/BiDi/Modules/Input/Key.cs | 12 +- .../Modules/Input/SequentialSourceActions.cs | 322 +++++++++--------- .../common/BiDi/Input/DefaultKeyboardTest.cs | 176 +++++----- .../common/BiDi/Input/DefaultMouseTest.cs | 82 ++--- 4 files changed, 296 insertions(+), 296 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs b/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs index c42f701f29862..a7d99ffca3ac9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/Key.cs @@ -1,8 +1,8 @@ -namespace OpenQA.Selenium.BiDi.Modules.Input; +//namespace OpenQA.Selenium.BiDi.Modules.Input; -partial record Key -{ - public const char Shift = '\uE008'; +//partial record Key +//{ +// public const char Shift = '\uE008'; - public const char Pause = '\uE00B'; -} +// public const char Pause = '\uE00B'; +//} diff --git a/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs index 6ed1d0899ec7e..dfdbc3f69a331 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Input/SequentialSourceActions.cs @@ -1,161 +1,161 @@ -using System.Collections; -using System.Collections.Generic; -using System.Linq; - -namespace OpenQA.Selenium.BiDi.Modules.Input; - -public interface ISequentialSourceActions : IEnumerable -{ - ISequentialSourceActions Pause(int duration); - - ISequentialSourceActions Type(string text); - ISequentialSourceActions KeyDown(char key); - ISequentialSourceActions KeyUp(char key); - - ISequentialSourceActions PointerDown(int button, PointerDownOptions? options = null); - ISequentialSourceActions PointerUp(int button); - ISequentialSourceActions PointerMove(int x, int y, PointerMoveOptions? options = null); -} - -public record SequentialSourceActions : ISequentialSourceActions -{ - private readonly KeyActions _keyActions = []; - private readonly PointerActions _pointerActions = []; - private readonly WheelActions _wheelActions = []; - private readonly WheelActions _noneActions = []; - - public ISequentialSourceActions Pause(int duration) - { - _noneActions.Add(new Pause { Duration = duration }); - - return Normalized(); - } - - public ISequentialSourceActions Type(string text) - { - _keyActions.Type(text); - - return Normalized(); - } - - public ISequentialSourceActions KeyDown(char key) - { - _keyActions.Add(new Key.Down(key)); - - return Normalized(); - } - - public ISequentialSourceActions KeyUp(char key) - { - _keyActions.Add(new Key.Up(key)); - - return Normalized(); - } - - public ISequentialSourceActions PointerDown(int button, PointerDownOptions? options = null) - { - _pointerActions.Add(new Pointer.Down(button) - { - Width = options?.Width, - Height = options?.Height, - Pressure = options?.Pressure, - TangentialPressure = options?.TangentialPressure, - Twist = options?.Twist, - AltitudeAngle = options?.AltitudeAngle, - AzimuthAngle = options?.AzimuthAngle - }); - - return Normalized(); - } - - public ISequentialSourceActions PointerUp(int button) - { - _pointerActions.Add(new Pointer.Up(button)); - - return Normalized(); - } - - public ISequentialSourceActions PointerMove(int x, int y, PointerMoveOptions? options = null) - { - _pointerActions.Add(new Pointer.Move(x, y) - { - Duration = options?.Duration, - Origin = options?.Origin, - Width = options?.Width, - Height = options?.Height, - Pressure = options?.Pressure, - TangentialPressure = options?.TangentialPressure, - Twist = options?.Twist, - AltitudeAngle = options?.AltitudeAngle, - AzimuthAngle = options?.AzimuthAngle - }); - - return Normalized(); - } - - private SequentialSourceActions Normalized() - { - var max = new[] { _keyActions.Count(), _pointerActions.Count(), _wheelActions.Count(), _noneActions.Count() }.Max(); - - for (int i = _keyActions.Count(); i < max; i++) - { - _keyActions.Add(new Pause()); - } - - for (int i = _pointerActions.Count(); i < max; i++) - { - _pointerActions.Add(new Pause()); - } - - for (int i = _wheelActions.Count(); i < max; i++) - { - _wheelActions.Add(new Pause()); - } - - for (int i = _noneActions.Count(); i < max; i++) - { - _noneActions.Add(new Pause()); - } - - return this; - } - - public IEnumerator GetEnumerator() - { - var sourceActions = new List - { - _keyActions, - _pointerActions, - _wheelActions, - _noneActions - }; - return sourceActions.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); -} - -public record PointerDownOptions : IPointerCommonProperties -{ - public int? Width { get; set; } - public int? Height { get; set; } - public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } - public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } -} - -public record PointerMoveOptions : IPointerCommonProperties -{ - public int? Duration { get; set; } - public Origin? Origin { get; set; } - - public int? Width { get; set; } - public int? Height { get; set; } - public double? Pressure { get; set; } - public double? TangentialPressure { get; set; } - public int? Twist { get; set; } - public double? AltitudeAngle { get; set; } - public double? AzimuthAngle { get; set; } -} +//using System.Collections; +//using System.Collections.Generic; +//using System.Linq; + +//namespace OpenQA.Selenium.BiDi.Modules.Input; + +//public interface ISequentialSourceActions : IEnumerable +//{ +// ISequentialSourceActions Pause(int duration); + +// ISequentialSourceActions Type(string text); +// ISequentialSourceActions KeyDown(char key); +// ISequentialSourceActions KeyUp(char key); + +// ISequentialSourceActions PointerDown(int button, PointerDownOptions? options = null); +// ISequentialSourceActions PointerUp(int button); +// ISequentialSourceActions PointerMove(int x, int y, PointerMoveOptions? options = null); +//} + +//public record SequentialSourceActions : ISequentialSourceActions +//{ +// private readonly KeyActions _keyActions = []; +// private readonly PointerActions _pointerActions = []; +// private readonly WheelActions _wheelActions = []; +// private readonly WheelActions _noneActions = []; + +// public ISequentialSourceActions Pause(int duration) +// { +// _noneActions.Add(new Pause { Duration = duration }); + +// return Normalized(); +// } + +// public ISequentialSourceActions Type(string text) +// { +// _keyActions.Type(text); + +// return Normalized(); +// } + +// public ISequentialSourceActions KeyDown(char key) +// { +// _keyActions.Add(new Key.Down(key)); + +// return Normalized(); +// } + +// public ISequentialSourceActions KeyUp(char key) +// { +// _keyActions.Add(new Key.Up(key)); + +// return Normalized(); +// } + +// public ISequentialSourceActions PointerDown(int button, PointerDownOptions? options = null) +// { +// _pointerActions.Add(new Pointer.Down(button) +// { +// Width = options?.Width, +// Height = options?.Height, +// Pressure = options?.Pressure, +// TangentialPressure = options?.TangentialPressure, +// Twist = options?.Twist, +// AltitudeAngle = options?.AltitudeAngle, +// AzimuthAngle = options?.AzimuthAngle +// }); + +// return Normalized(); +// } + +// public ISequentialSourceActions PointerUp(int button) +// { +// _pointerActions.Add(new Pointer.Up(button)); + +// return Normalized(); +// } + +// public ISequentialSourceActions PointerMove(int x, int y, PointerMoveOptions? options = null) +// { +// _pointerActions.Add(new Pointer.Move(x, y) +// { +// Duration = options?.Duration, +// Origin = options?.Origin, +// Width = options?.Width, +// Height = options?.Height, +// Pressure = options?.Pressure, +// TangentialPressure = options?.TangentialPressure, +// Twist = options?.Twist, +// AltitudeAngle = options?.AltitudeAngle, +// AzimuthAngle = options?.AzimuthAngle +// }); + +// return Normalized(); +// } + +// private SequentialSourceActions Normalized() +// { +// var max = new[] { _keyActions.Count(), _pointerActions.Count(), _wheelActions.Count(), _noneActions.Count() }.Max(); + +// for (int i = _keyActions.Count(); i < max; i++) +// { +// _keyActions.Add(new Pause()); +// } + +// for (int i = _pointerActions.Count(); i < max; i++) +// { +// _pointerActions.Add(new Pause()); +// } + +// for (int i = _wheelActions.Count(); i < max; i++) +// { +// _wheelActions.Add(new Pause()); +// } + +// for (int i = _noneActions.Count(); i < max; i++) +// { +// _noneActions.Add(new Pause()); +// } + +// return this; +// } + +// public IEnumerator GetEnumerator() +// { +// var sourceActions = new List +// { +// _keyActions, +// _pointerActions, +// _wheelActions, +// _noneActions +// }; +// return sourceActions.GetEnumerator(); +// } + +// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); +//} + +//public record PointerDownOptions : IPointerCommonProperties +//{ +// public int? Width { get; set; } +// public int? Height { get; set; } +// public double? Pressure { get; set; } +// public double? TangentialPressure { get; set; } +// public int? Twist { get; set; } +// public double? AltitudeAngle { get; set; } +// public double? AzimuthAngle { get; set; } +//} + +//public record PointerMoveOptions : IPointerCommonProperties +//{ +// public int? Duration { get; set; } +// public Origin? Origin { get; set; } + +// public int? Width { get; set; } +// public int? Height { get; set; } +// public double? Pressure { get; set; } +// public double? TangentialPressure { get; set; } +// public int? Twist { get; set; } +// public double? AltitudeAngle { get; set; } +// public double? AzimuthAngle { get; set; } +//} diff --git a/dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs b/dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs index 33800788d191d..f226719e17c0a 100644 --- a/dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultKeyboardTest.cs @@ -1,88 +1,88 @@ -using NUnit.Framework; -using OpenQA.Selenium.BiDi.Modules.BrowsingContext; -using OpenQA.Selenium.BiDi.Modules.Input; -using System.Threading.Tasks; - -namespace OpenQA.Selenium.BiDi.Input; - -class DefaultKeyboardTest : BiDiTestFixture -{ - [Test] - public async Task TestBasicKeyboardInput() - { - driver.Url = UrlBuilder.WhereIs("single_text_input.html"); - - var input = (await context.LocateNodesAsync(new Locator.Css("#textInput")))[0]; - - await context.Input.PerformActionsAsync(new SequentialSourceActions() - .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) - .PointerDown(0) - .PointerUp(0) - .Type("abc def")); - - Assert.That(driver.FindElement(By.Id("textInput")).GetAttribute("value"), Is.EqualTo("abc def")); - } - - [Test] - public async Task TestSendingKeyDownOnly() - { - driver.Url = UrlBuilder.WhereIs("key_logger.html"); - - var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; - - await context.Input.PerformActionsAsync(new SequentialSourceActions() - .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) - .PointerDown(0) - .PointerUp(0) - .KeyDown(Key.Shift)); - - Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keydown")); - } - - [Test] - public async Task TestSendingKeyUp() - { - driver.Url = UrlBuilder.WhereIs("key_logger.html"); - - var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; - - await context.Input.PerformActionsAsync(new SequentialSourceActions() - .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) - .PointerDown(0) - .PointerUp(0) - .KeyDown(Key.Shift) - .KeyUp(Key.Shift)); - - Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keyup")); - } - - [Test] - public async Task TestSendingKeysWithShiftPressed() - { - driver.Url = UrlBuilder.WhereIs("key_logger.html"); - - var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; - - await context.Input.PerformActionsAsync(new SequentialSourceActions() - .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) - .PointerDown(0) - .PointerUp(0) - .KeyDown(Key.Shift) - .Type("ab") - .KeyUp(Key.Shift)); - - Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keydown keydown keypress keyup keydown keypress keyup keyup")); - Assert.That(driver.FindElement(By.Id("theworks")).GetAttribute("value"), Is.EqualTo("AB")); - } - - [Test] - public async Task TestSendingKeysToActiveElement() - { - driver.Url = UrlBuilder.WhereIs("bodyTypingTest.html"); - - await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("ab")); - - Assert.That(driver.FindElement(By.Id("body_result")).Text, Does.EndWith("keypress keypress")); - Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo(" ")); - } -} +//using NUnit.Framework; +//using OpenQA.Selenium.BiDi.Modules.BrowsingContext; +//using OpenQA.Selenium.BiDi.Modules.Input; +//using System.Threading.Tasks; + +//namespace OpenQA.Selenium.BiDi.Input; + +//class DefaultKeyboardTest : BiDiTestFixture +//{ +// [Test] +// public async Task TestBasicKeyboardInput() +// { +// driver.Url = UrlBuilder.WhereIs("single_text_input.html"); + +// var input = (await context.LocateNodesAsync(new Locator.Css("#textInput")))[0]; + +// await context.Input.PerformActionsAsync(new SequentialSourceActions() +// .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) +// .PointerDown(0) +// .PointerUp(0) +// .Type("abc def")); + +// Assert.That(driver.FindElement(By.Id("textInput")).GetAttribute("value"), Is.EqualTo("abc def")); +// } + +// [Test] +// public async Task TestSendingKeyDownOnly() +// { +// driver.Url = UrlBuilder.WhereIs("key_logger.html"); + +// var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; + +// await context.Input.PerformActionsAsync(new SequentialSourceActions() +// .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) +// .PointerDown(0) +// .PointerUp(0) +// .KeyDown(Key.Shift)); + +// Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keydown")); +// } + +// [Test] +// public async Task TestSendingKeyUp() +// { +// driver.Url = UrlBuilder.WhereIs("key_logger.html"); + +// var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; + +// await context.Input.PerformActionsAsync(new SequentialSourceActions() +// .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) +// .PointerDown(0) +// .PointerUp(0) +// .KeyDown(Key.Shift) +// .KeyUp(Key.Shift)); + +// Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keyup")); +// } + +// [Test] +// public async Task TestSendingKeysWithShiftPressed() +// { +// driver.Url = UrlBuilder.WhereIs("key_logger.html"); + +// var input = (await context.LocateNodesAsync(new Locator.Css("#theworks")))[0]; + +// await context.Input.PerformActionsAsync(new SequentialSourceActions() +// .PointerMove(0, 0, new() { Origin = new Modules.Input.Origin.Element(new Modules.Script.SharedReference(input.SharedId)) }) +// .PointerDown(0) +// .PointerUp(0) +// .KeyDown(Key.Shift) +// .Type("ab") +// .KeyUp(Key.Shift)); + +// Assert.That(driver.FindElement(By.Id("result")).Text, Does.EndWith("keydown keydown keypress keyup keydown keypress keyup keyup")); +// Assert.That(driver.FindElement(By.Id("theworks")).GetAttribute("value"), Is.EqualTo("AB")); +// } + +// [Test] +// public async Task TestSendingKeysToActiveElement() +// { +// driver.Url = UrlBuilder.WhereIs("bodyTypingTest.html"); + +// await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("ab")); + +// Assert.That(driver.FindElement(By.Id("body_result")).Text, Does.EndWith("keypress keypress")); +// Assert.That(driver.FindElement(By.Id("result")).Text, Is.EqualTo(" ")); +// } +//} diff --git a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs index 0e682571399d0..c7408a83101f1 100644 --- a/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs +++ b/dotnet/test/common/BiDi/Input/DefaultMouseTest.cs @@ -1,49 +1,49 @@ -using NUnit.Framework; -using OpenQA.Selenium.BiDi.Modules.BrowsingContext; -using OpenQA.Selenium.BiDi.Modules.Input; -using System.Threading.Tasks; +//using NUnit.Framework; +//using OpenQA.Selenium.BiDi.Modules.BrowsingContext; +//using OpenQA.Selenium.BiDi.Modules.Input; +//using System.Threading.Tasks; -namespace OpenQA.Selenium.BiDi.Input; +//namespace OpenQA.Selenium.BiDi.Input; -class DefaultMouseTest : BiDiTestFixture -{ - [Test] - public async Task PerformDragAndDropWithMouse() - { - driver.Url = UrlBuilder.WhereIs("draggableLists.html"); +//class DefaultMouseTest : BiDiTestFixture +//{ +// [Test] +// public async Task PerformDragAndDropWithMouse() +// { +// driver.Url = UrlBuilder.WhereIs("draggableLists.html"); - await context.Input.PerformActionsAsync([ - new KeyActions - { - Actions = - { - new Key.Down('A'), - new Key.Up('B') - } - } - ]); +// await context.Input.PerformActionsAsync([ +// new KeyActions +// { +// Actions = +// { +// new Key.Down('A'), +// new Key.Up('B') +// } +// } +// ]); - await context.Input.PerformActionsAsync([new KeyActions - { - new Key.Down('A'), - new Key.Down('B'), - new Pause() - }]); +// await context.Input.PerformActionsAsync([new KeyActions +// { +// new Key.Down('A'), +// new Key.Down('B'), +// new Pause() +// }]); - await context.Input.PerformActionsAsync([new PointerActions - { - new Pointer.Down(0), - new Pointer.Up(0), - }]); - } +// await context.Input.PerformActionsAsync([new PointerActions +// { +// new Pointer.Down(0), +// new Pointer.Up(0), +// }]); +// } - //[Test] - public async Task PerformCombined() - { - await context.NavigateAsync("https://nuget.org", new() { Wait = ReadinessState.Complete }); +// //[Test] +// public async Task PerformCombined() +// { +// await context.NavigateAsync("https://nuget.org", new() { Wait = ReadinessState.Complete }); - await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("Hello").Pause(2000).KeyDown(Key.Shift).Type("World")); +// await context.Input.PerformActionsAsync(new SequentialSourceActions().Type("Hello").Pause(2000).KeyDown(Key.Shift).Type("World")); - await Task.Delay(3000); - } -} +// await Task.Delay(3000); +// } +//}