Skip to content

[java] Handle system proxy setting for arguments passed to selenium manager#17402

Open
bhecquet wants to merge 1 commit intoSeleniumHQ:trunkfrom
bhecquet:proxy_system_for_selenium_manager
Open

[java] Handle system proxy setting for arguments passed to selenium manager#17402
bhecquet wants to merge 1 commit intoSeleniumHQ:trunkfrom
bhecquet:proxy_system_for_selenium_manager

Conversation

@bhecquet
Copy link
Copy Markdown
Contributor

This PR handles System proxy setting when using selenium manager

🔗 Related Issues

Fixes #17358

💥 What does this PR do?

The PR adds "system" proxy in the exclusion when building argument list of selenium manager

I've also added some units tests on this part, and also checked in a real test environment

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s):
    • What was generated:
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

N/A

🔄 Types of changes

  • Bug fix (backwards compatible)

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Handle system proxy setting for Selenium Manager arguments

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Exclude SYSTEM proxy type from Selenium Manager arguments
• Add unit tests for SYSTEM, AUTODETECT, and DIRECT proxy types
• Prevent system proxy settings from being passed to manager

Grey Divider

File Changes

1. java/src/org/openqa/selenium/remote/service/DriverFinder.java 🐞 Bug fix +2/-1

Exclude SYSTEM proxy type from manager arguments

• Added check to exclude Proxy.ProxyType.SYSTEM from proxy arguments passed to Selenium Manager
• Prevents system proxy configuration from being incorrectly forwarded to the manager

java/src/org/openqa/selenium/remote/service/DriverFinder.java


2. java/test/org/openqa/selenium/remote/service/DriverFinderTest.java 🧪 Tests +56/-0

Add proxy type handling unit tests

• Added import for ProxyType enum
• Created parameterized test helper method createsArgumentsForSeleniumManagerWithProxySettings()
• Added three new test cases for SYSTEM, AUTODETECT, and DIRECT proxy types
• Tests verify that proxy settings are correctly handled and not passed to Selenium Manager

java/test/org/openqa/selenium/remote/service/DriverFinderTest.java


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented Apr 28, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0)

Grey Divider


Action required

1. Dangling --proxy argument 🐞 Bug ≡ Correctness
Description
DriverFinder.toArguments() can add --proxy without a following proxy value when ProxyType is
neither DIRECT/AUTODETECT/SYSTEM but no ssl/http/pac value is set (e.g., default UNSPECIFIED or
MANUAL with only socksProxy/noProxy). This can cause Selenium Manager to mis-parse subsequent flags
(since it appends more args after the provided list) and fail driver/browser resolution.
Code

