Selenium Firefox Webdriver有时候没有关闭

时间:2013-11-13 08:25:20

标签: java firefox selenium selenium-webdriver

我的问题是,有时当我测试一个网站时,FF webdriver在测试后没有关闭浏览器窗口,尽管它继续测试过程,直到打开这么多窗口,没有剩余内存。 我已经尝试过使用driver.close()和driver.quit()以及它们两个,但有时它们似乎没有用。有没有办法强迫司机退出?我查看了杀死进程,但我似乎无法获得已启动的Web驱动程序的PID ... 我是唯一一个遇到过这个问题的人吗?

3 个答案:

答案 0 :(得分:0)

好吧,我不确定您的代码是什么样子的(因为您没有提供它),但是这种测试的通常流程是让类具有以下方法。

public class TestClass {

     private WebDriver driver;

     @BeforeClass
     public void setUp() {
         driver = new FirefoxDriver(); //or any other one
     }

     @Test
     public void test1() {}

     @Test
     public void test2() {}

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

请注意,您不必在测试方法中调用WebDriver#closeWebDriver#quit,您可以在测试期间重复使用浏览器会话。

答案 1 :(得分:0)

您需要在框架tearDown中为每个testCase 调用driver.quit(),就像您应该在每个testCase的框架setUp中分配它一样。 看看http://siking.wordpress.com/2013/02/28/what-is-wrong-with-groovytestcase-and-selenium/,它在某种程度上描述了你的问题。

答案 2 :(得分:-1)

我让Firefox使用driver.quit()。我做的是卸载我当前的版本,并从Modzilla公开的这个目录下载旧版本的Firefox: https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/

我从这里下载的版本是“Firefox Setup 27.0.exe”: https://ftp.mozilla.org/pub/mozilla.org/firefox/releases/27.0/win32/en-US/

之后一切顺利。


在我切换Firefox版本之前,我使用Firefox浏览器从这里下载Selenium IDE: http://www.seleniumhq.org/download/  enter image description here

Selenium IDE是一个Firefox插件。

我认为发生的事情就是这个=当我使用Firefox版本32(最新版本)并查看“Extensions”选项时,Selenium IDE将无法显示。现在我有Firefox版本27,Selenium IDE出现了,它看起来像这样: enter image description here

相关问题