org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start with Selenium and Java

Viewed 913

I have tried everything that has been told in Stackoverflow topics. I have java selenium tests run on remote slave through jenkins. The absurd thing is first test always run and browsers opens, all other tests give me "Timed out waiting for driver server to start".

public WebDriver startChrome() {
            
    System.setProperty("java.net.preferIPv4Stack", "true");
    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    ChromeOptions chromeOptions = new ChromeOptions();
    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("credentials_enable_service", false);
    prefs.put("profile.password_manager_enabled", false);
    chromeOptions.addArguments("--no-sandbox"); 
    chromeOptions.addArguments("--disable-dev-shm-usage"); 
    chromeOptions.addArguments("--aggressive-cache-discard"); 
    chromeOptions.addArguments("--disable-cache"); 
    chromeOptions.addArguments("--disable-application-cache"); 
    chromeOptions.addArguments("--disable-offline-load-stale-cache"); 
    chromeOptions.addArguments("--disk-cache-size=0");
    chromeOptions.addArguments("--dns-prefetch-disable"); 
    chromeOptions.addArguments("--no-proxy-server"); 
    chromeOptions.addArguments("--log-level=3"); 
    chromeOptions.addArguments("--silent"); 
    chromeOptions.addArguments("--disable-browser-side-navigation"); 
    chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL); 
    chromeOptions.addArguments("-disable-cache");
    chromeOptions.addArguments("-disable-extensions");
    chromeOptions.addArguments("--incognito");
    chromeOptions.addArguments("start-maximized");
    //chromeOptions.setExperimentalOption("useAutomationExtension", false);
    ChromeDriverService chromeDriverService = ChromeDriverService.createDefaultService();
    port = chromeDriverService.getUrl().getPort();
    return new ChromeDriver(chromeDriverService, chromeOptions);
}

Error:

Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '4.0.0-alpha-7', revision: 'de8579b6d5'
System info: host: 'ISTDTSTYNMD04V', ip: '10.52.253.54', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_271'
Driver info: driver.version: unknown
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:231)
    at org.openqa.selenium.remote.service.DriverService.lambda$start$0(DriverService.java:193)
    at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604)
    at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1596)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1067)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1703)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:172)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:35592/status] to be available after 20000 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:90)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:227)
    ... 7 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:88)
    ... 8 more

All the solutions I have tried so far:

  • Update Java 1_8_271
  • Update Selenium 4
  • Update ChromeDriver 87
  • Check localhost traffic with rawcap
  • Check localhost dns definiton in etc/hosts
  • Update Chrome 87
  • Set Proxy
  • Check port availability
  • Check driver path
  • Kill all chrome and driver tasks before create (Only solution that worked, but not good for parallel tests)
  • Check localhost url and port is accessible with chrome -> http 200

When I try to reach url and port through java urlconnection in code driver create function catch block), it gives me connection reset but in chrome it gives 200.

All help will be appreciated.

Best Regards

1 Answers

This error message...

Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. 
Build info: version: '4.0.0-alpha-7', revision: 'de8579b6d5' 
System info: host: 'ISTDTSTYNMD04V', ip: '10.52.253.54', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_271' 
Driver info: driver.version: unknown

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.

A bit of more information about your usecase would have helped us to analyze the error in a better way. However to start with you can use only one single arguments start-maximized and remove all the other arguments which would get you started. So your effective code block will be:

public WebDriver startChrome() {

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("start-maximized");
    ChromeDriverService chromeDriverService = ChromeDriverService.createDefaultService();
    return new ChromeDriver(chromeDriverService, chromeOptions);
}

Additional Consideration

Ensure that:

  • JDK is upgraded to current levels JDK 8u271.
  • Selenium is upgraded to current released Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v87.0 level.
  • Chrome is updated to current Chrome Version 87.0 level. (as per ChromeDriver v87.0 release notes).
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

References

You can find a couple of relevant detailed discussions in:

Related