首页 文章

Selenium Firefox Webdriver有时候没有关闭

提问于
浏览
1

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

3 回答

  • -1

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

  • 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 ,您可以在测试期间重复使用浏览器会话 .

  • 0

    我让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

相关问题