Class: ATT::Popup

Inherits:
Object
  • Object
show all
Defined in:
lib/popup/popup.rb,
lib/popup/version.rb

Direct Known Subclasses

AlertPopup, ConfirmPopup, FilePopup

Constant Summary collapse

VERSION =
'0.0.9'
@@windows =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ Popup

:nodoc:



31
32
33
# File 'lib/popup/popup.rb', line 31

def initialize(window) # :nodoc: 
  @window = window
end

Instance Attribute Details

#windowObject (readonly)

Returns the value of attribute window.



35
36
37
# File 'lib/popup/popup.rb', line 35

def window
  @window
end

Class Method Details

.collect_windowsObject

:nodoc:



74
75
76
# File 'lib/popup/popup.rb', line 74

def self.collect_windows
  RAutomation::Window.windows.collect { |w| w.hwnd }.find_all { |hwnd| PopupWindow.is_popup?(hwnd) }
end

.findObject

@Return: Popup object that is found.

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/popup/popup.rb', line 41

def self.find
  raise NotRecordError,"please call record() before use me." unless @@windows
  windows_new = []
  begin
    RAutomation::WaitHelper.wait_until(Config::timeout) do
      sleep 0.5
      windows_now = collect_windows
      windows_new = windows_now - @@windows
      windows_new.size > 0 && windows_new.reject! { |h| RAutomation::Window.new(:hwnd=>h).text.chomp == "" }
      windows_new.size > 0
    end
  rescue RAutomation::WaitHelper::TimeoutError
    raise WindowNotFoundError,"can not found new window in time #{Config::timeout} seconds"
  end
  #~ puts "new = " + (windows_new.collect do |hwnd| RAutomation::Window.new(:hwnd=>hwnd,:adapter=>"autoit").text end).join(",")
  # TODO: next week we should guess one window, but not raise a big exception
  raise MutliWindowsMatchError,"more than one windows opened between record() and find()" if windows_new.size > 1
  window = RAutomation::Window.new(:hwnd => windows_new[0] ) if windows_new.size == 1
  return self.new(window)
end

.find_allObject



62
63
64
65
66
# File 'lib/popup/popup.rb', line 62

def self.find_all
  windows_now = collect_windows
  windows_new = windows_now - @@windows
  windows_new.collect { |hwnd| self.new( RAutomation::Window.new(:hwnd => hwnd ) ) }
end

.find_whenObject

Find a new popup when execute the block you have given.



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/popup/popup.rb', line 80

def self.find_when # :yields: 
  record
  begin
    thread = Thread.new {
      yield
    }
    find
  ensure
    thread.kill
  end
end

.recordObject

Record all the windows availed now. @return: Array that contains all the hwnd of visble windows.



70
71
72
# File 'lib/popup/popup.rb', line 70

def self.record
  @@windows = collect_windows
end

Instance Method Details

#assert_exist?Boolean Also known as: exist?

false if not

Returns:

  • (Boolean)


99
100
101
# File 'lib/popup/popup.rb', line 99

def assert_exist?
  @window.exist?
end

#closeObject

Close the window It behave as click x button at the right postion above.



94
95
96
# File 'lib/popup/popup.rb', line 94

def close
  @window.close
end