From 3efcdd7ecee96ce012ec9724de7bd89be2c4f1b6 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 16 Mar 2025 15:55:27 +0300 Subject: [PATCH 1/2] [dotnet] [bidi] Make `ClipRectangle` as not nested --- .../BrowsingContext/CaptureScreenshotCommand.cs | 13 ++++++------- .../BiDi/BrowsingContext/BrowsingContextTest.cs | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 328644b8ed82b..6323f306b9c94 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -48,14 +48,13 @@ public record struct ImageFormat(string Type) } [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -[JsonDerivedType(typeof(Box), "box")] -[JsonDerivedType(typeof(Element), "element")] -public abstract record ClipRectangle -{ - public record Box(double X, double Y, double Width, double Height) : ClipRectangle; +[JsonDerivedType(typeof(BoxClipRectangle), "box")] +[JsonDerivedType(typeof(ElementClipRectangle), "element")] +public abstract record ClipRectangle; - public record Element([property: JsonPropertyName("element")] Script.ISharedReference SharedReference) : ClipRectangle; -} +public record BoxClipRectangle(double X, double Y, double Width, double Height) : ClipRectangle; + +public record ElementClipRectangle([property: JsonPropertyName("element")] Script.ISharedReference SharedReference) : ClipRectangle; public record CaptureScreenshotResult(string Data) { diff --git a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs index 59f451fe421e4..59b0676933205 100644 --- a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs @@ -260,7 +260,7 @@ public async Task CanCaptureScreenshotWithParameters() var screenshot = await context.CaptureScreenshotAsync(new() { Origin = Origin.Document, - Clip = new ClipRectangle.Box(5, 5, 10, 10) + Clip = new BoxClipRectangle(5, 5, 10, 10) }); Assert.That(screenshot, Is.Not.Null); @@ -273,7 +273,7 @@ public async Task CanCaptureScreenshotOfViewport() var screenshot = await context.CaptureScreenshotAsync(new() { Origin = Origin.Viewport, - Clip = new ClipRectangle.Box(5, 5, 10, 10) + Clip = new BoxClipRectangle(5, 5, 10, 10) }); Assert.That(screenshot, Is.Not.Null); @@ -289,7 +289,7 @@ public async Task CanCaptureScreenshotOfElement() var screenshot = await context.CaptureScreenshotAsync(new() { - Clip = new ClipRectangle.Element(nodes[0]) + Clip = new ElementClipRectangle(nodes[0]) }); Assert.That(screenshot, Is.Not.Null); From 74fde27445bb435c387ca52fe7af2e5d620fb501 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 16 Mar 2025 16:02:35 +0300 Subject: [PATCH 2/2] Screenshot origin --- .../Json/BiDiJsonSerializerContext.cs | 1 - .../BrowsingContext/CaptureScreenshotCommand.cs | 14 +++++++------- .../BiDi/BrowsingContext/BrowsingContextTest.cs | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index 32c3335a61bb3..aa0ba1eca819c 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -119,7 +119,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Modules.BrowsingContext.UserPromptOpenedEventArgs))] [JsonSerializable(typeof(Modules.BrowsingContext.UserPromptClosedEventArgs))] -[JsonSerializable(typeof(Modules.BrowsingContext.Origin), TypeInfoPropertyName = "BrowsingContext_Origin")] [JsonSerializable(typeof(Modules.Network.BytesValue.String), TypeInfoPropertyName = "Network_BytesValue_String")] [JsonSerializable(typeof(Modules.Network.UrlPattern.String), TypeInfoPropertyName = "Network_UrlPattern_String")] diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 6323f306b9c94..bbede96ad4654 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -25,21 +25,21 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext; internal class CaptureScreenshotCommand(CaptureScreenshotCommandParameters @params) : Command(@params, "browsingContext.captureScreenshot"); -internal record CaptureScreenshotCommandParameters(BrowsingContext Context, Origin? Origin, ImageFormat? Format, ClipRectangle? Clip) : CommandParameters; +internal record CaptureScreenshotCommandParameters(BrowsingContext Context, CaptureScreenshotOptions.ScreenshotOrigin? Origin, ImageFormat? Format, ClipRectangle? Clip) : CommandParameters; public record CaptureScreenshotOptions : CommandOptions { - public Origin? Origin { get; set; } + public ScreenshotOrigin? Origin { get; set; } public ImageFormat? Format { get; set; } public ClipRectangle? Clip { get; set; } -} -public enum Origin -{ - Viewport, - Document + public enum ScreenshotOrigin + { + Viewport, + Document + } } public record struct ImageFormat(string Type) diff --git a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs index 59b0676933205..f5576d75d336a 100644 --- a/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs +++ b/dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs @@ -259,7 +259,7 @@ public async Task CanCaptureScreenshotWithParameters() { var screenshot = await context.CaptureScreenshotAsync(new() { - Origin = Origin.Document, + Origin = CaptureScreenshotOptions.ScreenshotOrigin.Document, Clip = new BoxClipRectangle(5, 5, 10, 10) }); @@ -272,7 +272,7 @@ public async Task CanCaptureScreenshotOfViewport() { var screenshot = await context.CaptureScreenshotAsync(new() { - Origin = Origin.Viewport, + Origin = CaptureScreenshotOptions.ScreenshotOrigin.Viewport, Clip = new BoxClipRectangle(5, 5, 10, 10) });