SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.73k stars 8.02k forks source link

[🐛 Bug]: a value is required for '--proxy ' but none was supplied with ProxyType.DIRECT #14162

Closed Jobvdb closed 3 days ago

Jobvdb commented 1 week ago

What happened?

Im developing a test automation app that uses Selenium and with upgrading from 4.18.1 to 4.21.0, I got this error: Unable to obtain: chromedriver, error Command failed with code: 2, executed: [--browser, chrome, --proxy, --language-binding, java, --output, json] error: a value is required for '--proxy ' but none was supplied For more information, try '--help'.

In the example below, I'm using ProxyType.DIRECT, but any type will trigger this behavior (including AUTODETECT)

How can we reproduce the issue?

@Test
    void withProxy() {
        org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
        proxy.setProxyType(org.openqa.selenium.Proxy.ProxyType.DIRECT);
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setProxy(proxy);
        new ChromeDriver(chromeOptions);
    }

Relevant log output

org.openqa.selenium.remote.NoSuchDriverException: Unable to obtain: chromedriver, error Command failed with code: 2, executed: [--browser, chrome, --proxy, --language-binding, java, --output, json]
error: a value is required for '--proxy <PROXY>' but none was supplied

For more information, try '--help'.

        at org.openqa.selenium.remote.service.DriverFinder.getBinaryPaths(DriverFinder.java:121)
        at org.openqa.selenium.remote.service.DriverFinder.getDriverPath(DriverFinder.java:55)
        at org.openqa.selenium.chrome.ChromeDriver.generateExecutor(ChromeDriver.java:99)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:72)
        at nl.testautomaat.test.driver.web.RemoteTest.withProxy(RemoteTest.java:27)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: org.openqa.selenium.WebDriverException: Command failed with code: 2, executed: [--browser, chrome, --proxy, --language-binding, java, --output, json]
error: a value is required for '--proxy <PROXY>' but none was supplied

For more information, try '--help'.

        at org.openqa.selenium.manager.SeleniumManager.runCommand(SeleniumManager.java:169)
        at org.openqa.selenium.manager.SeleniumManager.getBinaryPaths(SeleniumManager.java:244)
        at org.openqa.selenium.remote.service.DriverFinder.getBinaryPaths(DriverFinder.java:102)
        ... 9 more
Caused by: org.openqa.selenium.json.JsonException: Unable to parse: error: a value is required for '--proxy <PROXY>' but none was supplied

For more information, try '--help'.

        at org.openqa.selenium.json.Json.toType(Json.java:169)
        at org.openqa.selenium.json.Json.toType(Json.java:152)
        at org.openqa.selenium.manager.SeleniumManager.runCommand(SeleniumManager.java:154)
        ... 11 more
Caused by: org.openqa.selenium.json.JsonException: Unable to determine type from: e. Last 1 characters read: e, next 107 characters to read: rror: a value is required for '--proxy <PROXY>' but none was supplied

For more information, try '--help'.

Build info: version: '4.21.0', revision: '79ed462ef4'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '14.0', java.version: '21.0.1'
Driver info: driver.version: ChromeDriver
        at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:166)
        at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$6(JsonTypeCoercer.java:167)
        at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:146)
        at org.openqa.selenium.json.Json.toType(Json.java:206)
        at org.openqa.selenium.json.Json.toType(Json.java:167)
        ... 13 more

Operating System

macOS

Selenium version

Java 4.21.0

What are the browser(s) and version(s) where you see this issue?

Chrome 126.0.6478.62 (Official build) (arm64)

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 126.0.6478.62

Are you using Selenium Grid?

No response

github-actions[bot] commented 1 week ago

@Jobvdb, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

titusfortner commented 1 week ago

Thanks for reporting, the bindings need to pass along the proxy information to Selenium Manager only when things need to be routed through a host instead of always,

Jobvdb commented 5 days ago

Thanks for picking this up! In the meantime, is there a work-around for this, except for not using the proxy setting?

titusfortner commented 5 days ago

Looks like it was added back in 4.9, which is too far back to make sense to downgrade versions.

Can either remove proxy or manage the drivers yourself for now.

Jobvdb commented 5 days ago

Alright, that was what I was going for, except I’m currently running 4.18.1 and it is working on that version. Not sure if that helps?

titusfortner commented 5 days ago

Oh, that's interesting. Can you turn on debugging and see what's different between the two? https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/

Jobvdb commented 4 days ago

Added Logger, but it seems to not log anything at all, before throwing the NoSuchDriverException. Maybe I'm doing it wrong? Here is my updated code:

@Test
    void withProxy() {
        Logger logger = Logger.getLogger("Proxy logger");
        logger.setLevel(Level.FINEST);
                Arrays.stream(logger.getHandlers()).forEach(handler -> {
            handler.setLevel(Level.FINEST);
        });

        org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
        proxy.setProxyType(org.openqa.selenium.Proxy.ProxyType.DIRECT);
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setProxy(proxy);
    }
diemol commented 3 days ago

You can try this tomorrow after the Nightly build has been generated. This will be also part of the 4.23 release.

Jobvdb commented 2 days ago

Perfect thanks! Tested and it works with the 4.23.0-SNAPSHOT version