Skip to content

[java] Fix BiDi not initializing for RemoteWebDriver built via builder - #17778

Closed
baflQA wants to merge 3 commits into
SeleniumHQ:trunkfrom
baflQA:patch-1
Closed

[java] Fix BiDi not initializing for RemoteWebDriver built via builder#17778
baflQA wants to merge 3 commits into
SeleniumHQ:trunkfrom
baflQA:patch-1

Conversation

@baflQA

@baflQA baflQA commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Related Issues

N/A

What does this PR do?

Fixes RemoteWebDriver to check this.capabilities (response capabilities from server) instead of the local capabilities parameter when detecting BiDi WebSocket URL support.

Implementation Notes

capabilities on line 293 is set to the response from the session — the server may return webSocketUrl in the response capabilities even if not in the requested ones. Using the local parameter instead of this.capabilities missed this case.

No alternatives considered — single-character fix to use correct variable.

AI assistance

  • I used AI tools in creating this PR

Additional Considerations

None.

Types of changes

  • Bug fix (backwards compatible)

@selenium-ci selenium-ci added the C-java Java Bindings label Jul 14, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

RemoteWebDriver: decide BiDi setup based on returned capabilities

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Use negotiated (response) capabilities when deciding whether to initialize BiDi.
• Align session-start behavior with what the remote end actually returned.
Diagram

graph TD
  A["RemoteWebDriver.startSession"] --> B["NEW_SESSION command"] --> C{{"Remote end"}} --> D["Response capabilities"] --> E["BiDi init gate"] --> F["createBiDi()"]
  F --> G["WebSocket BiDi"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Gate BiDi init on requested capability
  • ➕ Preserves intent: only attempt BiDi when client explicitly requested it ('webSocketUrl: true').
  • ➕ Works even when the response capability is a WebSocket URL string (per spec).
  • ➖ Will still attempt createBiDi() even if remote end ignored the request (though createBiDi() safely returns empty).
2. Gate BiDi init on presence/type of returned webSocketUrl
  • ➕ Matches actual availability: only attempt BiDi when remote end returned a usable URL (e.g., String).
  • ➕ Avoids unnecessary connection attempts when unsupported.
  • ➖ If the response omits webSocketUrl despite support, BiDi will not initialize even if requested.
3. Combine both gates (requested AND returned URL present)
  • ➕ Most explicit: client opt-in plus confirmed remote support before connecting.
  • ➕ Avoids both unnecessary attempts and unexpected enablement.
  • ➖ Slightly more logic and may block BiDi in edge cases where only one signal is present.

Recommendation: Consider gating BiDi initialization either on the originally requested capability, or (preferably) on the returned capability being a non-empty String URL (or combining both). As written, using Boolean.TRUE.equals(...) against the returned capability may not trigger if the remote end returns a WebSocket URL string, which could prevent BiDi from being initialized.

Files changed (1) +1 / -1

Bug fix (1) +1 / -1
RemoteWebDriver.javaUse negotiated capabilities for BiDi initialization decision +1/-1

Use negotiated capabilities for BiDi initialization decision

• Updates the BiDi initialization conditional to consult the capabilities returned by the NEW_SESSION response (stored on the driver) rather than the originally provided capabilities. This changes when createBiDi() is attempted during session startup.

java/src/org/openqa/selenium/remote/RemoteWebDriver.java

@qodo-code-review

qodo-code-review Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Action required

1. createBiDi() called unconditionally ✗ Dismissed 📘 Rule violation ≡ Correctness
Description
RemoteWebDriver.startSession now unconditionally calls createBiDi(), which can eagerly establish
a BiDi WebSocket connection whenever the server returns a string webSocketUrl, changing
user-visible behavior even if the client never explicitly enabled BiDi. Compliance requires either
cross-binding comparison evidence (since other bindings appear to initialize BiDi lazily/on first
use) or clear documentation of any intentional divergence, as this can add session-start latency and
trigger unexpected outbound WebSocket attempts/warnings.
Code

java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295]

