Skip to content

Commit 8c4302c

Browse files
authored
[dotnet] [bidi] Specific result type for any command (#16405)
1 parent 6dcb5a6 commit 8c4302c

File tree

55 files changed

+258
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+258
-154
lines changed

dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,28 @@ namespace OpenQA.Selenium.BiDi.Browser;
2424

2525
public sealed class BrowserModule : Module
2626
{
27-
public async Task<EmptyResult> CloseAsync(CloseOptions? options = null)
27+
public async Task<CloseResult> CloseAsync(CloseOptions? options = null)
2828
{
29-
return await Broker.ExecuteCommandAsync(new CloseCommand(), options, JsonContext.Browser_CloseCommand, JsonContext.EmptyResult).ConfigureAwait(false);
29+
return await Broker.ExecuteCommandAsync(new CloseCommand(), options, JsonContext.Browser_CloseCommand, JsonContext.Browser_CloseResult).ConfigureAwait(false);
3030
}
3131

32-
public async Task<UserContextInfo> CreateUserContextAsync(CreateUserContextOptions? options = null)
32+
public async Task<CreateUserContextResult> CreateUserContextAsync(CreateUserContextOptions? options = null)
3333
{
3434
var @params = new CreateUserContextParameters(options?.AcceptInsecureCerts, options?.Proxy, options?.UnhandledPromptBehavior);
3535

36-
return await Broker.ExecuteCommandAsync(new CreateUserContextCommand(@params), options, JsonContext.CreateUserContextCommand, JsonContext.UserContextInfo).ConfigureAwait(false);
36+
return await Broker.ExecuteCommandAsync(new CreateUserContextCommand(@params), options, JsonContext.CreateUserContextCommand, JsonContext.CreateUserContextResult).ConfigureAwait(false);
3737
}
3838

3939
public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null)
4040
{
4141
return await Broker.ExecuteCommandAsync(new GetUserContextsCommand(), options, JsonContext.GetUserContextsCommand, JsonContext.GetUserContextsResult).ConfigureAwait(false);
4242
}
4343

44-
public async Task<EmptyResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null)
44+
public async Task<RemoveUserContextResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null)
4545
{
4646
var @params = new RemoveUserContextParameters(userContext);
4747

48-
return await Broker.ExecuteCommandAsync(new RemoveUserContextCommand(@params), options, JsonContext.RemoveUserContextCommand, JsonContext.EmptyResult).ConfigureAwait(false);
48+
return await Broker.ExecuteCommandAsync(new RemoveUserContextCommand(@params), options, JsonContext.RemoveUserContextCommand, JsonContext.RemoveUserContextResult).ConfigureAwait(false);
4949
}
5050

5151
public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null)
@@ -54,24 +54,24 @@ public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindows
5454
).ConfigureAwait(false);
5555
}
5656

57-
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
57+
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
5858
{
5959
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);
6060

61-
return await Broker.ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.EmptyResult).ConfigureAwait(false);
61+
return await Broker.ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.SetDownloadBehaviorResult).ConfigureAwait(false);
6262
}
6363

64-
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
64+
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
6565
{
6666
var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts);
6767

68-
return await Broker.ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.EmptyResult).ConfigureAwait(false);
68+
return await Broker.ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.SetDownloadBehaviorResult).ConfigureAwait(false);
6969
}
7070

71-
public async Task<EmptyResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
71+
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
7272
{
7373
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts);
7474

75-
return await Broker.ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.EmptyResult).ConfigureAwait(false);
75+
return await Broker.ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.SetDownloadBehaviorResult).ConfigureAwait(false);
7676
}
7777
}

dotnet/src/webdriver/BiDi/Browser/CloseCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
namespace OpenQA.Selenium.BiDi.Browser;
2323

2424
internal sealed class CloseCommand()
25-
: Command<Parameters, EmptyResult>(Parameters.Empty, "browser.close");
25+
: Command<Parameters, CloseResult>(Parameters.Empty, "browser.close");
2626

