开发者

Firefox windows don't close after Selenium test has run

I've been running my selenium tests using selenium rc for about 6 months and suddenly the firefox windows selenium opens do not close when the test is finished.

开发者_JAVA技巧

I am using a specific firefox profile and had not updated my selenium rc jar. I thought that perhaps the latest build of firefox may have been the problem but I reverted back to firefox 2 and the windows still stay open.

I'm running the test on a Windows box.

I've noticed other people seem to be having this problem - just wondering if anyone has a solution?

Thanks, Gearoid.


My solution was to use driver.quit() (this will auto close the Firefox browser) instead of driver.close() - even though there was only one Firefox window open, AFAIK.


Very simple solution in the end - just called SeleniumTestCase's tearDown() method (ie. we call super.tearDown(); from our base test class)

That closes down all the browser windows successfully.


We had this problem and after some investigation we fixed it.

In Selenium RC you have the file "grid_configuration.yml" where you have the list of browsers and their respective identifier, for instance "*firefox". Depending of your environment when you execute "firefox" you'll be probably calling a wrapper, an alias or a symbolic link of the firefox executable file. When Selenium is launched, it creates some fork process for the browser and depending if you are calling the firefox executable file directly or a wrapper, the creation of these process is different and when it tries to kill the process in the tearDown() it actually kills the child process and keep the father alive, so the tearDown() doesn't close the browser.

The solution is edit the "grid_configuration.yml" file changing "*firefox" for the absolute path of the browser executable file (always with * at the beginning)


We use Microsoft's freely available sysinternals pskill tool to kill the browser (including firefox) process.

By executing pskill "firefox.exe" that will kill a FireFox window.

If you need to execute that on a remote machine, you can use [psexec][3]. Also for both there are command switches to automatically accept the EULA (-accepteula) so you don't have to.


Gearóid: I cannot see how that would solve the problem. super.tearDown() is called automatically after each test case any way, so making an additional call would only make it run twice.

I have noticed that the browser windows do not shut down until the Selenium server is stopped. So, in my case, if there are 100 selenium tests, I would have 200 Firefox windows open before they are eventually closed when the Selenium server exits.

(I am running Fedora 13 and Firefox 3.6.7)


Using TestNG, you can precede the teardown() function with an @AfterMethod, or an @AfterTest annotation, instead of @AfterClass.


If you are using python at the end of your tearDown use super(unittest2.TestCase,self).tearDown()


Using MSTest, I was calling driver.Quit() in the TestCleanup but I keep end up with a load of Firefox windows open at end of the tests.

I have found that a NoSuchElementException seems to prevent the driver from successfully calling quit so wrapped up the TestCleanup with a try/finally:

[TestCleanup]
        public void TestCleanUp()
        {
            try
            {
                driver.FindElement(By.Id("ctl00_btnClearSession")).Click();
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                wait.Until((d) => { return d.FindElement(By.Id("ctl00_btnClearSession")).Displayed; });
             }
            finally {
                driver.Quit();
            }
        }

This worked with the problem I kept having but it may be the case that I have to wrap all my TestMethods with try/finally's as well. This is far from ideal, but I no longer seem to have windows left open when I do this.


I had the same issue. I am running Selenium as part of my Visual Studio unit tests and was having the same issue with Firefox browsers not closing at the end of tests.

Two things fixed this for me:

1) I updated the /core folder under the website with an up to date version.

2) I found that selenium was calling my Set Up method in a base class twice. Counter- intuitively (at least for me) it seems selenium calls the set up method in a parent class automatically. If you try to call it in a set up of a child class (ie with something like base.setup() ) it will run twice, and open up Firefox windows it can't close. I removed the calls to base.setup() and all my extra window problems were resolved.


Mere days from the question's 3rd birthday I submit yet another obscure solution:

My Firefox was in a custom location. Because I didn't want to babysit a custom JVM argument every time I ran my Selenium tests locally, I put a passthrough script in /usr/local/bin. Presumably Selenium was killing the process it started (my script), not the browser.

So I'm back to using the JVM argument for custom browser locations:

-Dwebdriver.firefox.bin="/path/to/firefox"


I had a similar issue when Firefox browser won't quite/close after a test run. Finally, I find out it was caused by excessive driver = webdriver.Firefox() line in one of the test module. My env. Selenium with Python & Firefox on Mac OS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