From 83305221c95107c95de10ffe288e8f3713e8e713 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 11 Apr 2026 10:15:52 +0300 Subject: [PATCH 1/2] [dotnet] [bidi] Align SetDownloadBehavior command --- .../webdriver/BiDi/Browser/BrowserModule.cs | 18 ++------------ .../webdriver/BiDi/Browser/IBrowserModule.cs | 4 +--- .../BiDi/Browser/SetDownloadBehavior.cs | 9 ++++--- .../webdriver/BiDi/Browser/BrowserTests.cs | 24 +++++++++---------- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs index d0e847adaf826..938790269bfe4 100644 --- a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs @@ -71,23 +71,9 @@ public async Task GetClientWindowsAsync(GetClientWindows return await ExecuteAsync(GetClientWindowsCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false); } - public async Task SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) + public async Task SetDownloadBehaviorAsync(DownloadBehavior? downloadBehavior, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) { - var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts); - - return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); - } - - public async Task SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) - { - var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts); - - return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); - } - - public async Task SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) - { - var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts); + var @params = new SetDownloadBehaviorParameters(downloadBehavior, options?.UserContexts); return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); } diff --git a/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs b/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs index b79395b311e81..b77ebccd877fd 100644 --- a/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs @@ -26,7 +26,5 @@ public interface IBrowserModule Task GetClientWindowsAsync(GetClientWindowsOptions? options = null, CancellationToken cancellationToken = default); Task GetUserContextsAsync(GetUserContextsOptions? options = null, CancellationToken cancellationToken = default); Task RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null, CancellationToken cancellationToken = default); - Task SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); - Task SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); - Task SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); + Task SetDownloadBehaviorAsync(DownloadBehavior? downloadBehavior, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); } diff --git a/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs b/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs index aef71f681dc28..cd3f6fab9c34f 100644 --- a/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs +++ b/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs @@ -26,11 +26,14 @@ internal sealed record SetDownloadBehaviorParameters([property: JsonIgnore(Condi [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(DownloadBehaviorAllowed), "allowed")] [JsonDerivedType(typeof(DownloadBehaviorDenied), "denied")] -internal abstract record DownloadBehavior; +public abstract record DownloadBehavior +{ + public static DownloadBehavior? Default => null; +} -internal sealed record DownloadBehaviorAllowed(string DestinationFolder) : DownloadBehavior; +public sealed record DownloadBehaviorAllowed(string DestinationFolder) : DownloadBehavior; -internal sealed record DownloadBehaviorDenied : DownloadBehavior; +public sealed record DownloadBehaviorDenied : DownloadBehavior; public sealed record SetDownloadBehaviorOptions : CommandOptions { diff --git a/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs b/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs index 7a1047dafe948..2ec84bc4cb845 100644 --- a/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs +++ b/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs @@ -17,6 +17,8 @@ // under the License. // +using OpenQA.Selenium.BiDi.Browser; + namespace OpenQA.Selenium.Tests.BiDi.Browser; internal class BrowserTests : BiDiTestFixture @@ -68,34 +70,30 @@ public async Task CanGetClientWindows() } [Test] - [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")] public async Task CanSetDownloadBehaviorAllowed() { - var result = await bidi.Browser.SetDownloadBehaviorAllowedAsync("/my/path"); + var result = await bidi.Browser.SetDownloadBehaviorAsync(new DownloadBehaviorAllowed("/my/path")); Assert.That(result, Is.Not.Null); } [Test] - [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")] - public async Task CanSetDownloadBehaviorAllowedDefault() + public async Task CanSetDownloadBehaviorDefault() { - var result = await bidi.Browser.SetDownloadBehaviorAllowedAsync(); + var result = await bidi.Browser.SetDownloadBehaviorAsync(null); + + // or + var result2 = await bidi.Browser.SetDownloadBehaviorAsync(DownloadBehavior.Default); + Assert.That(result, Is.Not.Null); + Assert.That(result2, Is.Not.Null); } [Test] - [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")] public async Task CanSetDownloadBehaviorDenied() { - var result = await bidi.Browser.SetDownloadBehaviorDeniedAsync(); + var result = await bidi.Browser.SetDownloadBehaviorAsync(new DownloadBehaviorDenied()); Assert.That(result, Is.Not.Null); } From 88222cf4b33a0daf952851630a9dc4fb9e97102b Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sat, 11 Apr 2026 10:28:44 +0300 Subject: [PATCH 2/2] Format --- dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs b/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs index 2ec84bc4cb845..548c64cd3c6e9 100644 --- a/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs +++ b/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs @@ -85,7 +85,7 @@ public async Task CanSetDownloadBehaviorDefault() // or var result2 = await bidi.Browser.SetDownloadBehaviorAsync(DownloadBehavior.Default); - + Assert.That(result, Is.Not.Null); Assert.That(result2, Is.Not.Null); }