2727
public sealed class CloseOptions : CommandOptions;
28+
29+
public sealed record CloseResult : EmptyResult;

dotnet/src/webdriver/BiDi/Browser/CreateUserContextCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace OpenQA.Selenium.BiDi.Browser;
2323

2424
internal sealed class CreateUserContextCommand(CreateUserContextParameters @params)
25-
: Command<CreateUserContextParameters, UserContextInfo>(@params, "browser.createUserContext");
25+
: Command<CreateUserContextParameters, CreateUserContextResult>(@params, "browser.createUserContext");
2626

2727
internal sealed record CreateUserContextParameters(bool? AcceptInsecureCerts, Session.ProxyConfiguration? Proxy, Session.UserPromptHandler? UnhandledPromptBehavior) : Parameters;
2828

@@ -34,3 +34,5 @@ public sealed class CreateUserContextOptions : CommandOptions
3434

3535
public Session.UserPromptHandler? UnhandledPromptBehavior { get; set; }
3636
}
37+
38+
public sealed record CreateUserContextResult(UserContext UserContext) : UserContextInfo(UserContext);

dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ internal GetClientWindowsResult(IReadOnlyList<ClientWindowInfo> clientWindows)
4444

4545
public int Count => ClientWindows.Count;
4646

47-
48-
4947
public IEnumerator<ClientWindowInfo> GetEnumerator() => ClientWindows.GetEnumerator();
5048

5149
IEnumerator IEnumerable.GetEnumerator() => (ClientWindows as IEnumerable).GetEnumerator();

dotnet/src/webdriver/BiDi/Browser/RemoveUserContextCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
namespace OpenQA.Selenium.BiDi.Browser;
2323

2424
internal sealed class RemoveUserContextCommand(RemoveUserContextParameters @params)
25-
: Command<RemoveUserContextParameters, EmptyResult>(@params, "browser.removeUserContext");
25+
: Command<RemoveUserContextParameters, RemoveUserContextResult>(@params, "browser.removeUserContext");
2626

2727
internal sealed record RemoveUserContextParameters(UserContext UserContext) : Parameters;
2828

2929
public sealed class RemoveUserContextOptions : CommandOptions;
30+
31+
public sealed record RemoveUserContextResult : EmptyResult;

dotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
namespace OpenQA.Selenium.BiDi.Browser;
2525

2626
internal sealed class SetDownloadBehaviorCommand(SetDownloadBehaviorParameters @params)
27-
: Command<SetDownloadBehaviorParameters, EmptyResult>(@params, "browser.setDownloadBehavior");
27+
: Command<SetDownloadBehaviorParameters, SetDownloadBehaviorResult>(@params, "browser.setDownloadBehavior");
2828

2929
internal sealed record SetDownloadBehaviorParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] DownloadBehavior? DownloadBehavior, IEnumerable<UserContext>? UserContexts) : Parameters;
3030

@@ -41,3 +41,5 @@ public sealed class SetDownloadBehaviorOptions : CommandOptions
4141
{
4242
public IEnumerable<UserContext>? UserContexts { get; set; }
4343
}
44+
45+
public sealed record SetDownloadBehaviorResult : EmptyResult;

dotnet/src/webdriver/BiDi/Browser/UserContextInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121

2222
namespace OpenQA.Selenium.BiDi.Browser;
2323

24-
public sealed record UserContextInfo(UserContext UserContext) : EmptyResult;
24+
public record UserContextInfo(UserContext UserContext) : EmptyResult;

dotnet/src/webdriver/BiDi/BrowsingContext/ActivateCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2323

2424
internal sealed class ActivateCommand(ActivateParameters @params)
25-
: Command<ActivateParameters, EmptyResult>(@params, "browsingContext.activate");
25+
: Command<ActivateParameters, ActivateResult>(@params, "browsingContext.activate");
2626

2727
internal sealed record ActivateParameters(BrowsingContext Context) : Parameters;
2828

