Skip to content

[🐛 Bug]: Selenium remote driver is giving error with proxy authentication #14176

Open
@pvsharma

Description

@pvsharma

What happened?

I am trying to launch a browser in BitBAr from my IDE setup. I have to bypass the proxy and then connect to remote server. After doing some google & stackoverlow help I wrote this code. But it does not seem to work with Java 11 but it connects the remote browser with Java 8. Can someone please help as I have spent lot of time undertanding the issue byt failed to get the solution

Selenium version used - 4.21.1 (used previous ones also) Jave version (11)

The errors I get are

getMessage(): Could not start a new session. Unable to parse remote response:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to parse remote response:

Caused by: org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read:

How can we reproduce the issue?

public static void main(String[] args) throws IOException, InterruptedException, NoSuchFieldException {
        MutableCapabilities capabilities = new MutableCapabilities();
        
        // SET PROXY DETAILS
        String proxyHost = "someurl.com";
        int proxyPort = 8080;
        String proxyUser = "proxyUSer";
        String proxyPassword = "proxyPassword";
        String remoteDesktopURL = "https://us-west-desktop-hub.bitbar.com/wd/hub/";
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
        ClientConfig config = null;

        // CONFIG TO ADD CREDENTIALS
        try {
            config = ClientConfig.defaultConfig()
                    .readTimeout(Duration.ofSeconds(90))
                    .authenticateAs(new UsernameAndPassword(proxyUser, proxyPassword))
                    .proxy(proxy)
                    .baseUrl(new URL(remoteDesktopURL));
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }

        capabilities.setCapability("platformName", "macOS");
        capabilities.setCapability("browserName", "chrome");
        capabilities.setCapability("browserVersion", "120");

        //Setting BITBAR capabilities
        HashMap<String, String> bitbarOptions = new HashMap<String, String>();
        bitbarOptions.put("apiKey", "someKey");
        bitbarOptions.put("osVersion", "12");
        bitbarOptions.put("resolution", "2560x1920");
        bitbarOptions.put("seleniumVersion", "4");
        bitbarOptions.put("bitbar_testTimeout", "1800");

        // Creating a RemoteWebDriver instance with Bitbar capabilities
        try{
            driver = RemoteWebDriver.builder()
                    .config(config)
                    .oneOf(capabilities)
                    .setCapability("bitbar:options", bitbarOptions)
                    .build();
        }
        catch (Exception e){
 
            e.printStackTrace();
        }

        driver.get("https://www.bbc.co.uk/");

Relevant log output

StackTrace: 
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Unable to parse remote response:  
Host info: host: 'HOR135F.local', ip: 'fdde:c05c:634:210a:cbf:d3cb:7650:59cc%en0'
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:100)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:75)
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.getRemoteDriver(RemoteWebDriverBuilder.java:394)
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.build(RemoteWebDriverBuilder.java:366)
	at org.example.WithProxyWithVPN.main(WithProxyWithVPN.java:88)
Caused by: org.openqa.selenium.json.JsonException: Unable to parse: 
	at org.openqa.selenium.json.Json.toType(Json.java:169)
	at org.openqa.selenium.json.Json.toType(Json.java:152)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:96)
	... 4 more
Caused by: org.openqa.selenium.json.JsonException: Expected to read a START_MAP but instead have: END. Last 0 characters read: 
Build info: version: '4.21.0', revision: '79ed462ef4'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '14.5', java.version: '11.0.18'
Driver info: driver.version: unknown
	at org.openqa.selenium.json.JsonInput.expect(JsonInput.java:467)
	at org.openqa.selenium.json.JsonInput.beginObject(JsonInput.java:333)
	at org.openqa.selenium.json.MapCoercer.lambda$apply$1(MapCoercer.java:64)
	at org.openqa.selenium.json.JsonTypeCoercer.lambda$buildCoercer$6(JsonTypeCoercer.java:171)
	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)
	... 6 more
Exception in thread "main" java.lang.NullPointerException

Operating System

macOS

Selenium version

4.21

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

BitBar Chrome

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

Chrome 123

Are you using Selenium Grid?

4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-javaJava BindingsI-defectSomething is not working as intendedJ-staleApplied to issues that become stale, and eventually closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions