Class: AePageObjects::MultipleWindows::CrossWindowLoaderStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/ae_page_objects/multiple_windows/cross_window_loader_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(window_list) ⇒ CrossWindowLoaderStrategy

Returns a new instance of CrossWindowLoaderStrategy.



7
8
9
10
11
12
# File 'lib/ae_page_objects/multiple_windows/cross_window_loader_strategy.rb', line 7

def initialize(window_list)
  @window_list     = window_list
  @original_window = window_list.current_window

  @current_window_loader = SingleWindow::SameWindowLoaderStrategy.new
end

Instance Method Details

#document_not_loaded_error_message(query) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/ae_page_objects/multiple_windows/cross_window_loader_strategy.rb', line 41

def document_not_loaded_error_message(query)
  all_windows = @window_list.opened.map do |window|
    name = window.current_document && window.current_document.to_s || "<none>"
    {:window_handle => window.handle, :document => name }
  end

  "Couldn't find document with type in #{query.permitted_types_dump} in any of the open windows: #{all_windows.inspect}"
end

#load_document_with_condition(condition) ⇒ Object



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
# File 'lib/ae_page_objects/multiple_windows/cross_window_loader_strategy.rb', line 14

def load_document_with_condition(condition)
  # Look in the current window first unless told not to
  unless condition.document_conditions[:ignore_current]
    @original_window.switch_to

    if document = @current_window_loader.load_document_with_condition(condition)
      return document
    end
  end

  # Loop through all the windows and attempt to instantiate the Document. Continue to loop around
  # until finding a Document that can be instantiated or timing out.
  @window_list.opened.each do |window|
    next if window == @original_window

    window.switch_to

    if document = @current_window_loader.load_document_with_condition(condition)
      return document
    end
  end

  @original_window.switch_to

  nil
end