luk*_*sch 13 memory-leaks webdriver phantomjs ghostdriver
在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);
}
}
Run Code Online (Sandbox Code Playgroud)
要运行它,您应该提供phantomjs二进制文件的路径作为系统属性或相应地设置变量.
让这个运行后我做这个shell命令
ps -ef | grep phantomjs
Run Code Online (Sandbox Code Playgroud)
并找到10个悬空的幻影过程.
如果我使用d1.quit(),我最终没有悬空过程.这显然更好,但我仍然希望得到相同的结果.close.
注意,这是 https://github.com/detro/ghostdriver/issues/162#issuecomment-25536311 的交叉链接
更新此帖子根据理查德的建议进行了更改(见下文).
| 归档时间: |
|
| 查看次数: |
8643 次 |
| 最近记录: |