1

I'm the frequent user of watir-webdriver. A fantastic gem, but I have an increasing issue with browsers that newer get closed. I run an ubuntu machine, that processes some background tasks, that fires up a firefox browser through watir webdriver. When the computer has been running fore some hours, processing typically more than a 100 jobs, then uncloses browsers start to become a problem. They take up memory, an eventually jams the computer forcing me to restart.

The problem occurs even though I do something like:

begin
  b = Watir::Browser.new :firefox, :profile => 'default'
  # Goto a few pages
  b.close
rescue => e
  b.close
  raise e
end

Any idea what I can do to solve it? is there a way to ensure that the processes are forced to quit if an exception occurs? And how I can debug it?

I often see a some timeout exceptions saying unable to bind to locking port or unable to obtain stable connection.

BTW ruby 1.9.3, ubuntu 12.04 watir-webdriver 0.6.1

Niels Kristian
  • 8,661
  • 11
  • 59
  • 117

2 Answers2

2

Try this:

begin
  b = Watir::Browser.new :firefox, :profile => 'default'
  # Goto a few pages
ensure
  b.close
end
Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
0

You might want to investigate headless solutions, such as the headless gem or Celerity.

The headless gem still drives a browser, just not on a display. Celerity, however, wraps HTMLUnit which is a virtual browser with decent javascript support. I've been using Celerity to run automated tests and it has been robust. The main caveat is that it is JRuby only.

Another option would be to use a leaner browser, such as webkit.

Mark Thomas
  • 37,131
  • 11
  • 74
  • 101
  • Thanks, but I already use the headless gem, but stat still runs a firefox application in the background. – Niels Kristian Oct 04 '12 at 06:33
  • Yeah, I've not had much luck with browser drivers on servers. Once I switched to Celerity I didn't have as many problems. – Mark Thomas Oct 04 '12 at 09:33
  • 1
    I'm using PhantomJS as headless browser, it's an almost feature complete WebKit implementation: http://phantomjs.org/ - not going to help with cross browser testing though, but good for unit tests! – dain Oct 04 '12 at 09:36
  • The headless gem is basically made for Linux, since it uses Xvfb: https://github.com/leonid-shevtsov/headless/issues/31 – Fredrik Bränström Oct 16 '16 at 07:09