Class: Selenium::SeleniumDriverManager

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium_rails/selenium_driver_manager.rb

Constant Summary collapse

@@selenium_drivers =

supports multiple drivers, keyed by options

{}

Class Method Summary collapse

Class Method Details

.driver(driver_options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/selenium_rails/selenium_driver_manager.rb', line 6

def self.driver(driver_options = {})
  browser_start_command = ENV['BROWSER_START_COMMAND'] ? ENV['BROWSER_START_COMMAND'] : '*firefox'
  opts = {:server_host => 'localhost', :server_port => '4444', :browser_start_command => browser_start_command, 
          :browser_url => 'http://localhost:3001', :timeout => 10000}.merge(driver_options)
  key = opts.map {|key, value| key.to_s + '=>' + value.to_s}.sort.join(',')
  unless @@selenium_drivers[key]
    @@selenium_drivers[key] = Selenium::SeleniumDriver.new(opts[:server_host], opts[:server_port], opts[:browser_start_command],
                                 opts[:browser_url], opts[:timeout])
    @@selenium_drivers[key].start
  end
  @@selenium_drivers[key]
end

.stop_driversObject



19
20
21
22
23
24
25
26
# File 'lib/selenium_rails/selenium_driver_manager.rb', line 19

def self.stop_drivers
  # Doesn't actually do anything if called from a different process than the one where the
  # drivers were started, but they will die anyway when the server is killed.
  @@selenium_drivers.each do |key, selenium_driver|
    selenium_driver.stop
    @@selenium_drivers.delete(key)
  end
end