Class: Watir::WindowCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Waitable
Defined in:
lib/watir/window_collection.rb

Instance Method Summary collapse

Methods included from Waitable

#wait_until, #wait_while

Constructor Details

#initialize(browser, selector = {}) ⇒ WindowCollection

Returns a new instance of WindowCollection.



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

def initialize(browser, selector = {})
  types = %i[title url element]
  unless selector.keys.all? { |k| types.include? k }
    raise ArgumentError, "invalid window selector: #{selector.inspect}"
  end

  @browser = browser
  @selector = selector
end

Instance Method Details

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



40
41
42
# File 'lib/watir/window_collection.rb', line 40

def ==(other)
  window_list == other.send(:window_list)
end

#[]Object Also known as: first, last, to_a

Raises:

  • (NoMethodError)


33
34
35
# File 'lib/watir/window_collection.rb', line 33

def [](*)
  raise NoMethodError, 'indexing not reliable on WindowCollection'
end

#each {|| ... } ⇒ Object

Yields each window in collection.

Yield Parameters:



24
25
26
27
# File 'lib/watir/window_collection.rb', line 24

def each(&blk)
  reset!
  window_list.each(&blk)
end

#reset!Object



54
55
56
# File 'lib/watir/window_collection.rb', line 54

def reset!
  @window_list = nil
end

#restore!Object



45
46
47
48
49
50
51
52
# File 'lib/watir/window_collection.rb', line 45

def restore!
  return if @browser.closed?

  window_list.reject { |win| win.handle == @browser.original_window.handle }.each(&:close)
  @browser.original_window.use
rescue StandardError
  @browser.close
end