Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ private List<String> toArguments() {
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());
Comment on lines 153 to 160
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

Expand Down
56 changes: 56 additions & 0 deletions java/test/org/openqa/selenium/remote/service/DriverFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.manager.SeleniumManager;
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
Expand Down Expand Up @@ -193,6 +194,61 @@ void createsArgumentsForSeleniumManager() throws IOException {
verifyNoMoreInteractions(seleniumManager);
}

@Test
void createsArgumentsForSeleniumManagerWithSystemProxySettings() throws IOException {
createsArgumentsForSeleniumManagerWithProxySettings(ProxyType.SYSTEM);
}

@Test
void createsArgumentsForSeleniumManagerWithAutodetectProxySettings() throws IOException {
createsArgumentsForSeleniumManagerWithProxySettings(ProxyType.AUTODETECT);
}

@Test
void createsArgumentsForSeleniumManagerWithDirectProxySettings() throws IOException {
createsArgumentsForSeleniumManagerWithProxySettings(ProxyType.DIRECT);
}

void createsArgumentsForSeleniumManagerWithProxySettings(ProxyType proxyType) throws IOException {
when(service.getExecutable()).thenReturn(null);
when(service.getDriverProperty()).thenReturn("property.selenium.manager.empty");
when(service.getDriverEnvironmentVariable())
.thenReturn("ENVIRONMENT_VARIABLE_IGNORES_SELENIUM_MANAGER");

Proxy proxy = new Proxy().setProxyType(proxyType);
Capabilities capabilities =
new ImmutableCapabilities(
"browserName",
"chrome",
"browserVersion",
"beta",
"proxy",
proxy,
"goog:chromeOptions",
Map.of("binary", browserFile.toString()));
DriverFinder finder = new DriverFinder(service, capabilities, seleniumManager);

List<String> arguments = new ArrayList<>();
arguments.add("--browser");
arguments.add("chrome");
arguments.add("--browser-version");
arguments.add("beta");
arguments.add("--browser-path");
arguments.add(browserFile.toString());
Result result = new Result(0, "", driverFile.toString(), browserFile.toString());
doReturn(result).when(seleniumManager).getBinaryPaths(arguments);

assertThat(finder.getDriverPath()).isEqualTo(driverFile.toString());
assertThat(finder.getBrowserPath()).isEqualTo(browserFile.toString());
verify(service, times(1)).getExecutable();
verify(service, times(1)).getDriverName();
verify(service, times(1)).getDriverProperty();
verify(service, times(1)).getDriverEnvironmentVariable();
verifyNoMoreInteractions(service);
verify(seleniumManager, times(1)).getBinaryPaths(arguments);
verifyNoMoreInteractions(seleniumManager);
}

private Path createExecutableFile(String prefix) {
Path driverFile = null;
try {
Expand Down
Loading