Class: Vapir::IE::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/vapir-ie/ie-process.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process_id) ⇒ Process

takes a process id



33
34
35
# File 'lib/vapir-ie/ie-process.rb', line 33

def initialize process_id
  @process_id = process_id
end

Instance Attribute Details

#process_idObject (readonly)

Returns the value of attribute process_id.



36
37
38
# File 'lib/vapir-ie/ie-process.rb', line 36

def process_id
  @process_id
end

Class Method Details

.startObject

start a new IE process and return a new Vapir::IE::Process object representing it.



21
22
23
24
25
26
27
28
29
30
# File 'lib/vapir-ie/ie-process.rb', line 21

def self.start
  require 'win32/process'
  program_files = ENV['ProgramFiles'] || "c:\\Program Files"
  startup_command = "#{program_files}\\Internet Explorer\\iexplore.exe"
  startup_command << " -nomerge" if ::Vapir::IE.version_parts.first==8
  # maybe raise an error here if it's > 8, as not-yet-supported? who knows what incompatibilities the future will hold 
  process_info = ::Process.create('app_name' => "#{startup_command} about:blank")
  process_id = process_info.process_id
  new process_id
end

Instance Method Details

#browser_object(options = {}) ⇒ Object

returns the browser object corresponding to the process id



39
40
41
42
43
44
45
46
47
# File 'lib/vapir-ie/ie-process.rb', line 39

def browser_object(options={})
  options=handle_options(options, :timeout => 32)
  Vapir.require_winwindow
  ::Waiter.try_for(options[:timeout], :exception => RuntimeError.new("Could not find a browser for process #{self.inspect}")) do
    Vapir::IE.browser_objects.detect do |browser_object|
      @process_id == WinWindow.new(Vapir::IE.fix_win32ole_hwnd(browser_object.hwnd)).process_id
    end
  end
end