+      this.biDi = createBiDi();
Evidence
The cited change in RemoteWebDriver.startSession assigns this.biDi = createBiDi() during session
creation, making BiDi initialization unconditional. createBiDi() will then immediately create a
WebSocket-backed connection when the returned session capabilities contain a string webSocketUrl
(via new Connection(...), whose constructor calls client.openSocket(...)), meaning a connection
attempt can occur even without an explicit client opt-in; elsewhere BiDi is framed as opt-in via
enableBiDi() setting webSocketUrl: true, and tests describe the expected flow as requesting
webSocketUrl: true before connecting. Since other bindings in the repo appear to establish BiDi
lazily when BiDi APIs are accessed, this constitutes a potentially divergent, user-visible behavior
change that the compliance checklist requires to be validated via cross-binding comparison or
explicitly documented as intentional.

Rule 389265: Compare cross-language bindings when changing user-visible behavior
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-296]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[435-469]
py/selenium/webdriver/remote/webdriver.py[1198-1222]
javascript/selenium-webdriver/lib/webdriver.js[1304-1314]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[263-306]
java/src/org/openqa/selenium/bidi/Connection.java[80-86]
java/src/org/openqa/selenium/chromium/ChromiumOptions.java[175-178]
java/test/org/openqa/selenium/grid/router/TunnelWebsocketTest.java[457-467]

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

## Issue description
Java `RemoteWebDriver.startSession` now eagerly initializes BiDi by unconditionally calling `createBiDi()`, which can immediately open a WebSocket whenever the server returns a string `webSocketUrl` in the *returned* capabilities. This can create unsolicited BiDi connections (even if the client never enabled BiDi), add session-start latency, and produce unexpected outbound WebSocket attempts/warnings; per compliance, you must either align behavior with other bindings (which appear to initialize BiDi lazily/on first use) or provide explicit cross-binding comparison evidence and document any intentional divergence.

## Issue Context
- `startSession` now assigns `this.biDi = createBiDi()` during session creation based solely on the returned `webSocketUrl` capability.
- `createBiDi()` opens a WebSocket immediately when `webSocketUrl` is present (through `new Connection(...)` and `Connection` invoking `client.openSocket(...)`).
- Elsewhere BiDi is treated as explicit opt-in: `enableBiDi()` sets `webSocketUrl: true`, and tests describe the expected flow as “client requests `webSocketUrl: true` … then connects”.
- Other Selenium language bindings in this repo (e.g., Python/JavaScript) appear to initialize BiDi lazily when BiDi APIs are accessed rather than during session creation.
- Compliance requires cross-binding comparison for user-visible behavior changes in a binding, or clear documentation/rationale near the change for any intended divergence (and reflected in tests if applicable).

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[292-296]

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


2. webSocketUrl boolean check on response ✓ Resolved 📘 Rule violation ≡ Correctness
Description
RemoteWebDriver.startSession now gates BiDi startup with
Boolean.TRUE.equals(this.capabilities.getCapability("webSocketUrl")), but the returned
webSocketUrl capability is typically a WebSocket URL string rather than a boolean. As a result,
Java may fail to initialize BiDi (breaking getHandle()/BiDi usage) and diverge from other Selenium
bindings that treat webSocketUrl as a returned URL value when present.
Code

java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295]

