Class: RAutomation::Adapter::Autoit::Window
- Inherits:
-
Object
- Object
- RAutomation::Adapter::Autoit::Window
show all
- Includes:
- WaitHelper
- Defined in:
- lib/rautomation/adapter/autoit/window.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(locators) ⇒ Window
Note:
this method is not meant to be accessed directly, but only through Window#initialize!
Creates the window object.
47
48
49
50
51
52
53
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 47
def initialize(locators)
@hwnd = locators[:hwnd]
@locator_index = locators.delete(:index) if locators[:index] && locators.size == 1
@locator_pid = locators.delete(:pid).to_i if locators[:pid]
@locator_text = locators.delete(:text)
(locators)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args)
Redirects all method calls not part of the public API to the AutoIt directly.
173
174
175
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 173
def method_missing(name, *args)
@@autoit.send(name, *args)
end
|
Instance Attribute Details
#locators
28
29
30
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 28
def locators
@locators
end
|
Instance Method Details
#activate
89
90
91
92
93
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 89
def activate
@@autoit.WinWait(locator_hwnd, "", 1)
@@autoit.WinActivate(locator_hwnd)
sleep 1
end
|
#active? ⇒ Boolean
96
97
98
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 96
def active?
@@autoit.WinActive(locator_hwnd) == 1
end
|
159
160
161
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 159
def button(locator)
Button.new(self, locator)
end
|
#close
152
153
154
155
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 152
def close
@@autoit.WinClose(locator_hwnd)
@@autoit.WinKill(locator_hwnd)
end
|
#exists? ⇒ Boolean
106
107
108
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 106
def exists?
@@autoit.WinExists(locator_hwnd) == 1
end
|
#hwnd
Note:
Searches only for visible windows.
Retrieves handle of the window.
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 58
def hwnd
@hwnd ||= begin
locators = @autoit_locators
if @locator_index || @locator_pid
locators = "[regexptitle:]" end
windows = @@autoit.WinList(locators, @locator_text).pop.compact.
map {|handle| self.class.new(:hwnd => handle.hex)}
windows.delete_if {|window| !window.visible?}
if @locator_pid
window = windows.find {|win| win.pid == @locator_pid}
else
window = windows[@locator_index || 0]
end
window ? window.hwnd : nil
end
end
|
#maximize
116
117
118
119
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 116
def maximize
@@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_MAXIMIZE)
sleep 1
end
|
#minimize
122
123
124
125
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 122
def minimize
@@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_MINIMIZE)
sleep 1
end
|
#minimized? ⇒ Boolean
128
129
130
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 128
def minimized?
@@autoit.WinGetState(locator_hwnd) & 16 == 16
end
|
#pid
79
80
81
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 79
def pid
@@autoit.WinGetProcess(locator_hwnd).to_i
end
|
#restore
133
134
135
136
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 133
def restore
@@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_RESTORE)
sleep 1
end
|
#send_keys(keys)
143
144
145
146
147
148
149
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 143
def send_keys(keys)
wait_until do
activate
active?
end
@@autoit.Send(keys)
end
|
#text
101
102
103
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 101
def text
@@autoit.WinGetText(locator_hwnd)
end
|
#text_field(locator)
165
166
167
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 165
def text_field(locator)
TextField.new(self, locator)
end
|
#title
84
85
86
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 84
def title
@@autoit.WinGetTitle(locator_hwnd)
end
|
#visible? ⇒ Boolean
111
112
113
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 111
def visible?
@@autoit.WinGetState(locator_hwnd) & 2 == 2
end
|