2929
public sealed class ActivateOptions : CommandOptions;
30+
31+
public sealed record ActivateResult : EmptyResult;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public Task<NavigateResult> NavigateAsync(string url, NavigateOptions? options =
6262
return BiDi.BrowsingContext.NavigateAsync(this, url, options);
6363
}
6464

65-
public Task<NavigateResult> ReloadAsync(ReloadOptions? options = null)
65+
public Task<ReloadResult> ReloadAsync(ReloadOptions? options = null)
6666
{
6767
return BiDi.BrowsingContext.ReloadAsync(this, options);
6868
}
6969

70-
public Task<EmptyResult> ActivateAsync(ActivateOptions? options = null)
70+
public Task<ActivateResult> ActivateAsync(ActivateOptions? options = null)
7171
{
7272
return BiDi.BrowsingContext.ActivateAsync(this, options);
7373
}
@@ -82,7 +82,7 @@ public Task<CaptureScreenshotResult> CaptureScreenshotAsync(CaptureScreenshotOpt
8282
return BiDi.BrowsingContext.CaptureScreenshotAsync(this, options);
8383
}
8484

85-
public Task<EmptyResult> CloseAsync(CloseOptions? options = null)
85+
public Task<CloseResult> CloseAsync(CloseOptions? options = null)
8686
{
8787
return BiDi.BrowsingContext.CloseAsync(this, options);
8888
}
@@ -92,7 +92,7 @@ public Task<TraverseHistoryResult> TraverseHistoryAsync(int delta, TraverseHisto
9292
return BiDi.BrowsingContext.TraverseHistoryAsync(this, delta, options);
9393
}
9494

95-
public Task<EmptyResult> SetViewportAsync(SetViewportOptions? options = null)
95+
public Task<SetViewportResult> SetViewportAsync(SetViewportOptions? options = null)
9696
{
9797
return BiDi.BrowsingContext.SetViewportAsync(this, options);
9898
}
@@ -102,7 +102,7 @@ public Task<PrintResult> PrintAsync(PrintOptions? options = null)
102102
return BiDi.BrowsingContext.PrintAsync(this, options);
103103
}
104104

105-
public Task<EmptyResult> HandleUserPromptAsync(HandleUserPromptOptions? options = null)
105+
public Task<HandleUserPromptResult> HandleUserPromptAsync(HandleUserPromptOptions? options = null)
106106
{
107107
return BiDi.BrowsingContext.HandleUserPromptAsync(this, options);
108108
}

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,22 @@
2020
using System.Threading.Tasks;
2121
using OpenQA.Selenium.BiDi.Input;
2222
using System.Collections.Generic;
23-
using OpenQA.Selenium.BiDi.Communication;
2423

2524
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2625

2726
public sealed class BrowsingContextInputModule(BrowsingContext context, InputModule inputModule)
2827
{
29-
public Task<EmptyResult> PerformActionsAsync(IEnumerable<SourceActions> actions, PerformActionsOptions? options = null)
28+
public Task<PerformActionsResult> PerformActionsAsync(IEnumerable<SourceActions> actions, PerformActionsOptions? options = null)
3029
{
3130
return inputModule.PerformActionsAsync(context, actions, options);
3231
}
3332

34-
public Task<EmptyResult> ReleaseActionsAsync(ReleaseActionsOptions? options = null)
33+
public Task<ReleaseActionsResult> ReleaseActionsAsync(ReleaseActionsOptions? options = null)
3534
{
3635
return inputModule.ReleaseActionsAsync(context, options);
3736
}
3837

39-
public Task<EmptyResult> SetFilesAsync(Script.ISharedReference element, IEnumerable<string> files, SetFilesOptions? options = null)
38+
public Task<SetFilesResult> SetFilesAsync(Script.ISharedReference element, IEnumerable<string> files, SetFilesOptions? options = null)
4039
{
4140
return inputModule.SetFilesAsync(context, element, files, options);
4241
}

0 commit comments

Comments
 (0)