I found this while looking for a solution to the same problem.
Something I came across was writing a very simple Ruby web service using Sinatra and letting it treat the browser object as a global variable:
require 'rubygems' require 'sinatra' require 'watir-webdriver' set :port, 9000 get '/openbrowser' do $browser = Watir::Browser.new :ff $timeout_length = 30 $browser.driver.manage.window.maximize end get '/closebrowser' do $browser.close end
Then add a second script request to send HTTP requests to the web service as follows:
require 'net/http' require 'uri' url = "http://localhost:9000/openbrowser" uri = URI.parse(url) Net::HTTP.get(uri) sleep(5) url = "http://localhost:9000/closebrowser" uri = URI.parse(url) Net::HTTP.get(uri)
That way, you can open the browser and use it with independent scripts if you want, and close it when you're done.
The bad news: you will probably need a lot of rework if you already have something.
The good news is: if you start from scratch, you can build it quickly. And, if you store your browser objects in an array, you can test against multiple browsers in parallel if you do such things.
Hope this helps (although he is 3 years late)
source share