Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle selenium crashes

I am currently automating tests with selenium RC which run every hour. Everything runs smoothly most of the time but there are some times where either firefox will crash or the selenium RC will just hang and because of these two issues the testing is not continued and is stalled. Does anyone know how I can make the firefox.exe and or java.exe(selenium instance) be killed when they do crash or hang, so testing can resume. The problems I see is detecting automatically when firefox or selenium is hanging and kill it via a script automatically.

thanks!

like image 295
si-mikey Avatar asked Mar 07 '11 06:03

si-mikey


People also ask

Can we use close () and quit together in Selenium?

close() closes only the current window on which Selenium is running automated tests. The WebDriver session, however, remains active. On the other hand, the driver. quit() method closes all browser windows and ends the WebDriver session.

What are the exception handling in Selenium?

Exception Handling in Selenium Exceptions are faults or disruptions that occur during the execution of a program/application. Exception handling is crucial for maintaining the natural or normal flow of the application. Selenium exceptions can be broadly categorized into two types: Checked and Unchecked Exceptions.

Is Selenium with python better than Java?

Selenium automation testing with Python can be the best decision ever. It has many advantages of using Python over Java for Selenium testing. 1. Python is an easy and a productive language than Java.


2 Answers

Ideally, each of your tests will be starting from a clean state, with no existing Firefox or IE processes running. In your test tearDown() methods, you should be closing / exiting your browsers. Even with this approach, sometimes, stray processes can still creep in. If you are running your Selenium server on Windows, via Java RC, putting this command in your tests' startUp() method can help ensure no browsers / instances are running:

Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

As far as detecting when they crash, Firefox will display an alert dialog indicating a crash. You can programatically interact with this window via external tools, such as AutoIT, which can automatically press the "OK" button on this dialog if you need. I've found that building an external AutoIT script that runs constantly in the background to handle popups, crashes, warnings, etc, is very helpful.

like image 114
NathanChristie Avatar answered Sep 23 '22 20:09

NathanChristie


Not sure I have the ultimate answer for you, but I can offer some ideas:

  • Selenium will have a time-out to deal with Firefox freezing. You should double check to make sure that is set correctly and working.
  • Whatever is running your selenium (like cruise control or team city) should also have a timeout that can kill off the selenium server.
  • People often revert to rebooting their servers once a day and report positive results.(Not me)
  • I would really encourage you to figure out the root cause of this. Selenium can feel frustrating and flaky, but after digging in, I've always found it was a diagnosable problem that could be fixed (like this).

(Se pushes us to terrible extremes: We actually wrote a ssh job triggered in TeamCity that logged into a windows machine and restarted the selenium server there. Ultimately we didn't use it.)

like image 23
ndp Avatar answered Sep 25 '22 20:09

ndp