Class: Watir::Window

Inherits:
Object show all
Includes:
ElementExtensions
Defined in:
lib/watir-classic/window.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ElementExtensions

#wait_until_present, #wait_while_present, #when_present

Constructor Details

#initialize(main_browser, locators, browser = nil, &blk) ⇒ Window

Returns a new instance of Window.



19
20
21
22
23
24
25
26
27
28
# File 'lib/watir-classic/window.rb', line 19

def initialize(main_browser, locators, browser=nil, &blk)
  valid_locators = [:title, :url, :hwnd, :index]
  locators.each_pair do |k, v| 
    raise ArgumentError, "Valid locators are #{valid_locators.join(", ")}" unless valid_locators.include?(k)
  end
  @main_browser = main_browser
  self.class.__main_ie = main_browser.ie
  @locators = locators
  @browser = browser
end

Class Attribute Details

.__main_ieObject

Returns the value of attribute __main_ie.



6
7
8
# File 'lib/watir-classic/window.rb', line 6

def __main_ie
  @__main_ie
end

Class Method Details

.wrap(*meths) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/watir-classic/window.rb', line 8

def wrap *meths
  meths.each do |meth|
    define_method meth do
      result = nil
      use {result = browser.send(meth)}
      result
    end
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



56
57
58
# File 'lib/watir-classic/window.rb', line 56

def ==(other)
  browser.hwnd == other.hwnd && browser.html == other.browser.html
end

#browserObject



32
33
34
35
36
# File 'lib/watir-classic/window.rb', line 32

def browser
  @browser ||= begin
                IE.find(@locators.keys.first, @locators.values.first)
               end
end

#current?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/watir-classic/window.rb', line 52

def current?
  @main_browser.hwnd == browser.hwnd && @main_browser.html == browser.html
end

#present?Boolean

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/watir-classic/window.rb', line 62

def present?
  @browser = nil
  browser && browser.exists?
end

#use(&blk) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/watir-classic/window.rb', line 38

def use(&blk)
  @main_browser.ie = browser.ie
  if blk
    begin
      blk.call
    ensure
      @main_browser.ie = self.class.__main_ie
      # try to find some existing IE when needed
      @main_browser.ie = IE._find(:index, 0) unless @main_browser.exists?
    end
  end
  self
end