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(container, locators) ⇒ Window
Note:
this method is not meant to be accessed directly, but only through Window#initialize!
Creates the window object.
49
50
51
52
53
54
55
56
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 49
def initialize(container, locators)
@container = container
@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.
186
187
188
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 186
def method_missing(name, *args)
@@autoit.send(name, *args)
end
|
Instance Attribute Details
#locators
30
31
32
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 30
def locators
@locators
end
|
Instance Method Details
#activate
97
98
99
100
101
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 97
def activate
@@autoit.WinWait(locator_hwnd, "", 1)
@@autoit.WinActivate(locator_hwnd)
sleep 1
end
|
#active? ⇒ Boolean
104
105
106
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 104
def active?
@@autoit.WinActive(locator_hwnd) == 1
end
|
172
173
174
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 172
def button(locator={})
Button.new(self, locator)
end
|
#class_names
92
93
94
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 92
def class_names
@@autoit.WinGetClassList(locator_hwnd).split("\n").sort
end
|
#close
160
161
162
163
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 160
def close
@@autoit.WinClose(locator_hwnd)
@@autoit.WinKill(locator_hwnd)
end
|
#exists? ⇒ Boolean
114
115
116
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 114
def exists?
@@autoit.WinExists(locator_hwnd) == 1
end
|
#hwnd
Note:
Searches only for visible windows.
Retrieves handle of the window.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 61
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| RAutomation::Window.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
124
125
126
127
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 124
def maximize
@@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_MAXIMIZE)
sleep 1
end
|
#minimize
130
131
132
133
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 130
def minimize
@@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_MINIMIZE)
sleep 1
end
|
#minimized? ⇒ Boolean
136
137
138
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 136
def minimized?
@@autoit.WinGetState(locator_hwnd) & 16 == 16
end
|
#mouse
165
166
167
168
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 165
def mouse
@container.wait_until_present
Mouse.new(self)
end
|
#pid
82
83
84
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 82
def pid
@@autoit.WinGetProcess(locator_hwnd).to_i
end
|
#restore
141
142
143
144
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 141
def restore
@@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_RESTORE)
sleep 1
end
|
#send_keys(keys)
151
152
153
154
155
156
157
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 151
def send_keys(keys)
wait_until do
activate
active?
end
@@autoit.Send(keys[0])
end
|
#text
109
110
111
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 109
def text
@@autoit.WinGetText(locator_hwnd)
end
|
#text_field(locator = {})
178
179
180
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 178
def text_field(locator={})
TextField.new(self, locator)
end
|
#title
87
88
89
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 87
def title
@@autoit.WinGetTitle(locator_hwnd)
end
|
#visible? ⇒ Boolean
119
120
121
|
# File 'lib/rautomation/adapter/autoit/window.rb', line 119
def visible?
@@autoit.WinGetState(locator_hwnd) & 2 == 2
end
|