PhantomJS 1.9.2、ubuntu 12 LTS、および Ghostdirver 1.04 と Selenium 2.35 では、テスト後に phantomjs プロセスがぶら下がっています。誰でもこれを修正する良い方法を知っていますか?
以下は、奇妙な動作を示すテスト プログラムです。
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);
}
}
これを実行するには、phantomjs バイナリのパスをシステム プロパティとして指定するか、それに応じて変数を設定する必要があります。
これを実行させた後、このシェルコマンドを実行します
ps -ef | grep phantomjs
ぶら下がっている 10 個の phantomjs プロセスを見つけます。
代わりに使用d1.quit()
すると、ダングリングプロセスがなくなります。これは明らかに優れていますが、それでも同じ結果が得られると予想していました.close
。
これは https://github.com/detro/ghostdriver/issues/162#issuecomment-25536311のクロスポストです。
更新この投稿は、Richard の提案に従って変更されました (以下を参照)。