1

My code is the following:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless");
    WebDriver driver

    try {
       driver = new ChromeDriver(options); //THE EXCEPTION GETS THROWN HERE

      // ...other code that doesn't get reached...
    }
    finally {
      if(driver != null) {
        logger.info("Quitting the driver...");
        driver.quit();
      }
      else {
        logger.info("Driver is null"); //THIS GETS LOGGED
      }
    }

An exception gets launched because of some problems with google-chrome. The exception that gets launched is the following (I add it just for completeness, but my question isn't related to this exception in particular but to the behaviour of ChromeDriver):

org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'localhost.localdomain', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.45.1.el7.x86_64', java.version: '11.0.12'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x563587e52ee3 <unknown>
#1 0x563587920608 <unknown>
#2 0x5635879438ef <unknown>
#3 0x56358793f46f <unknown>
#4 0x563587979f45 <unknown>
#5 0x563587974163 <unknown>
#6 0x563587949bfc <unknown>
#7 0x56358794ac05 <unknown>
#8 0x563587e84baa <unknown>
#9 0x563587e9a651 <unknown>
#10 0x563587e85b05 <unknown>
#11 0x563587e9ba68 <unknown>
#12 0x563587e7a05f <unknown>
#13 0x563587eb6818 <unknown>
#14 0x563587eb6998 <unknown>
#15 0x563587ed1eed <unknown>
#16 0x7f7b4b962ea5 <unknown>

    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)

The problem is that when the code reaches the finally block the driver.quit() doesn't get executed, because the driver object is null. Against my expectations, the chromedriver process runs (I checked with ps -aux | grep chromedriver). I wouldn't expect it honestly, because the driver being null suggests me that the process failed to be created. How do I handle this situation? Do I have to make my application kill the chromedriver process?

0 Answers0