Class: Watir::Browser::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-classic/browser_process.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process_id) ⇒ Process

Returns a new instance of Process.



16
17
18
# File 'lib/watir-classic/browser_process.rb', line 16

def initialize process_id
  @process_id = process_id
end

Instance Attribute Details

#process_idObject (readonly)

Returns the value of attribute process_id.



20
21
22
# File 'lib/watir-classic/browser_process.rb', line 20

def process_id
  @process_id
end

Class Method Details

.process_id_from_hwnd(hwnd) ⇒ Object

Returns the process id for the specifed hWnd.



39
40
41
42
43
44
# File 'lib/watir-classic/browser_process.rb', line 39

def self.process_id_from_hwnd hwnd
  pid_info = ' ' * 32
  Win32API.new('user32', 'GetWindowThreadProcessId', 'ip', 'i').
  call(hwnd, pid_info)
  process_id =  pid_info.unpack("L")[0]
end

.startObject



6
7
8
9
10
11
12
13
14
# File 'lib/watir-classic/browser_process.rb', line 6

def self.start
  program_files = ENV['ProgramFiles'] || "c:\\Program Files"
  startup_command = "#{program_files}\\Internet Explorer\\iexplore.exe"
  startup_command << " -nomerge" if Browser.version_parts.first.to_i == 8
  startup_command << " -noframemerging" if Browser.version_parts.first.to_i >= 9
  process_info = ::Process.create('app_name' => "#{startup_command} about:blank")
  process_id = process_info.process_id
  new process_id
end

Instance Method Details

#windowObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/watir-classic/browser_process.rb', line 22

def window
  Wait.until do
    found_window = nil
    Browser.each do | ie |
      window = ie.ie
      hwnd = ie.hwnd
      process_id = Process.process_id_from_hwnd hwnd        
      if process_id == @process_id
        found_window = window
        break
      end
    end
    found_window
  end
end