Skip to content

[dotnet] [bidi] Align ContinueWithAuth command#17337

Merged
nvborisenko merged 5 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-continuewithauth
Apr 11, 2026
Merged

[dotnet] [bidi] Align ContinueWithAuth command#17337
nvborisenko merged 5 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-continuewithauth

Conversation

@nvborisenko
Copy link
Copy Markdown
Member

One more polymorphic command.

💥 What does this PR do?

This pull request refactors and simplifies the APIs for controlling network authentication in the WebDriver BiDi .NET bindings. The changes consolidate multiple method overloads into single, more flexible methods, and update the related types to be public and more extensible. Test code is updated accordingly.

🔄 Types of changes

  • Cleanup (formatting, renaming)

Copilot AI review requested due to automatic review settings April 11, 2026 07:50
@selenium-ci selenium-ci added the C-dotnet .NET Bindings label Apr 11, 2026
@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Align SetDownloadBehavior and ContinueWithAuth commands with polymorphic pattern

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Consolidate multiple method overloads into single polymorphic methods
• Make DownloadBehavior and ContinueWithAuth types public for extensibility
• Simplify API by accepting polymorphic action parameters instead of separate overloads
• Update test code to use new unified method signatures

Grey Divider

File Changes

1. dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs ✨ Enhancement +2/-16

Consolidate SetDownloadBehavior methods into single polymorphic method

• Consolidate three SetDownloadBehavior method overloads into single method accepting
 DownloadBehavior parameter
• Remove separate methods for allowed, denied, and default behaviors
• Simplify parameter construction to use polymorphic DownloadBehavior type

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


2. dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs ✨ Enhancement +1/-3

Update IBrowserModule interface for polymorphic SetDownloadBehavior

• Replace three SetDownloadBehavior method signatures with single unified signature
• Update method to accept DownloadBehavior parameter instead of specific behavior types

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


3. dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs ✨ Enhancement +6/-3

Make DownloadBehavior types public with default property

• Change DownloadBehavior from internal abstract record to public abstract record
• Add static Default property to DownloadBehavior for null behavior representation
• Make DownloadBehaviorAllowed and DownloadBehaviorDenied public sealed records

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


View more (5)
4. dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs ✨ Enhancement +13/-15

Refactor ContinueWithAuth to use public polymorphic action types

• Introduce public ContinueWithAuth abstract record as base type for actions
• Create public ContinueWithAuthCredentials, ContinueWithAuthDefault, and ContinueWithAuthCancel
 sealed records
• Rename internal parameter types to ContinueWithAuthCredentialsParameters,
 ContinueWithAuthDefaultParameters, and ContinueWithAuthCancelParameters
• Remove old ContinueWithAuthOptions hierarchy and consolidate to single ContinueWithAuthOptions

dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs


5. dotnet/src/webdriver/BiDi/Network/INetworkModule.cs ✨ Enhancement +1/-3

Update INetworkModule interface for polymorphic ContinueWithAuth

• Replace three ContinueWithAuth method overloads with single unified signature
• Update method to accept ContinueWithAuth action parameter instead of specific credential types
• Simplify options parameter to use single ContinueWithAuthOptions type

dotnet/src/webdriver/BiDi/Network/INetworkModule.cs


6. dotnet/src/webdriver/BiDi/Network/NetworkModule.cs ✨ Enhancement +10/-12

Consolidate ContinueWithAuth methods with polymorphic dispatch

• Consolidate three ContinueWithAuth method implementations into single method
• Add switch expression to map ContinueWithAuth action types to internal parameter types
• Include validation for unknown action types with ArgumentException

dotnet/src/webdriver/BiDi/Network/NetworkModule.cs


7. dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs 🧪 Tests +11/-13

Update browser tests for new SetDownloadBehavior API

• Add using statement for OpenQA.Selenium.BiDi.Browser namespace
• Update test methods to use new SetDownloadBehaviorAsync signature with DownloadBehavior parameter
• Remove IgnoreBrowser attributes from SetDownloadBehavior tests
• Add test demonstrating both null and DownloadBehavior.Default usage patterns

dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs


8. dotnet/test/webdriver/BiDi/Network/NetworkTests.cs 🧪 Tests +3/-3

Update network tests for new ContinueWithAuth API

• Update ContinueWithAuth test calls to use new polymorphic action types
• Replace AuthCredentials parameter with ContinueWithAuthCredentials wrapper
• Replace ContinueWithAuthDefaultCredentialsOptions with ContinueWithAuthDefault instance
• Replace ContinueWithAuthCancelCredentialsOptions with ContinueWithAuthCancel instance

dotnet/test/webdriver/BiDi/Network/NetworkTests.cs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Apr 11, 2026

Code Review by Qodo

🐞 Bugs (0)   📘 Rule violations (3)   📎 Requirement gaps (0)   🎨 UX Issues (0)
📘\ ≡ Correctness (1) ⚙ Maintainability (2)

Grey Divider


Action required

1. Removed SetDownloadBehavior*Async overloads 📘
Description
The public IBrowserModule API removes the
SetDownloadBehaviorAllowedAsync/SetDownloadBehaviorDeniedAsync overloads and replaces them with
SetDownloadBehaviorAsync, requiring user code changes. This breaks upgrade-by-version-bump
expectations for the .NET BiDi API surface.
Code

dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs[29]

