selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[πŸ› Bug]: Setting a Proxy when using RemoteWebdriver does not start the session

Open tslape opened this issue 3 years ago β€’ 8 comments

What happened?

When attempting to run a test using using selenium-server-4.11.0.jar to start a standalone server and using a proxy with RemoteWebdriver, the session is never started. It cannot cast class java.util.LinkedHashMap to org.openqa.selenium.Proxy

Using a proxy with Chromedriver does not see an issue. Starting the server with the previous version, selenium-server-4.10.0.jar, does not see any issues with the proxy and RemoteWebdriver. The issue persists even when specifying the JDK client 4.11.0 to start the server.

How can we reproduce the issue?

java -jar selenium-server-4.11.0.jar standalone --selenium-manager true
java -jar selenium-server-4.10.0.jar standalone --selenium-manager true
java -Dwebdriver-http.factory=jdk-http-client -jar selenium-server-4.11.0.jar --ext selenium-http-jdk-client=4.11.0.jar standalone --selenium-manager true
java -Dwebdriver-http.factory=jdk-http-client -jar selenium-server-4.10.0.jar --ext selenium-http-jdk-client=4.10.0.jar standalone --selenium-manager true

using OpenQA.Selenium.Chrome;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace ClassLibrary1
{
    [TestClass]
    public class FirstScriptTest
    {

        [TestMethod]
        public void ChromeDriverSession()
        {
            var driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");

            var title = driver.Title;
            Assert.AreEqual("Web form", title);

            driver.Quit();
        }

        [TestMethod]
        public void RemoteWebdriverSession()
        {
            var driver = new RemoteWebDriver(new Uri("http://localhost:4444"), new ChromeOptions());

            driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");

            var title = driver.Title;
            Assert.AreEqual("Web form", title);

            driver.Quit();
        }

        [TestMethod]
        public void ChromeDriverSessionWithProxy()
        {
            var chromeOptions = new ChromeOptions();
            var proxy = new Proxy
            {
                IsAutoDetect = true,
                Kind = ProxyKind.AutoDetect
            };
            chromeOptions.Proxy = proxy;
            var driver = new ChromeDriver(chromeOptions);

            driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");

            var title = driver.Title;
            Assert.AreEqual("Web form", title);

            driver.Quit();
        }
        [TestMethod]
        public void RemoteWebdriverSessionWithProxy()
        {
            var chromeOptions = new ChromeOptions();

            var proxy = new Proxy
            {
                IsAutoDetect = true,
                Kind = ProxyKind.AutoDetect
            };
            chromeOptions.Proxy = proxy;
            var driver = new RemoteWebDriver(new Uri("http://localhost:4444"), chromeOptions);

            driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");

            driver.Quit();
        }
    }
}

Relevant log output

{
    "eventName": "exception",
    "attributes": {
        "exception.message": "Unable to create session: Could not start a new session. Unable to obtain: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*]}, proxy: {proxyType: autodetect}}, error class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.Proxy (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.Proxy is in unnamed module of loader 'app')\nFor documentation on this error, please visit: https:\u002f\u002fwww.selenium.dev\u002fdocumentation\u002fwebdriver\u002ftroubleshooting\u002ferrors\u002fdriver_location\u002f\nBuild info: version: '4.11.0', revision: '040bc5406b'\nSystem info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'\nDriver info: driver.version: unknown \nHost info: host: '{{computerName}}', ip: '{{ipAddress}}'\nBuild info: version: '4.11.0', revision: '040bc5406b'\nSystem info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'\nDriver info: driver.version: unknown",
        "exception.stacktrace": "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to obtain: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*]}, proxy: {proxyType: autodetect}}, error class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.Proxy (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.Proxy is in unnamed module of loader 'app')\nFor documentation on this error, please visit: https:\u002f\u002fwww.selenium.dev\u002fdocumentation\u002fwebdriver\u002ftroubleshooting\u002ferrors\u002fdriver_location\u002f\nBuild info: version: '4.11.0', revision: '040bc5406b'\nSystem info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'\nDriver info: driver.version: unknown \nHost info: host: '{{computerName}}', ip: '{{ipAddress}}'\nBuild info: version: '4.11.0', revision: '040bc5406b'\nSystem info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'\nDriver info: driver.version: unknown\r\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:235)\r\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:73)\r\n\tat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)\r\n\tat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:467)\r\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:648)\r\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:565)\r\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:829)\r\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:785)\r\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)\r\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)\r\n\tat java.base\u002fjava.lang.Thread.run(Thread.java:833)\r\n",
        "exception.type": "org.openqa.selenium.SessionNotCreatedException",
        "logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor",
        "request.payload": "[Capabilities {browserName: chrome, goog:chromeOptions: {}, proxy: {proxyType: autodetect}}]"
    }
}