java/src/org/openqa/selenium/remote/service/DriverFinder.java[R153-160]

    Proxy proxy = Proxy.extractFrom(options);
    if (proxy != null
        && proxy.getProxyType() != Proxy.ProxyType.DIRECT
-        && proxy.getProxyType() != Proxy.ProxyType.AUTODETECT) {
+        && proxy.getProxyType() != Proxy.ProxyType.AUTODETECT
+        && proxy.getProxyType() != Proxy.ProxyType.SYSTEM) {
      arguments.add("--proxy");
      if (proxy.getSslProxy() != null) {
        arguments.add(proxy.getSslProxy());
Evidence
The code adds --proxy based only on proxy type, but only conditionally appends a value
(ssl/http/pac). Proxy defaults to UNSPECIFIED, and MANUAL can be set via noProxy/socksProxy without
setting http/ssl/pac—so the value can be missing. SeleniumManager then appends additional flags
after the provided arguments, meaning a trailing --proxy can consume the next flag as its value.
The existing DriverFinderTest shows the intended contract is --proxy followed by a value.

java/src/org/openqa/selenium/remote/service/DriverFinder.java[133-167]
java/src/org/openqa/selenium/Proxy.java[39-89]
java/src/org/openqa/selenium/Proxy.java[284-333]
java/src/org/openqa/selenium/manager/SeleniumManager.java[266-279]
java/test/org/openqa/selenium/remote/service/DriverFinderTest.java[155-185]

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

### Issue description
`DriverFinder.toArguments()` may append `--proxy` without any proxy value for some valid `Proxy` configurations (e.g., `ProxyType.UNSPECIFIED` default, or `ProxyType.MANUAL` where only `socksProxy`/`noProxy` is set). This can break Selenium Manager CLI parsing because additional flags are appended later.

### Issue Context
Selenium Manager is invoked with the list from `DriverFinder.toArguments()`, and then `SeleniumManager#getBinaryPaths` appends additional flags (e.g., `--language-binding`, `--output`). A dangling `--proxy` means the next appended flag can be consumed as the proxy value.

### Fix Focus Areas
- java/src/org/openqa/selenium/remote/service/DriverFinder.java[153-166]
- java/src/org/openqa/selenium/manager/SeleniumManager.java[266-279]
- java/test/org/openqa/selenium/remote/service/DriverFinderTest.java[155-250]

### Suggested fix
- Compute a `proxyArg` first (first non-null of `sslProxy`, `httpProxy`, `proxyAutoconfigUrl`, and *optionally* `socksProxy` if Selenium Manager supports it).
- Only add `--proxy` when `proxyArg != null && !proxyArg.isEmpty()`.
- Consider explicitly excluding `ProxyType.UNSPECIFIED` (or treating it as "no proxy").

### Tests to add/adjust
- Add a unit test where capabilities include `new Proxy()` (UNSPECIFIED) and assert Selenium Manager is called **without** `--proxy`.
- Add a unit test for `new Proxy().setNoProxy("...")` (MANUAL but no http/ssl/pac) and assert Selenium Manager is called **without** `--proxy` (or with an explicit supported value, depending on intended behavior).
- (Optional) Add a unit test for `setSocksProxy` verifying behavior matches the intended Selenium Manager support.

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


Grey Divider

Qodo Logo

@selenium-ci selenium-ci added the C-java Java Bindings label Apr 28, 2026
Comment on lines 153 to 160
Proxy proxy = Proxy.extractFrom(options);
if (proxy != null
&& proxy.getProxyType() != Proxy.ProxyType.DIRECT
&& proxy.getProxyType() != Proxy.ProxyType.AUTODETECT) {
&& proxy.getProxyType() != Proxy.ProxyType.AUTODETECT
&& proxy.getProxyType() != Proxy.ProxyType.SYSTEM) {
arguments.add("--proxy");
if (proxy.getSslProxy() != null) {
arguments.add(proxy.getSslProxy());
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. Dangling --proxy argument 🐞 Bug ≡ Correctness

DriverFinder.toArguments() can add --proxy without a following proxy value when ProxyType is
neither DIRECT/AUTODETECT/SYSTEM but no ssl/http/pac value is set (e.g., default UNSPECIFIED or
MANUAL with only socksProxy/noProxy). This can cause Selenium Manager to mis-parse subsequent flags
(since it appends more args after the provided list) and fail driver/browser resolution.
Agent Prompt
### Issue description
`DriverFinder.toArguments()` may append `--proxy` without any proxy value for some valid `Proxy` configurations (e.g., `ProxyType.UNSPECIFIED` default, or `ProxyType.MANUAL` where only `socksProxy`/`noProxy` is set). This can break Selenium Manager CLI parsing because additional flags are appended later.

### Issue Context
Selenium Manager is invoked with the list from `DriverFinder.toArguments()`, and then `SeleniumManager#getBinaryPaths` appends additional flags (e.g., `--language-binding`, `--output`). A dangling `--proxy` means the next appended flag can be consumed as the proxy value.

### Fix Focus Areas
- java/src/org/openqa/selenium/remote/service/DriverFinder.java[153-166]
- java/src/org/openqa/selenium/manager/SeleniumManager.java[266-279]
- java/test/org/openqa/selenium/remote/service/DriverFinderTest.java[155-250]

### Suggested fix
- Compute a `proxyArg` first (first non-null of `sslProxy`, `httpProxy`, `proxyAutoconfigUrl`, and *optionally* `socksProxy` if Selenium Manager supports it).
- Only add `--proxy` when `proxyArg != null && !proxyArg.isEmpty()`.
- Consider explicitly excluding `ProxyType.UNSPECIFIED` (or treating it as "no proxy").

### Tests to add/adjust
- Add a unit test where capabilities include `new Proxy()` (UNSPECIFIED) and assert Selenium Manager is called **without** `--proxy`.
- Add a unit test for `new Proxy().setNoProxy("...")` (MANUAL but no http/ssl/pac) and assert Selenium Manager is called **without** `--proxy` (or with an explicit supported value, depending on intended behavior).
- (Optional) Add a unit test for `setSocksProxy` verifying behavior matches the intended Selenium Manager support.

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

@cgoldberg cgoldberg changed the title #17358: handle system proxy setting for arguments passed to selenium … [java] Handle system proxy setting for arguments passed to selenium manager Apr 28, 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.

[🐛 Bug]: Grid does not get Driver when session capabilities expect "system" proxy

2 participants