+      if (Boolean.TRUE.equals(this.capabilities.getCapability("webSocketUrl"))) {
Evidence
The cited change compares the *response* capabilities (this.capabilities) value for webSocketUrl
to Boolean.TRUE, yet createBiDi() proceeds only when webSocketUrl is a String URL, and other
parts of the codebase and other language bindings likewise interpret a returned webSocketUrl as a
URL value (while the client request may use webSocketUrl: true to ask for it). Therefore, a
boolean equality check against the returned capability will evaluate false for the standard
BiDi-capable response shape ("ws(s)://..."), preventing BiDi initialization in Java even when
supported.

Rule 389265: Compare cross-language bindings when changing user-visible behavior
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-297]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[437-442]
py/selenium/webdriver/remote/webdriver.py[1208-1213]
javascript/selenium-webdriver/bidi/browser.js[29-35]
dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs[28-35]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[263-297]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[437-471]
java/src/org/openqa/selenium/chromium/ChromiumOptions.java[175-178]
java/src/org/openqa/selenium/bidi/BiDiProvider.java[94-106]
java/src/org/openqa/selenium/grid/node/local/LocalNode.java[1242-1250]

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

## Issue description
`RemoteWebDriver.startSession` decides whether to call `createBiDi()` using `Boolean.TRUE.equals(this.capabilities.getCapability("webSocketUrl"))`, but `this.capabilities` represents the *response* capabilities where `webSocketUrl` is typically a **String WebSocket URL** when BiDi is supported. This prevents BiDi from being initialized for normal BiDi-capable sessions and causes Java behavior to diverge from other Selenium bindings.

## Issue Context
- Client code may *request* BiDi by sending `webSocketUrl: true` in options.
- The remote end typically *responds* with `webSocketUrl: "ws(s)://..."` when BiDi is available.
- Java `createBiDi()` reads `webSocketUrl` and expects it to be a `String` (otherwise it returns empty/no-ops).
- Other bindings (Python/JS/.NET) generally check for the presence of a returned `webSocketUrl` value (not a boolean) to enable BiDi.

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[263-297]
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-297]
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[437-442]

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



Remediation recommended

3. BiDi regression test missing 📘 Rule violation ▣ Testability
Description
This bug-fix change alters BiDi initialization behavior in startSession, but the provided change
set includes no updated/new automated test that would fail if the change were reverted. The
compliance checklist requires regression coverage for bug fixes affecting observable behavior.
Code

java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295]

+      this.biDi = createBiDi();
Evidence
The diff shows a functional behavior change at startSession (BiDi initialization path), but no
test change is present in the provided patch to lock in the expected behavior. The checklist
requires regression tests for bug fixes/new behavior.

Rule 389273: Require tests for all new functionality and bug fixes
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-296]

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

## Issue description
A behavioral bug fix to BiDi initialization lacks an accompanying regression test update in the provided change set.

## Issue Context
The change modifies session startup behavior (`startSession`) to set `biDi` via `createBiDi()`. Per compliance, bug fixes and user-visible behavior changes should have an automated test that would fail under the pre-fix behavior.

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295-295]

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


Grey Divider

Previous review results

Review updated until commit f9e37e5

Results up to commit d031b74


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. webSocketUrl boolean check on response ✓ Resolved 📘 Rule violation ≡ Correctness
Description
RemoteWebDriver.startSession now gates BiDi startup with
Boolean.TRUE.equals(this.capabilities.getCapability("webSocketUrl")), but the returned
webSocketUrl capability is typically a WebSocket URL string rather than a boolean. As a result,
Java may fail to initialize BiDi (breaking getHandle()/BiDi usage) and diverge from other Selenium
bindings that treat webSocketUrl as a returned URL value when present.
Code

java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295]

+      if (Boolean.TRUE.equals(this.capabilities.getCapability("webSocketUrl"))) {
Evidence
The cited change compares the *response* capabilities (this.capabilities) value for webSocketUrl
to Boolean.TRUE, yet createBiDi() proceeds only when webSocketUrl is a String URL, and other
parts of the codebase and other language bindings likewise interpret a returned webSocketUrl as a
URL value (while the client request may use webSocketUrl: true to ask for it). Therefore, a
boolean equality check against the returned capability will evaluate false for the standard
BiDi-capable response shape ("ws(s)://..."), preventing BiDi initialization in Java even when
supported.

Rule 389265: Compare cross-language bindings when changing user-visible behavior
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-297]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[437-442]
py/selenium/webdriver/remote/webdriver.py[1208-1213]
javascript/selenium-webdriver/bidi/browser.js[29-35]
dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs[28-35]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[263-297]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[437-471]
java/src/org/openqa/selenium/chromium/ChromiumOptions.java[175-178]
java/src/org/openqa/selenium/bidi/BiDiProvider.java[94-106]
java/src/org/openqa/selenium/grid/node/local/LocalNode.java[1242-1250]

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