+    Task<SetDownloadBehaviorResult> SetDownloadBehaviorAsync(DownloadBehavior? downloadBehavior, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default);
Evidence
PR Compliance ID 1 requires backward-compatible public API changes, but the interface now exposes
only SetDownloadBehaviorAsync(...) rather than the previous overload set; no deprecated overloads
remain to preserve compatibility.

AGENTS.md
dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs[22-30]
AGENTS.md

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The public `IBrowserModule` methods `SetDownloadBehaviorAllowedAsync(...)` and `SetDownloadBehaviorDeniedAsync(...)` were removed and replaced with `SetDownloadBehaviorAsync(...)`, which is a breaking change for existing consumers.

## Issue Context
Compliance requires maintaining backward compatibility for public interfaces, and deprecating public APIs before removal.

## Fix Focus Areas
- dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs[22-30]
- dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs[69-79]
- dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs[24-41]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Changed ContinueWithAuthAsync signature 📘
Description
The public INetworkModule.ContinueWithAuthAsync overloads were removed and replaced with a
different signature taking ContinueWithAuth action, requiring user code changes. This is a
breaking public API change without compatibility shims.
Code

dotnet/src/webdriver/BiDi/Network/INetworkModule.cs[28]

+    Task<ContinueWithAuthResult> ContinueWithAuthAsync(Request request, ContinueWithAuth action, ContinueWithAuthOptions? options = null, CancellationToken cancellationToken = default);
Evidence
PR Compliance ID 1 requires backward-compatible public API evolution, but the interface now exposes
only ContinueWithAuthAsync(Request, ContinueWithAuth, ...) rather than the prior overload set;
there are no deprecated overloads left for a transition period (PR Compliance ID 7).

AGENTS.md
dotnet/src/webdriver/BiDi/Network/INetworkModule.cs[22-31]
AGENTS.md

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`INetworkModule` removed the existing `ContinueWithAuthAsync(...)` overloads and replaced them with a new signature. This breaks consumers who depended on the previous overloads.

## Issue Context
To preserve public API compatibility, keep old overloads as `[Obsolete("...")]` wrappers that forward to the new `ContinueWithAuth`-based method.

## Fix Focus Areas
- dotnet/src/webdriver/BiDi/Network/INetworkModule.cs[22-46]
- dotnet/src/webdriver/BiDi/Network/NetworkModule.cs[168-179]
- dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs[24-46]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. No null-check for action 📘
Description
ContinueWithAuthAsync does not validate the externally provided action argument, and the default
case uses action.GetType(), which will throw NullReferenceException if action is null. This
fails to validate an input early with a clear, actionable error.
Code

dotnet/src/webdriver/BiDi/Network/NetworkModule.cs[R170-176]

+        ContinueWithAuthParameters @params = action switch
+        {
+            ContinueWithAuthCredentials c => new ContinueWithAuthCredentialsParameters(request, c.Credentials),
+            ContinueWithAuthDefault => new ContinueWithAuthDefaultParameters(request),
+            ContinueWithAuthCancel => new ContinueWithAuthCancelParameters(request),
+            _ => throw new ArgumentException($"Unknown action type: {action.GetType()}", nameof(action))
+        };
Evidence
PR Compliance ID 11 requires validating externally provided inputs early with clear exceptions; the
added switch expression throws using action.GetType() without any null guard, producing an unclear
NRE path instead of an explicit argument validation failure.

dotnet/src/webdriver/BiDi/Network/NetworkModule.cs[168-178]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`ContinueWithAuthAsync(Request request, ContinueWithAuth action, ...)` does not validate `action` for null, and will throw `NullReferenceException` when building the exception message (`action.GetType()`).

## Issue Context
Even though `ContinueWithAuth` is non-nullable, null can still be passed at runtime (e.g., from older code, reflection, or null-forgiving usage). Fail fast with `ArgumentNullException` (or a clear `ArgumentException`) before the switch.

## Fix Focus Areas
- dotnet/src/webdriver/BiDi/Network/NetworkModule.cs[168-178]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the WebDriver BiDi .NET APIs for network authentication continuation and browser download behavior by consolidating multiple overloads into single polymorphic methods, and updating call sites in the BiDi tests.

Changes:

  • Replaced multiple ContinueWithAuthAsync overloads with a single method taking a ContinueWithAuth action object.
  • Replaced multiple SetDownloadBehavior*Async overloads with a single SetDownloadBehaviorAsync(DownloadBehavior?) method and made DownloadBehavior public.
  • Updated BiDi test usage to the new consolidated APIs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
dotnet/test/webdriver/BiDi/Network/NetworkTests.cs Updates auth continuation calls to new ContinueWithAuth action types.
dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs Updates download behavior tests to new consolidated API and public behavior types.
dotnet/src/webdriver/BiDi/Network/NetworkModule.cs Implements consolidated ContinueWithAuthAsync with action-to-parameters mapping.
dotnet/src/webdriver/BiDi/Network/INetworkModule.cs Updates public interface to single ContinueWithAuthAsync signature.
dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs Introduces public ContinueWithAuth action records; reshapes options/parameters types.
dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs Makes DownloadBehavior public and adds Default convenience value.
dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs Updates public interface to single SetDownloadBehaviorAsync signature.
dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs Implements consolidated SetDownloadBehaviorAsync.

@nvborisenko nvborisenko merged commit 82fd32a into SeleniumHQ:trunk Apr 11, 2026
19 checks passed
@nvborisenko nvborisenko deleted the bidi-continuewithauth branch April 11, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-dotnet .NET Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants