Firefox windows don't close after Selenium test has run
Asked Answered
C

11

12

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.

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.

Cr answered 12/8, 2010 at 9:27 Comment(1)
Jus to clarify, are you running the RC on a Windows box (so the browser is being run in Windows) or are you running the test on a Windows box (so your client code is run in Windows and connects to an RC), or both?Giacobo
C
6

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.

Cr answered 18/8, 2010 at 8:28 Comment(1)
That is basic of RC..setup, test, teardown. :)Fetterlock
A
10

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.

Andorra answered 4/6, 2012 at 21:11 Comment(0)
C
6

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.

Cr answered 18/8, 2010 at 8:28 Comment(1)
That is basic of RC..setup, test, teardown. :)Fetterlock
G
3

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)

Gunter answered 27/9, 2010 at 21:42 Comment(0)
P
0

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.

Pademelon answered 17/8, 2010 at 21:46 Comment(0)
F
0

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)

Fairfield answered 6/9, 2010 at 8:52 Comment(0)
L
0

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

Lutist answered 20/9, 2010 at 20:49 Comment(0)
J
0

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

Justus answered 30/6, 2011 at 20:35 Comment(0)
S
0

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.

Suicidal answered 6/7, 2012 at 9:1 Comment(0)
O
0

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.

Overwhelm answered 26/3, 2013 at 5:40 Comment(0)
A
0

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"

Available answered 5/8, 2013 at 19:22 Comment(0)
I
0

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.

Intercessor answered 17/2, 2019 at 22:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.