Skip to content

Commit 4b330ff

Browse files
nvborisenkosandeepsuryaprasad
authored andcommitted
[dotnet] [bidi] Make ClipRectangle as not nested (SeleniumHQ#15431)
1 parent fe43278 commit 4b330ff

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
119119

120120
[JsonSerializable(typeof(Modules.BrowsingContext.UserPromptOpenedEventArgs))]
121121
[JsonSerializable(typeof(Modules.BrowsingContext.UserPromptClosedEventArgs))]
122-
[JsonSerializable(typeof(Modules.BrowsingContext.Origin), TypeInfoPropertyName = "BrowsingContext_Origin")]
123122

124123
[JsonSerializable(typeof(Modules.Network.ContinueWithAuthParameters.Default), TypeInfoPropertyName = "Network_ContinueWithAuthParameters_Default")]
125124
[JsonSerializable(typeof(Modules.Network.AddInterceptCommand))]

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs

+13-14
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2525
internal class CaptureScreenshotCommand(CaptureScreenshotCommandParameters @params)
2626
: Command<CaptureScreenshotCommandParameters>(@params, "browsingContext.captureScreenshot");
2727

28-
internal record CaptureScreenshotCommandParameters(BrowsingContext Context, Origin? Origin, ImageFormat? Format, ClipRectangle? Clip) : CommandParameters;
28+
internal record CaptureScreenshotCommandParameters(BrowsingContext Context, CaptureScreenshotOptions.ScreenshotOrigin? Origin, ImageFormat? Format, ClipRectangle? Clip) : CommandParameters;
2929

3030
public record CaptureScreenshotOptions : CommandOptions
3131
{
32-
public Origin? Origin { get; set; }
32+
public ScreenshotOrigin? Origin { get; set; }
3333

3434
public ImageFormat? Format { get; set; }
3535

3636
public ClipRectangle? Clip { get; set; }
37-
}
3837

39-
public enum Origin
40-
{
41-
Viewport,
42-
Document
38+
public enum ScreenshotOrigin
39+
{
40+
Viewport,
41+
Document
42+
}
4343
}
4444

4545
public record struct ImageFormat(string Type)
@@ -48,14 +48,13 @@ public record struct ImageFormat(string Type)
4848
}
4949

5050
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
51-
[JsonDerivedType(typeof(Box), "box")]
52-
[JsonDerivedType(typeof(Element), "element")]
53-
public abstract record ClipRectangle
54-
{
55-
public record Box(double X, double Y, double Width, double Height) : ClipRectangle;
51+
[JsonDerivedType(typeof(BoxClipRectangle), "box")]
52+
[JsonDerivedType(typeof(ElementClipRectangle), "element")]
53+
public abstract record ClipRectangle;
5654

57-
public record Element([property: JsonPropertyName("element")] Script.ISharedReference SharedReference) : ClipRectangle;
58-
}
55+
public record BoxClipRectangle(double X, double Y, double Width, double Height) : ClipRectangle;
56+
57+
public record ElementClipRectangle([property: JsonPropertyName("element")] Script.ISharedReference SharedReference) : ClipRectangle;
5958

6059
public record CaptureScreenshotResult(string Data)
6160
{

dotnet/test/common/BiDi/BrowsingContext/BrowsingContextTest.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ public async Task CanCaptureScreenshotWithParameters()
259259
{
260260
var screenshot = await context.CaptureScreenshotAsync(new()
261261
{
262-
Origin = Origin.Document,
263-
Clip = new ClipRectangle.Box(5, 5, 10, 10)
262+
Origin = CaptureScreenshotOptions.ScreenshotOrigin.Document,
263+
Clip = new BoxClipRectangle(5, 5, 10, 10)
264264
});
265265

266266
Assert.That(screenshot, Is.Not.Null);
@@ -272,8 +272,8 @@ public async Task CanCaptureScreenshotOfViewport()
272272
{
273273
var screenshot = await context.CaptureScreenshotAsync(new()
274274
{
275-
Origin = Origin.Viewport,
276-
Clip = new ClipRectangle.Box(5, 5, 10, 10)
275+
Origin = CaptureScreenshotOptions.ScreenshotOrigin.Viewport,
276+
Clip = new BoxClipRectangle(5, 5, 10, 10)
277277
});
278278

279279
Assert.That(screenshot, Is.Not.Null);
@@ -289,7 +289,7 @@ public async Task CanCaptureScreenshotOfElement()
289289

290290
var screenshot = await context.CaptureScreenshotAsync(new()
291291
{
292-
Clip = new ClipRectangle.Element(nodes[0])
292+
Clip = new ElementClipRectangle(nodes[0])
293293
});
294294

295295
Assert.That(screenshot, Is.Not.Null);

0 commit comments

Comments
 (0)