## Issue description
`RemoteWebDriver.startSession` decides whether to call `createBiDi()` using `Boolean.TRUE.equals(this.capabilities.getCapability("webSocketUrl"))`, but `this.capabilities` represents the *response* capabilities where `webSocketUrl` is typically a **String WebSocket URL** when BiDi is supported. This prevents BiDi from being initialized for normal BiDi-capable sessions and causes Java behavior to diverge from other Selenium bindings.

## Issue Context
- Client code may *request* BiDi by sending `webSocketUrl: true` in options.
- The remote end typically *responds* with `webSocketUrl: "ws(s)://..."` when BiDi is available.
- Java `createBiDi()` reads `webSocketUrl` and expects it to be a `String` (otherwise it returns empty/no-ops).
- Other bindings (Python/JS/.NET) generally check for the presence of a returned `webSocketUrl` value (not a boolean) to enable BiDi.

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[263-297]
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-297]
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[437-442]

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


Results up to commit cd4e3ab


🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. createBiDi() called unconditionally ✗ Dismissed 📘 Rule violation ≡ Correctness
Description
RemoteWebDriver.startSession now unconditionally calls createBiDi(), which can eagerly establish
a BiDi WebSocket connection whenever the server returns a string webSocketUrl, changing
user-visible behavior even if the client never explicitly enabled BiDi. Compliance requires either
cross-binding comparison evidence (since other bindings appear to initialize BiDi lazily/on first
use) or clear documentation of any intentional divergence, as this can add session-start latency and
trigger unexpected outbound WebSocket attempts/warnings.
Code

java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295]

+      this.biDi = createBiDi();
Evidence
The cited change in RemoteWebDriver.startSession assigns this.biDi = createBiDi() during session
creation, making BiDi initialization unconditional. createBiDi() will then immediately create a
WebSocket-backed connection when the returned session capabilities contain a string webSocketUrl
(via new Connection(...), whose constructor calls client.openSocket(...)), meaning a connection
attempt can occur even without an explicit client opt-in; elsewhere BiDi is framed as opt-in via
enableBiDi() setting webSocketUrl: true, and tests describe the expected flow as requesting
webSocketUrl: true before connecting. Since other bindings in the repo appear to establish BiDi
lazily when BiDi APIs are accessed, this constitutes a potentially divergent, user-visible behavior
change that the compliance checklist requires to be validated via cross-binding comparison or
explicitly documented as intentional.

Rule 389265: Compare cross-language bindings when changing user-visible behavior
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-296]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[435-469]
py/selenium/webdriver/remote/webdriver.py[1198-1222]
javascript/selenium-webdriver/lib/webdriver.js[1304-1314]
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[263-306]
java/src/org/openqa/selenium/bidi/Connection.java[80-86]
java/src/org/openqa/selenium/chromium/ChromiumOptions.java[175-178]
java/test/org/openqa/selenium/grid/router/TunnelWebsocketTest.java[457-467]

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

## Issue description
Java `RemoteWebDriver.startSession` now eagerly initializes BiDi by unconditionally calling `createBiDi()`, which can immediately open a WebSocket whenever the server returns a string `webSocketUrl` in the *returned* capabilities. This can create unsolicited BiDi connections (even if the client never enabled BiDi), add session-start latency, and produce unexpected outbound WebSocket attempts/warnings; per compliance, you must either align behavior with other bindings (which appear to initialize BiDi lazily/on first use) or provide explicit cross-binding comparison evidence and document any intentional divergence.