System.InvalidOperationException: Could not start a new session. Unable to obtain: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*]}, proxy: {proxyType: autodetect}}, error class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.Proxy (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.Proxy is in unnamed module of loader 'app')
For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'
Driver info: driver.version: unknown 
Host info: host: '{{computerName}}', ip: '{{ipAddress}}'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'
Driver info: driver.version: unknown (SessionNotCreated)

  Stack Trace: 
WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.StartSession(ICapabilities desiredCapabilities)
WebDriver.ctor(ICommandExecutor executor, ICapabilities capabilities)
RemoteWebDriver.ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
RemoteWebDriver.ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
RemoteWebDriver.ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
RemoteWebDriver.ctor(Uri remoteAddress, DriverOptions options)
FirstScriptTest.RemoteWebdriverSessionWithProxy() line 69

Operating System

Windows 11, Windows 10

Selenium version

Dotnet 4.11.0, JavaScript 4.11.1

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

Chrome 115

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

ChromeDriver Stable 115.0.5790.102

Are you using Selenium Grid?

4.11.0 with Java 17.0.8

tslape avatar Aug 02 '23 13:08 tslape

@tslape, 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!

github-actions[bot] avatar Aug 02 '23 13:08 github-actions[bot]

Why do you need to set a proxy for a remote browser?

diemol avatar Aug 03 '23 07:08 diemol

After a settings or network change on our workstations, running one test while on the VPN would take an extra 20 seconds for the initial load of the site. The issue was resolved by adding the AutoDetect proxy.

tslape avatar Aug 03 '23 11:08 tslape

Another use case: We use a proxy during our automated tests to fake server responses or track/assert browser requests.

fknittel avatar Aug 08 '23 14:08 fknittel

I'm also getting this issue- when setting proxy. When removing the proxy config it works:

Error: [0-0] 2023-08-09T11:47:19.327Z ERROR webdriver: session not created: Could not start a new session. Could not start a new session. Unable to obtain: Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 115.0, goog:chromeOptions: {args: []}, proxy: {proxyType: manual, sslProxy: http://Guadalajara.wonderpr...}, se:noVncPort: 7900, se:vncEnabled: true}, error class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.Proxy (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.Proxy is in unnamed module of loader org.openqa.selenium.grid.Bootstrap$PossessiveClassLoader @404b9385) [0-0] For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/ [0-0] Build info: version: '4.11.0', revision: '040bc5406b' [0-0] System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-124-generic', java.version: '11.0.20' [0-0] Driver info: driver.version: unknown [0-0] Host info: host: '8f1d9e0d6af0', ip: '10.0.62.12'

marwahaks avatar Aug 09 '23 11:08 marwahaks

I'm also stuck with this issue.

InvalidOperationException: Could not start a new session. Unable to obtain: Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, --enable-javascript, --no-sandbox, --disable-dev-shm-usage]}, proxy: {proxyType: manual, socksProxy: <removed>, socksVersion: 5}}, error class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.Proxy (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.Proxy is in unnamed module of loader 'app')
For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.1.0-11-amd64', java.version: '17.0.8'
Driver info: driver.version: unknown
Host info: host: '<removed>', ip: '127.0.1.1'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.1.0-11-amd64', java.version: '17.0.8'
Driver info: driver.version: unknown (SessionNotCreated)

<removed> - strings removed for security reasons

ilyabreev avatar Aug 14 '23 06:08 ilyabreev

I also have the same issue.

System.InvalidOperationException : Could not start a new session. Could not start a new session. Unable to obtain: Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 115.0, goog:chromeOptions: {args: [--ignore-certificate-errors, --disable-dev-shm-usage, --no-sandbox, --expose-internals-for-testing, --allow-running-insecure-co..., --disable-browser-side-navi..., --silent, --disable-gpu, --dns-prefetch-disable, --log-level=3, --aggressive-cache-discard, --disable-cache, --disable-application-cache, --disable-offline-load-stal...]}, proxy: {proxyType: direct}, se:noVncPort: 7900, se:vncEnabled: true}, error class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.Proxy (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.Proxy is in unnamed module of loader org.openqa.selenium.grid.Bootstrap$PossessiveClassLoader @17a7cec2)
For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location/
Build info: version: '4.11.0', revision: '040bc5406b'

johnqa avatar Aug 21 '23 14:08 johnqa

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 07 '23 00:12 github-actions[bot]