From a1c1540af12901e1437fe8c25400ae7251731a41 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:59:35 +0300 Subject: [PATCH 1/5] Browser BrowsingContext Input --- .../BrowsingContext/BrowsingContextModule.cs | 81 +++---------------- .../CaptureScreenshotCommand.cs | 9 +-- .../Modules/BrowsingContext/CloseCommand.cs | 7 +- .../Modules/BrowsingContext/CreateCommand.cs | 9 +-- .../Modules/BrowsingContext/GetTreeCommand.cs | 7 +- .../HandleUserPromptCommand.cs | 7 +- .../BrowsingContext/LocateNodesCommand.cs | 9 +-- .../BrowsingContext/NavigateCommand.cs | 5 +- .../Modules/BrowsingContext/PrintCommand.cs | 17 +--- .../Modules/BrowsingContext/ReloadCommand.cs | 7 +- .../BrowsingContext/SetViewportCommand.cs | 7 +- 11 files changed, 24 insertions(+), 141 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs index 2f4ccc00c5e92..43e470c13ce1b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs @@ -30,14 +30,7 @@ public class BrowsingContextModule(Broker broker) : Module(broker) { public async Task CreateAsync(ContextType type, CreateOptions? options = null) { - var @params = new CreateCommandParameters(type); - - if (options is not null) - { - @params.ReferenceContext = options.ReferenceContext; - @params.Background = options.Background; - @params.UserContext = options.UserContext; - } + var @params = new CreateCommandParameters(type, options?.ReferenceContext, options?.Background, options?.UserContext); var createResult = await Broker.ExecuteCommandAsync(new CreateCommand(@params), options).ConfigureAwait(false); @@ -46,12 +39,7 @@ public async Task CreateAsync(ContextType type, CreateOptions? public async Task NavigateAsync(BrowsingContext context, string url, NavigateOptions? options = null) { - var @params = new NavigateCommandParameters(context, url); - - if (options is not null) - { - @params.Wait = options.Wait; - } + var @params = new NavigateCommandParameters(context, url, options?.Wait); return await Broker.ExecuteCommandAsync(new NavigateCommand(@params), options).ConfigureAwait(false); } @@ -65,35 +53,21 @@ public async Task ActivateAsync(BrowsingContext context, ActivateOptions? option public async Task LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null) { - var @params = new LocateNodesCommandParameters(context, locator); - - if (options is not null) - { - @params.MaxNodeCount = options.MaxNodeCount; - @params.SerializationOptions = options.SerializationOptions; - @params.StartNodes = options.StartNodes; - } + var @params = new LocateNodesCommandParameters(context, locator, options?.MaxNodeCount, options?.SerializationOptions, options?.StartNodes); return await Broker.ExecuteCommandAsync(new LocateNodesCommand(@params), options).ConfigureAwait(false); } public async Task CaptureScreenshotAsync(BrowsingContext context, CaptureScreenshotOptions? options = null) { - var @params = new CaptureScreenshotCommandParameters(context); - - if (options is not null) - { - @params.Origin = options.Origin; - @params.Format = options.Format; - @params.Clip = options.Clip; - } + var @params = new CaptureScreenshotCommandParameters(context, options?.Origin, options?.Format, options?.Clip); return await Broker.ExecuteCommandAsync(new CaptureScreenshotCommand(@params), options).ConfigureAwait(false); } public async Task CloseAsync(BrowsingContext context, CloseOptions? options = null) { - var @params = new CloseCommandParameters(context); + var @params = new CloseCommandParameters(context, options?.PromptUnload); await Broker.ExecuteCommandAsync(new CloseCommand(@params), options).ConfigureAwait(false); } @@ -107,39 +81,21 @@ public async Task TraverseHistoryAsync(BrowsingContext co public async Task ReloadAsync(BrowsingContext context, ReloadOptions? options = null) { - var @params = new ReloadCommandParameters(context); - - if (options is not null) - { - @params.IgnoreCache = options.IgnoreCache; - @params.Wait = options.Wait; - } + var @params = new ReloadCommandParameters(context, options?.IgnoreCache, options?.Wait); return await Broker.ExecuteCommandAsync(new ReloadCommand(@params), options).ConfigureAwait(false); } public async Task SetViewportAsync(BrowsingContext context, SetViewportOptions? options = null) { - var @params = new SetViewportCommandParameters(context); - - if (options is not null) - { - @params.Viewport = options.Viewport; - @params.DevicePixelRatio = options?.DevicePixelRatio; - } + var @params = new SetViewportCommandParameters(context, options?.Viewport, options?.DevicePixelRatio); await Broker.ExecuteCommandAsync(new SetViewportCommand(@params), options).ConfigureAwait(false); } public async Task> GetTreeAsync(GetTreeOptions? options = null) { - var @params = new GetTreeCommandParameters(); - - if (options is not null) - { - @params.MaxDepth = options.MaxDepth; - @params.Root = options.Root; - } + var @params = new GetTreeCommandParameters(options?.MaxDepth, options?.Root); var getTreeResult = await Broker.ExecuteCommandAsync(new GetTreeCommand(@params), options).ConfigureAwait(false); @@ -148,31 +104,14 @@ public async Task> GetTreeAsync(GetTreeOption public async Task PrintAsync(BrowsingContext context, PrintOptions? options = null) { - var @params = new PrintCommandParameters(context); - - if (options is not null) - { - @params.Background = options.Background; - @params.Margin = options.Margin; - @params.Orientation = options.Orientation; - @params.Page = options.Page; - @params.PageRanges = options.PageRanges; - @params.Scale = options.Scale; - @params.ShrinkToFit = options.ShrinkToFit; - } + var @params = new PrintCommandParameters(context, options?.Background, options?.Margin, options?.Orientation, options?.Page, options?.PageRanges, options?.Scale, options?.ShrinkToFit); return await Broker.ExecuteCommandAsync(new PrintCommand(@params), options).ConfigureAwait(false); } public async Task HandleUserPromptAsync(BrowsingContext context, HandleUserPromptOptions? options = null) { - var @params = new HandleUserPromptCommandParameters(context); - - if (options is not null) - { - @params.Accept = options.Accept; - @params.UserText = options.UserText; - } + var @params = new HandleUserPromptCommandParameters(context, options?.Accept, options?.UserText); await Broker.ExecuteCommandAsync(new HandleUserPromptCommand(@params), options).ConfigureAwait(false); } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 5af6bcda53d2c..242bfb0f0534c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -27,14 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class CaptureScreenshotCommand(CaptureScreenshotCommandParameters @params) : Command(@params, "browsingContext.captureScreenshot"); -internal record CaptureScreenshotCommandParameters(BrowsingContext Context) : CommandParameters -{ - public Origin? Origin { get; set; } - - public ImageFormat? Format { get; set; } - - public ClipRectangle? Clip { get; set; } -} +internal record CaptureScreenshotCommandParameters(BrowsingContext Context, Origin? Origin, ImageFormat? Format, ClipRectangle? Clip) : CommandParameters; public record CaptureScreenshotOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs index d335012b6569d..2561401a75dec 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs @@ -26,6 +26,9 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class CloseCommand(CloseCommandParameters @params) : Command(@params, "browsingContext.close"); -internal record CloseCommandParameters(BrowsingContext Context) : CommandParameters; +internal record CloseCommandParameters(BrowsingContext Context, bool? PromptUnload) : CommandParameters; -public record CloseOptions : CommandOptions; +public record CloseOptions : CommandOptions +{ + public bool? PromptUnload { get; set; } +} diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs index de967f4a109a2..fc0e95f9f52a4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs @@ -26,14 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class CreateCommand(CreateCommandParameters @params) : Command(@params, "browsingContext.create"); -internal record CreateCommandParameters(ContextType Type) : CommandParameters -{ - public BrowsingContext? ReferenceContext { get; set; } - - public bool? Background { get; set; } - - public Browser.UserContext? UserContext { get; set; } -} +internal record CreateCommandParameters(ContextType Type, BrowsingContext? ReferenceContext, bool? Background, Browser.UserContext? UserContext) : CommandParameters; public record CreateOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs index b271e8517012d..d226f57588cb0 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs @@ -27,12 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class GetTreeCommand(GetTreeCommandParameters @params) : Command(@params, "browsingContext.getTree"); -internal record GetTreeCommandParameters : CommandParameters -{ - public long? MaxDepth { get; set; } - - public BrowsingContext? Root { get; set; } -} +internal record GetTreeCommandParameters(long? MaxDepth, BrowsingContext? Root) : CommandParameters; public record GetTreeOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs index 4e75e6620c3b7..acd09150d7ca9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs @@ -26,12 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; class HandleUserPromptCommand(HandleUserPromptCommandParameters @params) : Command(@params, "browsingContext.handleUserPrompt"); -internal record HandleUserPromptCommandParameters(BrowsingContext Context) : CommandParameters -{ - public bool? Accept { get; set; } - - public string? UserText { get; set; } -} +internal record HandleUserPromptCommandParameters(BrowsingContext Context, bool? Accept, string? UserText) : CommandParameters; public record HandleUserPromptOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs index 9e58c9eb92a76..0093bc10f45ac 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs @@ -28,14 +28,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class LocateNodesCommand(LocateNodesCommandParameters @params) : Command(@params, "browsingContext.locateNodes"); -internal record LocateNodesCommandParameters(BrowsingContext Context, Locator Locator) : CommandParameters -{ - public long? MaxNodeCount { get; set; } - - public Script.SerializationOptions? SerializationOptions { get; set; } - - public IEnumerable? StartNodes { get; set; } -} +internal record LocateNodesCommandParameters(BrowsingContext Context, Locator Locator, long? MaxNodeCount, Script.SerializationOptions? SerializationOptions, IEnumerable? StartNodes) : CommandParameters; public record LocateNodesOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs index ff1714b30a5f0..6aea4eb9ce521 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs @@ -26,10 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class NavigateCommand(NavigateCommandParameters @params) : Command(@params, "browsingContext.navigate"); -internal record NavigateCommandParameters(BrowsingContext Context, string Url) : CommandParameters -{ - public ReadinessState? Wait { get; set; } -} +internal record NavigateCommandParameters(BrowsingContext Context, string Url, ReadinessState? Wait) : CommandParameters; public record NavigateOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs index 47046cabfae7f..f59d1076d9cc4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs @@ -28,22 +28,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class PrintCommand(PrintCommandParameters @params) : Command(@params, "browsingContext.print"); -internal record PrintCommandParameters(BrowsingContext Context) : CommandParameters -{ - public bool? Background { get; set; } - - public PrintMargin? Margin { get; set; } - - public PrintOrientation? Orientation { get; set; } - - public PrintPage? Page { get; set; } - - public IEnumerable? PageRanges { get; set; } - - public double? Scale { get; set; } - - public bool? ShrinkToFit { get; set; } -} +internal record PrintCommandParameters(BrowsingContext Context, bool? Background, PrintMargin? Margin, PrintOrientation? Orientation, PrintPage? Page, IEnumerable? PageRanges, double? Scale, bool? ShrinkToFit) : CommandParameters; public record PrintOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs index 0ec8e4c9ff612..32de5805269f9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs @@ -26,12 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class ReloadCommand(ReloadCommandParameters @params) : Command(@params, "browsingContext.reload"); -internal record ReloadCommandParameters(BrowsingContext Context) : CommandParameters -{ - public bool? IgnoreCache { get; set; } - - public ReadinessState? Wait { get; set; } -} +internal record ReloadCommandParameters(BrowsingContext Context, bool? IgnoreCache, ReadinessState? Wait) : CommandParameters; public record ReloadOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs index 75dc8252986b3..23bfef7f3f074 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs @@ -26,12 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class SetViewportCommand(SetViewportCommandParameters @params) : Command(@params, "browsingContext.setViewport"); -internal record SetViewportCommandParameters(BrowsingContext Context) : CommandParameters -{ - public Viewport? Viewport { get; set; } - - public double? DevicePixelRatio { get; set; } -} +internal record SetViewportCommandParameters(BrowsingContext Context, Viewport? Viewport, double? DevicePixelRatio) : CommandParameters; public record SetViewportOptions : CommandOptions { From e45a627ec99be5ba6de141a7efcb9a9a8c117d33 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:12:48 +0300 Subject: [PATCH 2/5] Network --- .../Modules/Network/AddInterceptCommand.cs | 7 +-- .../Modules/Network/ContinueRequestCommand.cs | 13 +---- .../Network/ContinueResponseCommand.cs | 13 +---- .../BiDi/Modules/Network/NetworkModule.cs | 48 ++----------------- .../Modules/Network/ProvideResponseCommand.cs | 13 +---- .../Network/SetCacheBehaviorCommand.cs | 5 +- 6 files changed, 10 insertions(+), 89 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs index c8d9525d9235a..addd8ba40692f 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs @@ -27,12 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; internal class AddInterceptCommand(AddInterceptCommandParameters @params) : Command(@params, "network.addIntercept"); -internal record AddInterceptCommandParameters(IEnumerable Phases) : CommandParameters -{ - public IEnumerable? Contexts { get; set; } - - public IEnumerable? UrlPatterns { get; set; } -} +internal record AddInterceptCommandParameters(IEnumerable Phases, IEnumerable? Contexts, IEnumerable? UrlPatterns) : CommandParameters; public record AddInterceptOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs index 07533727fe15d..726157e40b1df 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs @@ -27,18 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; internal class ContinueRequestCommand(ContinueRequestCommandParameters @params) : Command(@params, "network.continueRequest"); -internal record ContinueRequestCommandParameters(Request Request) : CommandParameters -{ - public BytesValue? Body { get; set; } - - public IEnumerable? Cookies { get; set; } - - public IEnumerable
? Headers { get; set; } - - public string? Method { get; set; } - - public string? Url { get; set; } -} +internal record ContinueRequestCommandParameters(Request Request, BytesValue? Body, IEnumerable? Cookies, IEnumerable
? Headers, string? Method, string? Url) : CommandParameters; public record ContinueRequestOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs index 8374957a75fd1..aca666e389f97 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs @@ -27,18 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; internal class ContinueResponseCommand(ContinueResponseCommandParameters @params) : Command(@params, "network.continueResponse"); -internal record ContinueResponseCommandParameters(Request Request) : CommandParameters -{ - public IEnumerable? Cookies { get; set; } - - public IEnumerable? Credentials { get; set; } - - public IEnumerable
? Headers { get; set; } - - public string? ReasonPhrase { get; set; } - - public long? StatusCode { get; set; } -} +internal record ContinueResponseCommandParameters(Request Request, IEnumerable? Cookies, IEnumerable? Credentials, IEnumerable
? Headers, string? ReasonPhrase, long? StatusCode) : CommandParameters; public record ContinueResponseOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs index 2589f3727df5c..be46a4ca71be8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs @@ -30,13 +30,7 @@ public sealed class NetworkModule(Broker broker) : Module(broker) { internal async Task AddInterceptAsync(IEnumerable phases, AddInterceptOptions? options = null) { - var @params = new AddInterceptCommandParameters(phases); - - if (options is not null) - { - @params.Contexts = options.Contexts; - @params.UrlPatterns = options.UrlPatterns; - } + var @params = new AddInterceptCommandParameters(phases, options?.Contexts, options?.UrlPatterns); var result = await Broker.ExecuteCommandAsync(new AddInterceptCommand(@params), options).ConfigureAwait(false); @@ -70,12 +64,7 @@ public async Task InterceptResponseAsync(Func InterceptAuthAsync(Func(@params, "network.provideResponse"); -internal record ProvideResponseCommandParameters(Request Request) : CommandParameters -{ - public BytesValue? Body { get; set; } - - public IEnumerable? Cookies { get; set; } - - public IEnumerable
? Headers { get; set; } - - public string? ReasonPhrase { get; set; } - - public long? StatusCode { get; set; } -} +internal record ProvideResponseCommandParameters(Request Request, BytesValue? Body, IEnumerable? Cookies, IEnumerable
? Headers, string? ReasonPhrase, long? StatusCode) : CommandParameters; public record ProvideResponseOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs index 15ca3014c2d6c..d144c048fd227 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs @@ -27,10 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Network; internal class SetCacheBehaviorCommand(SetCacheBehaviorCommandParameters @params) : Command(@params, "network.setCacheBehavior"); -internal record SetCacheBehaviorCommandParameters(CacheBehavior CacheBehavior) : CommandParameters -{ - public IEnumerable? Contexts { get; set; } -} +internal record SetCacheBehaviorCommandParameters(CacheBehavior CacheBehavior, IEnumerable? Contexts) : CommandParameters; public record SetCacheBehaviorOptions : CommandOptions { From e9a55a4673187a54b781e26051b313d1d3ec8c46 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:24:05 +0300 Subject: [PATCH 3/5] Script --- .../Modules/Script/AddPreloadScriptCommand.cs | 9 +---- .../Modules/Script/CallFunctionCommand.cs | 17 ++------- .../BiDi/Modules/Script/EvaluateCommand.cs | 9 +---- .../BiDi/Modules/Script/GetRealmsCommand.cs | 7 +--- .../BiDi/Modules/Script/ScriptModule.cs | 38 ++----------------- 5 files changed, 10 insertions(+), 70 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs index 871b327a6c79a..9c04a66d3fc9b 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs @@ -27,14 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; internal class AddPreloadScriptCommand(AddPreloadScriptCommandParameters @params) : Command(@params, "script.addPreloadScript"); -internal record AddPreloadScriptCommandParameters(string FunctionDeclaration) : CommandParameters -{ - public IEnumerable? Arguments { get; set; } - - public IEnumerable? Contexts { get; set; } - - public string? Sandbox { get; set; } -} +internal record AddPreloadScriptCommandParameters(string FunctionDeclaration, IEnumerable? Arguments, IEnumerable? Contexts, string? Sandbox) : CommandParameters; public record AddPreloadScriptOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs index 8f7b172fe8072..77d711a83a909 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs @@ -27,28 +27,17 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; internal class CallFunctionCommand(CallFunctionCommandParameters @params) : Command(@params, "script.callFunction"); -internal record CallFunctionCommandParameters(string FunctionDeclaration, bool AwaitPromise, Target Target) : CommandParameters -{ - public IEnumerable? Arguments { get; set; } - - public ResultOwnership? ResultOwnership { get; set; } - - public SerializationOptions? SerializationOptions { get; set; } - - public LocalValue? This { get; set; } - - public bool? UserActivation { get; set; } -} +internal record CallFunctionCommandParameters(string FunctionDeclaration, bool AwaitPromise, Target Target, IEnumerable? Arguments, ResultOwnership? ResultOwnership, SerializationOptions? SerializationOptions, LocalValue? This, bool? UserActivation) : CommandParameters; public record CallFunctionOptions : CommandOptions { - public IEnumerable? Arguments { get; set; } + public IEnumerable? Arguments { get; set; } public ResultOwnership? ResultOwnership { get; set; } public SerializationOptions? SerializationOptions { get; set; } - public object? This { get; set; } + public LocalValue? This { get; set; } public bool? UserActivation { get; set; } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs index 4559077094ad4..cb88c9db4ac25 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs @@ -26,14 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; internal class EvaluateCommand(EvaluateCommandParameters @params) : Command(@params, "script.evaluate"); -internal record EvaluateCommandParameters(string Expression, Target Target, bool AwaitPromise) : CommandParameters -{ - public ResultOwnership? ResultOwnership { get; set; } - - public SerializationOptions? SerializationOptions { get; set; } - - public bool? UserActivation { get; set; } -} +internal record EvaluateCommandParameters(string Expression, Target Target, bool AwaitPromise, ResultOwnership? ResultOwnership, SerializationOptions? SerializationOptions, bool? UserActivation) : CommandParameters; public record EvaluateOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs index d929c18ed1c4c..516d81d9498ed 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs @@ -28,12 +28,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; internal class GetRealmsCommand(GetRealmsCommandParameters @params) : Command(@params, "script.getRealms"); -internal record GetRealmsCommandParameters : CommandParameters -{ - public BrowsingContext.BrowsingContext? Context { get; set; } - - public RealmType? Type { get; set; } -} +internal record GetRealmsCommandParameters(BrowsingContext.BrowsingContext? Context, RealmType? Type) : CommandParameters; public record GetRealmsOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs index 7aa516480da01..b7c8754be3c5d 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs @@ -19,7 +19,6 @@ using OpenQA.Selenium.BiDi.Communication; using System; -using System.Linq; using System.Threading.Tasks; #nullable enable @@ -30,14 +29,7 @@ public sealed class ScriptModule(Broker broker) : Module(broker) { public async Task EvaluateAsync(string expression, bool awaitPromise, Target target, EvaluateOptions? options = null) { - var @params = new EvaluateCommandParameters(expression, target, awaitPromise); - - if (options is not null) - { - @params.ResultOwnership = options.ResultOwnership; - @params.SerializationOptions = options.SerializationOptions; - @params.UserActivation = options.UserActivation; - } + var @params = new EvaluateCommandParameters(expression, target, awaitPromise, options?.ResultOwnership, options?.SerializationOptions, options?.UserActivation); var result = await Broker.ExecuteCommandAsync(new EvaluateCommand(@params), options).ConfigureAwait(false); @@ -58,16 +50,7 @@ public sealed class ScriptModule(Broker broker) : Module(broker) public async Task CallFunctionAsync(string functionDeclaration, bool awaitPromise, Target target, CallFunctionOptions? options = null) { - var @params = new CallFunctionCommandParameters(functionDeclaration, awaitPromise, target); - - if (options is not null) - { - @params.Arguments = options.Arguments?.Select(LocalValue.ConvertFrom); - @params.ResultOwnership = options.ResultOwnership; - @params.SerializationOptions = options.SerializationOptions; - @params.This = LocalValue.ConvertFrom(options.This); - @params.UserActivation = options.UserActivation; - } + var @params = new CallFunctionCommandParameters(functionDeclaration, awaitPromise, target, options?.Arguments, options?.ResultOwnership, options?.SerializationOptions, options?.This, options?.UserActivation); var result = await Broker.ExecuteCommandAsync(new CallFunctionCommand(@params), options).ConfigureAwait(false); @@ -88,27 +71,14 @@ public sealed class ScriptModule(Broker broker) : Module(broker) public async Task GetRealmsAsync(GetRealmsOptions? options = null) { - var @params = new GetRealmsCommandParameters(); - - if (options is not null) - { - @params.Context = options.Context; - @params.Type = options.Type; - } + var @params = new GetRealmsCommandParameters(options?.Context, options?.Type); return await Broker.ExecuteCommandAsync(new GetRealmsCommand(@params), options).ConfigureAwait(false); } public async Task AddPreloadScriptAsync(string functionDeclaration, AddPreloadScriptOptions? options = null) { - var @params = new AddPreloadScriptCommandParameters(functionDeclaration); - - if (options is not null) - { - @params.Contexts = options.Contexts; - @params.Arguments = options.Arguments; - @params.Sandbox = options.Sandbox; - } + var @params = new AddPreloadScriptCommandParameters(functionDeclaration, options?.Arguments, options?.Contexts, options?.Sandbox); var result = await Broker.ExecuteCommandAsync(new AddPreloadScriptCommand(@params), options).ConfigureAwait(false); From 5947c46c19f4fa9c9e1866f1f7bda6d114d6fea2 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:29:27 +0300 Subject: [PATCH 4/5] Session --- .../webdriver/BiDi/Modules/Session/SessionModule.cs | 13 +++---------- .../BiDi/Modules/Session/SubscribeCommand.cs | 5 +---- .../BiDi/Modules/Session/UnsubscribeCommand.cs | 9 ++++----- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs b/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs index c26969a2b59a0..fed4004232273 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs @@ -34,12 +34,7 @@ public async Task StatusAsync(StatusOptions? options = null) public async Task SubscribeAsync(IEnumerable events, SubscribeOptions? options = null) { - var @params = new SubscribeCommandParameters(events); - - if (options is not null) - { - @params.Contexts = options.Contexts; - } + var @params = new SubscribeCommandParameters(events, options?.Contexts); return await Broker.ExecuteCommandAsync(new(@params), options).ConfigureAwait(false); } @@ -51,11 +46,9 @@ public async Task UnsubscribeAsync(IEnumerable subscriptions, Unsu await Broker.ExecuteCommandAsync(new UnsubscribeByIdCommand(@params), options).ConfigureAwait(false); } - public async Task UnsubscribeAsync(IEnumerable eventNames = null, UnsubscribeByAttributesOptions? options = null) + public async Task UnsubscribeAsync(IEnumerable eventNames, UnsubscribeByAttributesOptions? options = null) { - var @params = new UnsubscribeByAttributesCommandParameters(eventNames); - - @params.Contexts = options?.Contexts; + var @params = new UnsubscribeByAttributesCommandParameters(eventNames, options?.Contexts); await Broker.ExecuteCommandAsync(new UnsubscribeByAttributesCommand(@params), options).ConfigureAwait(false); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs index 44cd432028552..154a327f836ad 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs @@ -27,10 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Session; internal class SubscribeCommand(SubscribeCommandParameters @params) : Command(@params, "session.subscribe"); -internal record SubscribeCommandParameters(IEnumerable Events) : CommandParameters -{ - public IEnumerable? Contexts { get; set; } -} +internal record SubscribeCommandParameters(IEnumerable Events, IEnumerable? Contexts) : CommandParameters; public record SubscribeOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs index 72f8a28bf8e61..a01d3259405bc 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs @@ -35,12 +35,11 @@ internal record UnsubscribeByIdCommandParameters(IEnumerable Subsc public record UnsubscribeByIdOptions : CommandOptions; -internal record UnsubscribeByAttributesCommandParameters(IEnumerable Events) : CommandParameters -{ - [Obsolete("Contexts param is deprecated and will be removed in the future versions")] +internal record UnsubscribeByAttributesCommandParameters( + IEnumerable Events, + [property: Obsolete("Contexts param is deprecated and will be removed in the future versions")] // https://w3c.github.io/webdriver-bidi/#type-session-UnsubscribeByAttributesRequest - public IEnumerable? Contexts { get; set; } -} + IEnumerable? Contexts) : CommandParameters; public record UnsubscribeByAttributesOptions : CommandOptions { From 0e66c1b6956471c0628e88aecbdc175043b76efe Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:33:11 +0300 Subject: [PATCH 5/5] Storage --- .../Modules/Storage/DeleteCookiesCommand.cs | 7 +----- .../BiDi/Modules/Storage/GetCookiesCommand.cs | 7 +----- .../BiDi/Modules/Storage/SetCookieCommand.cs | 5 +--- .../BiDi/Modules/Storage/StorageModule.cs | 23 +++---------------- 4 files changed, 6 insertions(+), 36 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs index f031501b83c12..ba932e30dc3ec 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs @@ -26,12 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Storage; internal class DeleteCookiesCommand(DeleteCookiesCommandParameters @params) : Command(@params, "storage.deleteCookies"); -internal record DeleteCookiesCommandParameters : CommandParameters -{ - public CookieFilter? Filter { get; set; } - - public PartitionDescriptor? Partition { get; set; } -} +internal record DeleteCookiesCommandParameters(CookieFilter? Filter, PartitionDescriptor? Partition) : CommandParameters; public record DeleteCookiesOptions : GetCookiesOptions; diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs index 7210210cb04b0..8c188c0a6e868 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs @@ -30,12 +30,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Storage; internal class GetCookiesCommand(GetCookiesCommandParameters @params) : Command(@params, "storage.getCookies"); -internal record GetCookiesCommandParameters : CommandParameters -{ - public CookieFilter? Filter { get; set; } - - public PartitionDescriptor? Partition { get; set; } -} +internal record GetCookiesCommandParameters(CookieFilter? Filter, PartitionDescriptor? Partition) : CommandParameters; public record GetCookiesOptions : CommandOptions { diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs index 03909a8b5c0ec..5ea465612d6bc 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs @@ -27,10 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Storage; internal class SetCookieCommand(SetCookieCommandParameters @params) : Command(@params, "storage.setCookie"); -internal record SetCookieCommandParameters(PartialCookie Cookie) : CommandParameters -{ - public PartitionDescriptor? Partition { get; set; } -} +internal record SetCookieCommandParameters(PartialCookie Cookie, PartitionDescriptor? Partition) : CommandParameters; public record PartialCookie(string Name, Network.BytesValue Value, string Domain) { diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs index 9aa51cafd2460..b27ce83af31c4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs @@ -28,38 +28,21 @@ public class StorageModule(Broker broker) : Module(broker) { public async Task GetCookiesAsync(GetCookiesOptions? options = null) { - var @params = new GetCookiesCommandParameters(); - - if (options is not null) - { - @params.Filter = options.Filter; - @params.Partition = options.Partition; - } + var @params = new GetCookiesCommandParameters(options?.Filter, options?.Partition); return await Broker.ExecuteCommandAsync(new GetCookiesCommand(@params), options).ConfigureAwait(false); } public async Task DeleteCookiesAsync(DeleteCookiesOptions? options = null) { - var @params = new DeleteCookiesCommandParameters(); - - if (options is not null) - { - @params.Filter = options.Filter; - @params.Partition = options.Partition; - } + var @params = new DeleteCookiesCommandParameters(options?.Filter, options?.Partition); return await Broker.ExecuteCommandAsync(new DeleteCookiesCommand(@params), options).ConfigureAwait(false); } public async Task SetCookieAsync(PartialCookie cookie, SetCookieOptions? options = null) { - var @params = new SetCookieCommandParameters(cookie); - - if (options is not null) - { - @params.Partition = options.Partition; - } + var @params = new SetCookieCommandParameters(cookie, options?.Partition); return await Broker.ExecuteCommandAsync(new SetCookieCommand(@params), options).ConfigureAwait(false); }