## Issue Context
- `startSession` now assigns `this.biDi = createBiDi()` during session creation based solely on the returned `webSocketUrl` capability.
- `createBiDi()` opens a WebSocket immediately when `webSocketUrl` is present (through `new Connection(...)` and `Connection` invoking `client.openSocket(...)`).
- Elsewhere BiDi is treated as explicit opt-in: `enableBiDi()` sets `webSocketUrl: true`, and tests describe the expected flow as “client requests `webSocketUrl: true` … then connects”.
- Other Selenium language bindings in this repo (e.g., Python/JavaScript) appear to initialize BiDi lazily when BiDi APIs are accessed rather than during session creation.
- Compliance requires cross-binding comparison for user-visible behavior changes in a binding, or clear documentation/rationale near the change for any intended divergence (and reflected in tests if applicable).

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[292-296]

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



Remediation recommended
2. BiDi regression test missing 📘 Rule violation ▣ Testability
Description
This bug-fix change alters BiDi initialization behavior in startSession, but the provided change
set includes no updated/new automated test that would fail if the change were reverted. The
compliance checklist requires regression coverage for bug fixes affecting observable behavior.
Code

java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295]

+      this.biDi = createBiDi();
Evidence
The diff shows a functional behavior change at startSession (BiDi initialization path), but no
test change is present in the provided patch to lock in the expected behavior. The checklist
requires regression tests for bug fixes/new behavior.

Rule 389273: Require tests for all new functionality and bug fixes
java/src/org/openqa/selenium/remote/RemoteWebDriver.java[293-296]

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

## Issue description
A behavioral bug fix to BiDi initialization lacks an accompanying regression test update in the provided change set.

## Issue Context
The change modifies session startup behavior (`startSession`) to set `biDi` via `createBiDi()`. Per compliance, bug fixes and user-visible behavior changes should have an automated test that would fail under the pre-fix behavior.

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295-295]

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


Qodo Logo

Comment thread java/src/org/openqa/selenium/remote/RemoteWebDriver.java Outdated
if (Boolean.TRUE.equals(capabilities.getCapability("webSocketUrl"))) {
this.biDi = createBiDi();
}
this.biDi = createBiDi();

@qodo-code-review qodo-code-review Bot Jul 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Action required

1. createbidi() called unconditionally 📘 Rule violation ≡ Correctness


RemoteWebDriver.startSession now unconditionally calls createBiDi(), which can eagerly establish
a BiDi WebSocket connection whenever the server returns a string webSocketUrl, changing
user-visible behavior even if the client never explicitly enabled BiDi. Compliance requires either
cross-binding comparison evidence (since other bindings appear to initialize BiDi lazily/on first
use) or clear documentation of any intentional divergence, as this can add session-start latency and
trigger unexpected outbound WebSocket attempts/warnings.
Agent Prompt
## Issue description
Java `RemoteWebDriver.startSession` now eagerly initializes BiDi by unconditionally calling `createBiDi()`, which can immediately open a WebSocket whenever the server returns a string `webSocketUrl` in the *returned* capabilities. This can create unsolicited BiDi connections (even if the client never enabled BiDi), add session-start latency, and produce unexpected outbound WebSocket attempts/warnings; per compliance, you must either align behavior with other bindings (which appear to initialize BiDi lazily/on first use) or provide explicit cross-binding comparison evidence and document any intentional divergence.

## Issue Context
- `startSession` now assigns `this.biDi = createBiDi()` during session creation based solely on the returned `webSocketUrl` capability.
- `createBiDi()` opens a WebSocket immediately when `webSocketUrl` is present (through `new Connection(...)` and `Connection` invoking `client.openSocket(...)`).
- Elsewhere BiDi is treated as explicit opt-in: `enableBiDi()` sets `webSocketUrl: true`, and tests describe the expected flow as “client requests `webSocketUrl: true` … then connects”.
- Other Selenium language bindings in this repo (e.g., Python/JavaScript) appear to initialize BiDi lazily when BiDi APIs are accessed rather than during session creation.
- Compliance requires cross-binding comparison for user-visible behavior changes in a binding, or clear documentation/rationale near the change for any intended divergence (and reflected in tests if applicable).

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[292-296]

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

