On PhantomJS 1.9.2, ubuntu 12 LTS and Ghostdirver 1.04 together with selenium 2.35 I get dangling phantomjs processes after my tests. Anyone knows a good way how to fix this?
Here is a test program that demonstrates the odd behavior:
package testing;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
public class PhantomIsNotKilledDemo {
private static WebDriver getDriver(){
String browserPathStr = System.getProperty("selenium.pathToBrowser");
if (browserPathStr == null) browserPathStr = "/home/user1/apps/phantomjs/bin/phantomjs";
DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability("takesScreenshot", true);
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
browserPathStr );
WebDriver driver = new PhantomJSDriver(caps);
return driver;
}
public static void main(String[] args) {
int max = 10;
for (int i = 0; i < max; i++){
WebDriver d1 = getDriver();
d1.get("http://www.imdb.com/title/tt1951264");
System.out.println("done with cycle " + (i+1) +" of "+max);
d1.close();
//d1.quit();
}
System.out.println("done");
System.exit(0);
}
}
To run this, you should supply the path of your phantomjs binary as system property or set the variable accordingly.
After letting this run I do this shell command
ps -ef | grep phantomjs
and find 10 dangling phantomjs processes.
If I use d1.quit()
instead, I end up with no dangling process. This is clearly better, but still I would have expected to get the same result with .close
.
Note, this is a crosspost of https://github.com/detro/ghostdriver/issues/162#issuecomment-25536311
Update This post is changed according to Richard's suggestion (see below).