Skip to content

Commit 8f424e2

Browse files
authored
[dotnet][bidi] Add optional PromptUnload parameter when closing BrowsingContext and compiler helps (#15254)
1 parent 37be72e commit 8f424e2

29 files changed

+58
-355
lines changed

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

+10-71
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@ public class BrowsingContextModule(Broker broker) : Module(broker)
3030
{
3131
public async Task<BrowsingContext> CreateAsync(ContextType type, CreateOptions? options = null)
3232
{
33-
var @params = new CreateCommandParameters(type);
34-
35-
if (options is not null)
36-
{
37-
@params.ReferenceContext = options.ReferenceContext;
38-
@params.Background = options.Background;
39-
@params.UserContext = options.UserContext;
40-
}
33+
var @params = new CreateCommandParameters(type, options?.ReferenceContext, options?.Background, options?.UserContext);
4134

4235
var createResult = await Broker.ExecuteCommandAsync<CreateCommand, CreateResult>(new CreateCommand(@params), options).ConfigureAwait(false);
4336

@@ -46,12 +39,7 @@ public async Task<BrowsingContext> CreateAsync(ContextType type, CreateOptions?
4639

4740
public async Task<NavigateResult> NavigateAsync(BrowsingContext context, string url, NavigateOptions? options = null)
4841
{
49-
var @params = new NavigateCommandParameters(context, url);
50-
51-
if (options is not null)
52-
{
53-
@params.Wait = options.Wait;
54-
}
42+
var @params = new NavigateCommandParameters(context, url, options?.Wait);
5543

5644
return await Broker.ExecuteCommandAsync<NavigateCommand, NavigateResult>(new NavigateCommand(@params), options).ConfigureAwait(false);
5745
}
@@ -65,35 +53,21 @@ public async Task ActivateAsync(BrowsingContext context, ActivateOptions? option
6553

6654
public async Task<LocateNodesResult> LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null)
6755
{
68-
var @params = new LocateNodesCommandParameters(context, locator);
69-
70-
if (options is not null)
71-
{
72-
@params.MaxNodeCount = options.MaxNodeCount;
73-
@params.SerializationOptions = options.SerializationOptions;
74-
@params.StartNodes = options.StartNodes;
75-
}
56+
var @params = new LocateNodesCommandParameters(context, locator, options?.MaxNodeCount, options?.SerializationOptions, options?.StartNodes);
7657

7758
return await Broker.ExecuteCommandAsync<LocateNodesCommand, LocateNodesResult>(new LocateNodesCommand(@params), options).ConfigureAwait(false);
7859
}
7960

8061
public async Task<CaptureScreenshotResult> CaptureScreenshotAsync(BrowsingContext context, CaptureScreenshotOptions? options = null)
8162
{
82-
var @params = new CaptureScreenshotCommandParameters(context);
83-
84-
if (options is not null)
85-
{
86-
@params.Origin = options.Origin;
87-
@params.Format = options.Format;
88-
@params.Clip = options.Clip;
89-
}
63+
var @params = new CaptureScreenshotCommandParameters(context, options?.Origin, options?.Format, options?.Clip);
9064

9165
return await Broker.ExecuteCommandAsync<CaptureScreenshotCommand, CaptureScreenshotResult>(new CaptureScreenshotCommand(@params), options).ConfigureAwait(false);
9266
}
9367

9468
public async Task CloseAsync(BrowsingContext context, CloseOptions? options = null)
9569
{
96-
var @params = new CloseCommandParameters(context);
70+
var @params = new CloseCommandParameters(context, options?.PromptUnload);
9771

9872
await Broker.ExecuteCommandAsync(new CloseCommand(@params), options).ConfigureAwait(false);
9973
}
@@ -107,39 +81,21 @@ public async Task<TraverseHistoryResult> TraverseHistoryAsync(BrowsingContext co
10781

10882
public async Task<NavigateResult> ReloadAsync(BrowsingContext context, ReloadOptions? options = null)
10983
{
110-
var @params = new ReloadCommandParameters(context);
111-
112-
if (options is not null)
113-
{
114-
@params.IgnoreCache = options.IgnoreCache;
115-
@params.Wait = options.Wait;
116-
}
84+
var @params = new ReloadCommandParameters(context, options?.IgnoreCache, options?.Wait);
11785

11886
return await Broker.ExecuteCommandAsync<ReloadCommand, NavigateResult>(new ReloadCommand(@params), options).ConfigureAwait(false);
11987
}
12088

12189
public async Task SetViewportAsync(BrowsingContext context, SetViewportOptions? options = null)
12290
{
123-
var @params = new SetViewportCommandParameters(context);
124-
125-
if (options is not null)
126-
{
127-
@params.Viewport = options.Viewport;
128-
@params.DevicePixelRatio = options?.DevicePixelRatio;
129-
}
91+
var @params = new SetViewportCommandParameters(context, options?.Viewport, options?.DevicePixelRatio);
13092

13193
await Broker.ExecuteCommandAsync(new SetViewportCommand(@params), options).ConfigureAwait(false);
13294
}
13395

13496
public async Task<IReadOnlyList<BrowsingContextInfo>> GetTreeAsync(GetTreeOptions? options = null)
13597
{
136-
var @params = new GetTreeCommandParameters();
137-
138-
if (options is not null)
139-
{
140-
@params.MaxDepth = options.MaxDepth;
141-
@params.Root = options.Root;
142-
}
98+
var @params = new GetTreeCommandParameters(options?.MaxDepth, options?.Root);
14399

144100
var getTreeResult = await Broker.ExecuteCommandAsync<GetTreeCommand, GetTreeResult>(new GetTreeCommand(@params), options).ConfigureAwait(false);
145101

@@ -148,31 +104,14 @@ public async Task<IReadOnlyList<BrowsingContextInfo>> GetTreeAsync(GetTreeOption
148104

149105
public async Task<PrintResult> PrintAsync(BrowsingContext context, PrintOptions? options = null)
150106
{
151-
var @params = new PrintCommandParameters(context);
152-
153-
if (options is not null)
154-
{
155-
@params.Background = options.Background;
156-
@params.Margin = options.Margin;
157-
@params.Orientation = options.Orientation;
158-
@params.Page = options.Page;
159-
@params.PageRanges = options.PageRanges;
160-
@params.Scale = options.Scale;
161-
@params.ShrinkToFit = options.ShrinkToFit;
162-
}
107+
var @params = new PrintCommandParameters(context, options?.Background, options?.Margin, options?.Orientation, options?.Page, options?.PageRanges, options?.Scale, options?.ShrinkToFit);
163108

164109
return await Broker.ExecuteCommandAsync<PrintCommand, PrintResult>(new PrintCommand(@params), options).ConfigureAwait(false);
165110
}
166111

167112
public async Task HandleUserPromptAsync(BrowsingContext context, HandleUserPromptOptions? options = null)
168113
{
169-
var @params = new HandleUserPromptCommandParameters(context);
170-
171-
if (options is not null)
172-
{
173-
@params.Accept = options.Accept;
174-
@params.UserText = options.UserText;
175-
}
114+
var @params = new HandleUserPromptCommandParameters(context, options?.Accept, options?.UserText);
176115

177116
await Broker.ExecuteCommandAsync(new HandleUserPromptCommand(@params), options).ConfigureAwait(false);
178117
}

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2727
internal class CaptureScreenshotCommand(CaptureScreenshotCommandParameters @params)
2828
: Command<CaptureScreenshotCommandParameters>(@params, "browsingContext.captureScreenshot");
2929

30-
internal record CaptureScreenshotCommandParameters(BrowsingContext Context) : CommandParameters
31-
{
32-
public Origin? Origin { get; set; }
33-
34-
public ImageFormat? Format { get; set; }
35-
36-
public ClipRectangle? Clip { get; set; }
37-
}
30+
internal record CaptureScreenshotCommandParameters(BrowsingContext Context, Origin? Origin, ImageFormat? Format, ClipRectangle? Clip) : CommandParameters;
3831

3932
public record CaptureScreenshotOptions : CommandOptions
4033
{

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2626
internal class CloseCommand(CloseCommandParameters @params)
2727
: Command<CloseCommandParameters>(@params, "browsingContext.close");
2828

29-
internal record CloseCommandParameters(BrowsingContext Context) : CommandParameters;
29+
internal record CloseCommandParameters(BrowsingContext Context, bool? PromptUnload) : CommandParameters;
3030

31-
public record CloseOptions : CommandOptions;
31+
public record CloseOptions : CommandOptions
32+
{
33+
public bool? PromptUnload { get; set; }
34+
}

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2626
internal class CreateCommand(CreateCommandParameters @params)
2727
: Command<CreateCommandParameters>(@params, "browsingContext.create");
2828

29-
internal record CreateCommandParameters(ContextType Type) : CommandParameters
30-
{
31-
public BrowsingContext? ReferenceContext { get; set; }
32-
33-
public bool? Background { get; set; }
34-
35-
public Browser.UserContext? UserContext { get; set; }
36-
}
29+
internal record CreateCommandParameters(ContextType Type, BrowsingContext? ReferenceContext, bool? Background, Browser.UserContext? UserContext) : CommandParameters;
3730

3831
public record CreateOptions : CommandOptions
3932
{

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2727
internal class GetTreeCommand(GetTreeCommandParameters @params)
2828
: Command<GetTreeCommandParameters>(@params, "browsingContext.getTree");
2929

30-
internal record GetTreeCommandParameters : CommandParameters
31-
{
32-
public long? MaxDepth { get; set; }
33-
34-
public BrowsingContext? Root { get; set; }
35-
}
30+
internal record GetTreeCommandParameters(long? MaxDepth, BrowsingContext? Root) : CommandParameters;
3631

3732
public record GetTreeOptions : CommandOptions
3833
{

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2626
class HandleUserPromptCommand(HandleUserPromptCommandParameters @params)
2727
: Command<HandleUserPromptCommandParameters>(@params, "browsingContext.handleUserPrompt");
2828

29-
internal record HandleUserPromptCommandParameters(BrowsingContext Context) : CommandParameters
30-
{
31-
public bool? Accept { get; set; }
32-
33-
public string? UserText { get; set; }
34-
}
29+
internal record HandleUserPromptCommandParameters(BrowsingContext Context, bool? Accept, string? UserText) : CommandParameters;
3530

3631
public record HandleUserPromptOptions : CommandOptions
3732
{

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2828
internal class LocateNodesCommand(LocateNodesCommandParameters @params)
2929
: Command<LocateNodesCommandParameters>(@params, "browsingContext.locateNodes");
3030

31-
internal record LocateNodesCommandParameters(BrowsingContext Context, Locator Locator) : CommandParameters
32-
{
33-
public long? MaxNodeCount { get; set; }
34-
35-
public Script.SerializationOptions? SerializationOptions { get; set; }
36-
37-
public IEnumerable<Script.ISharedReference>? StartNodes { get; set; }
38-
}
31+
internal record LocateNodesCommandParameters(BrowsingContext Context, Locator Locator, long? MaxNodeCount, Script.SerializationOptions? SerializationOptions, IEnumerable<Script.ISharedReference>? StartNodes) : CommandParameters;
3932

4033
public record LocateNodesOptions : CommandOptions
4134
{

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2626
internal class NavigateCommand(NavigateCommandParameters @params)
2727
: Command<NavigateCommandParameters>(@params, "browsingContext.navigate");
2828

29-
internal record NavigateCommandParameters(BrowsingContext Context, string Url) : CommandParameters
30-
{
31-
public ReadinessState? Wait { get; set; }
32-
}
29+
internal record NavigateCommandParameters(BrowsingContext Context, string Url, ReadinessState? Wait) : CommandParameters;
3330

3431
public record NavigateOptions : CommandOptions
3532
{

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

+1-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2828
internal class PrintCommand(PrintCommandParameters @params)
2929
: Command<PrintCommandParameters>(@params, "browsingContext.print");
3030

31-
internal record PrintCommandParameters(BrowsingContext Context) : CommandParameters
32-
{
33-
public bool? Background { get; set; }
34-
35-
public PrintMargin? Margin { get; set; }
36-
37-
public PrintOrientation? Orientation { get; set; }
38-
39-
public PrintPage? Page { get; set; }
40-
41-
public IEnumerable<PrintPageRange>? PageRanges { get; set; }
42-
43-
public double? Scale { get; set; }
44-
45-
public bool? ShrinkToFit { get; set; }
46-
}
31+
internal record PrintCommandParameters(BrowsingContext Context, bool? Background, PrintMargin? Margin, PrintOrientation? Orientation, PrintPage? Page, IEnumerable<PrintPageRange>? PageRanges, double? Scale, bool? ShrinkToFit) : CommandParameters;
4732

4833
public record PrintOptions : CommandOptions
4934
{

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2626
internal class ReloadCommand(ReloadCommandParameters @params)
2727
: Command<ReloadCommandParameters>(@params, "browsingContext.reload");
2828

29-
internal record ReloadCommandParameters(BrowsingContext Context) : CommandParameters
30-
{
31-
public bool? IgnoreCache { get; set; }
32-
33-
public ReadinessState? Wait { get; set; }
34-
}
29+
internal record ReloadCommandParameters(BrowsingContext Context, bool? IgnoreCache, ReadinessState? Wait) : CommandParameters;
3530

3631
public record ReloadOptions : CommandOptions
3732
{

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2626
internal class SetViewportCommand(SetViewportCommandParameters @params)
2727
: Command<SetViewportCommandParameters>(@params, "browsingContext.setViewport");
2828

29-
internal record SetViewportCommandParameters(BrowsingContext Context) : CommandParameters
30-
{
31-
public Viewport? Viewport { get; set; }
32-
33-
public double? DevicePixelRatio { get; set; }
34-
}
29+
internal record SetViewportCommandParameters(BrowsingContext Context, Viewport? Viewport, double? DevicePixelRatio) : CommandParameters;
3530

3631
public record SetViewportOptions : CommandOptions
3732
{

dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Network;
2727
internal class AddInterceptCommand(AddInterceptCommandParameters @params)
2828
: Command<AddInterceptCommandParameters>(@params, "network.addIntercept");
2929

30-
internal record AddInterceptCommandParameters(IEnumerable<InterceptPhase> Phases) : CommandParameters
31-
{
32-
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
33-
34-
public IEnumerable<UrlPattern>? UrlPatterns { get; set; }
35-
}
30+
internal record AddInterceptCommandParameters(IEnumerable<InterceptPhase> Phases, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<UrlPattern>? UrlPatterns) : CommandParameters;
3631

3732
public record AddInterceptOptions : CommandOptions
3833
{

dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Network;
2727
internal class ContinueRequestCommand(ContinueRequestCommandParameters @params)
2828
: Command<ContinueRequestCommandParameters>(@params, "network.continueRequest");
2929

30-
internal record ContinueRequestCommandParameters(Request Request) : CommandParameters
31-
{
32-
public BytesValue? Body { get; set; }
33-
34-
public IEnumerable<CookieHeader>? Cookies { get; set; }
35-
36-
public IEnumerable<Header>? Headers { get; set; }
37-
38-
public string? Method { get; set; }
39-
40-
public string? Url { get; set; }
41-
}
30+
internal record ContinueRequestCommandParameters(Request Request, BytesValue? Body, IEnumerable<CookieHeader>? Cookies, IEnumerable<Header>? Headers, string? Method, string? Url) : CommandParameters;
4231

4332
public record ContinueRequestOptions : CommandOptions
4433
{

dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs

+1-12
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Network;
2727
internal class ContinueResponseCommand(ContinueResponseCommandParameters @params)
2828
: Command<ContinueResponseCommandParameters>(@params, "network.continueResponse");
2929

30-
internal record ContinueResponseCommandParameters(Request Request) : CommandParameters
31-
{
32-
public IEnumerable<SetCookieHeader>? Cookies { get; set; }
33-
34-
public IEnumerable<AuthCredentials>? Credentials { get; set; }
35-
36-
public IEnumerable<Header>? Headers { get; set; }
37-
38-
public string? ReasonPhrase { get; set; }
39-
40-
public long? StatusCode { get; set; }
41-
}
30+
internal record ContinueResponseCommandParameters(Request Request, IEnumerable<SetCookieHeader>? Cookies, IEnumerable<AuthCredentials>? Credentials, IEnumerable<Header>? Headers, string? ReasonPhrase, long? StatusCode) : CommandParameters;
4231

4332
public record ContinueResponseOptions : CommandOptions
4433
{

0 commit comments

Comments
 (0)