createBiDi() returns an empty Optional unless the remote actually returned a webSocketUrl, so no connection is opened for browsers that didn't negotiate BiDi — and this only restores the eager behavior ChromiumDriver/FirefoxDriver already had before #17753 moved BiDi creation up into RemoteWebDriver."

if (Boolean.TRUE.equals(capabilities.getCapability("webSocketUrl"))) {
this.biDi = createBiDi();
}
this.biDi = createBiDi();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remediation recommended

2. Bidi regression test missing 📘 Rule violation ▣ Testability

This bug-fix change alters BiDi initialization behavior in startSession, but the provided change
set includes no updated/new automated test that would fail if the change were reverted. The
compliance checklist requires regression coverage for bug fixes affecting observable behavior.
Agent Prompt
## Issue description
A behavioral bug fix to BiDi initialization lacks an accompanying regression test update in the provided change set.

## Issue Context
The change modifies session startup behavior (`startSession`) to set `biDi` via `createBiDi()`. Per compliance, bug fixes and user-visible behavior changes should have an automated test that would fail under the pre-fix behavior.

## Fix Focus Areas
- java/src/org/openqa/selenium/remote/RemoteWebDriver.java[295-295]

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

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit cd4e3ab

@diemol diemol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why the need for this change? This will create a BiDi connection for every browser, even if it is not desired or the browser does not support it.

@baflQA

baflQA commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Why the need for this change? This will create a BiDi connection for every browser, even if it is not desired or the browser does not support it.

Not true. The createBiDi() method does all the required checks, returning an empty optional if many conditions are not fulfilled. If the webSocketUrl is not among the returned capabilities, or it does not match the ws url pattern, it won't be created.
When the remote driver is created, the RemoteDriverBuilder passes empty capabilities to the RemoteDriver constructor.
As a result, we must check the returned capabilities, not the requested capabilities (as the createBiDi method already does). So, we can refactor the existing if
if (Boolean.TRUE.equals(capabilities.getCapability("webSocketUrl")))

but since in the response it's not a boolean value, but the WS url, we would basically have to duplicate the checks that are already performed in the createBiDi method.

@titusfortner

Copy link
Copy Markdown
Member

@baflQA reasoning is correct here, and the solution is good. Can you add a test?

@titusfortner titusfortner changed the title Use response capabilities [java] Fix BiDi not initializing for RemoteWebDriver built via builder Jul 14, 2026
@baflQA

baflQA commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

If i will be able to setup the workspace, I'll do my best.

@pujagani

pujagani commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

We should check if the websocketurl was set by the requested capabilities before creating a BiDi session i.e. the user requested for BiDi. That check should not be removed ideally. createBiDi() does checks on the returned capabilities and if that is a correct websocketURL to make the websocket connection, which ideally will happen only if BiDi was requested from end-user. That is how the code should look. For Firefox, when it does not support BiDi returns the same capability value back i.e. boolean value, hence the checks in createBiDi().

I am not sure why that breaks when using the builder. Can you please share a code snippet of how you are invoking the RemoteWebDriver builder that worked before the regression?

@pujagani

pujagani commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Based on the discussion with @baflQA on Slack and reading the spec, the changes here should be fine. There shouldnt be scenario that websocketurl exists in returned caps without user requesting it based on the spec and my understanding of it. I will also help adding tests. Thank you @baflQA for your contribution!

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit f9e37e5

@pujagani

Copy link
Copy Markdown
Contributor

Closing this, I was unable to add tests to this branch. So I have same changes and commits in another PR with unit tests added #17792

@pujagani pujagani closed this Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-java Java Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants