Class: FireWatir::Firefox

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

Constant Summary collapse

@@firefox_started =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Firefox

Returns a new instance of Firefox.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/watir_extensions.rb', line 7

def initialize(options = {})
  if(options.kind_of?(Integer))
    options = {:waitTime => options}
  end

  if(options[:profile])
    profile_opt = "-no-remote -P #{options[:profile]}"
  else
    profile_opt = ""
  end

  waitTime = options[:waitTime] || 2

  case RUBY_PLATFORM
  when /mswin/
    # Get the path to Firefox.exe using Registry.
    require 'win32/registry.rb'
    path_to_bin = ""
    Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
      keys = reg.keys
      reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
      reg1.each do |subkey, type, data|
        if(subkey =~ /pathtoexe/i)
          path_to_bin = data
        end
      end
    end

  when /linux/i
    path_to_bin = `which firefox`.strip
  when /darwin/i
    path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
  when /java/
    raise "Not implemented: Create a browser finder in JRuby"
  end

  @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")} unless @@firefox_started

  sleep waitTime
  begin
    set_defaults()
  rescue Watir::Exception::UnableToStartJSShException
    if !@t # no new thread starting browser, try again
      puts "Firefox with JSSH not detected after you indicated @@firefox_started"
      @t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
      sleep waitTime
      set_defaults
    end
  end
  get_window_number()
  set_browser_document()
end

Class Method Details

.firefox_started=(value) ⇒ Object



60
61
62
# File 'lib/watir_extensions.rb', line 60

def self.firefox_started=(value)
  @@firefox_started = value
end