Class: RAutomation::Adapter::Win32::Window
- Inherits:
-
Object
- Object
- RAutomation::Adapter::Win32::Window
show all
- Includes:
- WaitHelper
- Defined in:
- lib/rautomation/adapter/win_32/window.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(container, locators) ⇒ Window
Note:
this method is not meant to be accessed directly, but only through Window#initialize!
Creates the window object.
39
40
41
42
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 39
def initialize(container, locators)
@container = container
(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 Functions directly.
199
200
201
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 199
def method_missing(name, *args)
Functions.respond_to?(name) ? Functions.send(name, *args) : super
end
|
Instance Attribute Details
#container
Returns the value of attribute container.
21
22
23
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 21
def container
@container
end
|
#locators
24
25
26
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 24
def locators
@locators
end
|
Class Method Details
.oleacc_module_handle
12
13
14
15
16
17
18
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 12
def oleacc_module_handle
@oleacc_module_handle ||= begin
oleacc = Functions.load_library "oleacc.dll"
Functions.co_initialize nil
oleacc
end
end
|
Instance Method Details
#activate
71
72
73
74
75
76
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 71
def activate
return if !exists? || active?
restore if minimized?
Functions.activate_window(hwnd)
sleep 0.1
end
|
#active? ⇒ Boolean
79
80
81
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 79
def active?
exists? && Functions.foreground_window == hwnd
end
|
187
188
189
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 187
def button(locator)
Button.new(self, locator)
end
|
#checkbox(locator = {})
224
225
226
227
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 224
def checkbox(locator={})
@container.wait_until_present
Checkbox.new(self, locator)
end
|
Note:
This is an Win32 adapter specific method, not part of the public API
Creates the child window object.
246
247
248
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 246
def child(locators)
RAutomation::Window.new Functions.child_window_locators(hwnd, locators)
end
|
#class_names
62
63
64
65
66
67
68
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 62
def class_names
classes = []
controls.each do |control|
classes << control.class_name
end
classes.sort
end
|
#close
176
177
178
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 176
def close
Functions.close_window(hwnd)
end
|
#control(locator = {})
209
210
211
212
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 209
def control(locator={})
@container.wait_until_present
Control.new(self, locator)
end
|
#dimensions ⇒ Hash
Returns Hash[:left, :top, :width, :height] with window coordinates.
137
138
139
140
141
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 137
def dimensions
@container.wait_until_present
left, top, right, bottom = Functions.window_rect(hwnd)
{:left => left, :top => top, :width => right - left, :height => bottom - top}
end
|
#exists? ⇒ Boolean
89
90
91
92
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 89
def exists?
result = hwnd && Functions.window_exists(hwnd)
!!result
end
|
#hwnd
Note:
Searches only for visible windows.
Retrieves handle of the window.
47
48
49
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 47
def hwnd
@hwnd ||= Functions.window_hwnd(@locators)
end
|
#label(locator = {})
Win32 adapter specific API methods
204
205
206
207
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 204
def label(locator={})
@container.wait_until_present
Label.new(self, locator)
end
|
#list_box(locator = {})
214
215
216
217
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 214
def list_box(locator={})
@container.wait_until_present
ListBox.new(self, locator)
end
|
#maximize
100
101
102
103
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 100
def maximize
Functions.show_window(hwnd, Constants::SW_MAXIMIZE)
sleep 1
end
|
#minimize
106
107
108
109
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 106
def minimize
Functions.show_window(hwnd, Constants::SW_MINIMIZE)
sleep 1
end
|
#minimized? ⇒ Boolean
112
113
114
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 112
def minimized?
Functions.minimized(hwnd)
end
|
#mouse
180
181
182
183
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 180
def mouse
@container.wait_until_present
Mouse.new(self)
end
|
#move(coords = {})
Note:
All coordinates are optional and if not specified current coordinates will be used
Moves/resizes the window.
129
130
131
132
133
134
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 129
def move(coords={})
@container.wait_until_present
rect = dimensions.merge(coords)
Functions.move_window(hwnd, rect[:left], rect[:top], rect[:width], rect[:height])
sleep 1
end
|
#pid
52
53
54
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 52
def pid
Functions.window_pid(hwnd)
end
|
#radio(locator = {})
229
230
231
232
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 229
def radio(locator={})
@container.wait_until_present
Radio.new(self, locator)
end
|
#restore
117
118
119
120
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 117
def restore
Functions.show_window(hwnd, Constants::SW_RESTORE)
sleep 1
end
|
#select_list(locator = {})
219
220
221
222
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 219
def select_list(locator={})
@container.wait_until_present
SelectList.new(self, locator)
end
|
#send_keys(args)
Activates the window and sends keys to it.
Refer to Keys::KEYS for all the special keycodes.
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 151
def send_keys(args)
Keys.encode(args).each do |arg|
wait_until do
activate
active?
end
if arg.is_a?(Array)
arg.reduce([]) do |pressed_keys, k|
if k == Keys[:null]
pressed_keys.each {|pressed_key| release_key pressed_key}
pressed_keys = []
else
pressed_keys << press_key(k)
end
pressed_keys
end
else
send_key arg
end
end
sleep 1
end
|
#table(locator = {})
234
235
236
237
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 234
def table(locator={})
@container.wait_until_present
Table.new(self, locator)
end
|
#text
84
85
86
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 84
def text
Functions.window_text(hwnd)
end
|
#text_field(locator)
193
194
195
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 193
def text_field(locator)
TextField.new(self, locator)
end
|
#title
57
58
59
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 57
def title
Functions.window_title(hwnd)
end
|
#visible? ⇒ Boolean
95
96
97
|
# File 'lib/rautomation/adapter/win_32/window.rb', line 95
def visible?
Functions.window_visible(hwnd)
end
|