How to close a ChromeDriver when running on Grid?
Asked Answered
S

2

6

I am currently running my tests with RemoteWebDriver with Selenium Grid 2 through TestNG suites. This works fine with Firefox and IE. Now I added Chrome and the tests run fine, but I always get an Exception when calling driver.quit() after all tests of a suite (works fine for FF and IE).

The Exception looks like this:

Error communicating with the remote browser. It may have died.
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)    
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:472)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:476)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:346)
at setups.StandardChromeSetup.tearDown(StandardChromeSetup.java:42)
19 lines not shown

Caused by Error communicating with the remote browser. It may have died. 
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:467)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:476)
at org.openqa.selenium.remote.RemoteWebDriver.quit(RemoteWebDriver.java:346)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101)
at $Proxy1.quit(Unknown Source)
at  org.openqa.selenium.support.events.EventFiringWebDriver.quit(EventFiringWebDriver.java:194)
at org.openqa.selenium.remote.server.handler.DeleteSession.call(DeleteSession.java:42)
at org.openqa.selenium.remote.server.handler.DeleteSession.call(DeleteSession.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:150)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722) 

I am using Selenium Version 2.24.1 and chromedriver.exe 21.0.1180.4

EDIT

Code for tearDown:

@AfterSuite
public void tearDown(){
  driver.quit();
}

Works perfectly for FF and IE with RemoteDriver and without. But not for chrome.

Starkey answered 25/6, 2012 at 10:3 Comment(3)
Can you post the code in setups.StandardChromeSetup.tearDownGnomic
added the info on tearDown it's nothing fancyStarkey
same setup & same problem here- I also get an os message that chromedriver.exe doesn't work anymore, when I confirm Google Chrome is killed.Sullyprudhomme
K
3

Faced the same problem. Here is how I resolved it. This seems to be a bug with the new version of the Chrome driver. Using the previous version of the driver (20.0.1133.0) solved this issue for me.

Check the driver download page.

Kweiyang answered 28/6, 2012 at 16:41 Comment(1)
I am currently on vacation so I can't test it ;-) When I get back to work and it works I ll accept your answer. ThanksStarkey
S
2

I see the cause of this may be that you are not closing active browsers before quitting the Driver. Try to close the windows, which may be the cause of some exceptions, with the following code:

Driver.Close();
Driver.Quit();

This should solve your issue.

Steelmaker answered 26/6, 2012 at 11:37 Comment(1)
I'm getting the same issue, but calling Close() before Quit() did not help.Dru

© 2022 - 2024 — McMap. All rights reserved.