Exception: null when setting up Selenium using ThreadLocal and ChromeDriver (Version 75)?

Current setup stored inside my DriverFactory:

private static ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
return webDriver.get();

Currently the following method seems to be failing:

public void loadUrl(String url) {
    try {
        getDriver().get(url);
        System.out.println("Successfully navigated to URL: " + url);
    } catch (Exception e) {
        System.out.println(e.getStackTrace());
        Assert.fail("Unable to navigate to URL: " + url + ", Exception: " + e.getMessage());
    }
}

Set driver method:

 public final void setDriver(String browser) throws Exception {
        String remoteHubUrl = "http://xxx.xxxx.xxx.xxx:4444/wd/hub/";
         try {
            switch (setBrowserType(browser)) {
                 case "grid":
                    DesiredCapabilities capabilities =new DesiredCapabilities();
                    capabilities.setBrowserName("chrome");
                    ChromeOptions op = new ChromeOptions();
                    op.merge(capabilities);
                    webDriver.set(new RemoteWebDriver(new URL(remoteHubUrl), op));
                        break;
                }
}

Exception Message:

Exception: null

There seems to be no issues when using older versions of chromedriver, any ideas?

Base Step which is used to initialise the driver prior to executing the tests:

@Before
public void setupHook()  {
    setDriver("grid");
}

1 answer

  • answered 2019-05-24 14:49 Ardesco

    The main Issue I see with the above code is that you are trying to instantiate a RemoteWebDriver instance using a ChromeOptions object instead of a DesiredCapabilities object.

    RemoteWebDriver requires a DesiredCapabilities (See Selenium code here) which ChromeOptions does not extend or implement. They do both extend AbstractCapabilities so you may just have been getting lucky in the past, but now they have diverged to an extent that they are no longer compatible.

    *EDIT*

    I would suggest you update your code to do this:

    switch (setBrowserType(browser)) {
        case "grid":
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setBrowserName("chrome");
            webDriver.set(new RemoteWebDriver(new URL(remoteHubUrl),capabilities));
            break;
    }