Class: RAutomation::Adapter::MsUia::Window
- Inherits:
-
Object
- Object
- RAutomation::Adapter::MsUia::Window
- Includes:
- Locators, WaitHelper
- Defined in:
- lib/rautomation/adapter/ms_uia/window.rb
Instance Attribute Summary collapse
-
#locators
readonly
Locators of the window.
Instance Method Summary collapse
- #activate
-
#active? ⇒ Boolean
todo - replace with UIA version.
- #bounding_rectangle
- #button(locator)
- #checkbox(locator)
-
#child(locators) ⇒ RAutomation::Window
todo - replace with UIA version Creates the child window object.
- #class_names
- #click_mouse
-
#close
todo - replace with UIA version.
- #control(locator)
- #controls(locator)
- #count_children(element)
-
#exists? ⇒ Boolean
todo - replace with UIA version.
-
#hwnd
todo - replace with UIA version Retrieves handle of the window.
-
#initialize(container, locators) ⇒ Window
constructor
Possible locators are :title, :text, :hwnd, :pid, :class and :index.
- #label(locator)
- #list_box(locator)
- #list_item(locator)
-
#maximize
todo - replace with UIA version.
-
#menu(locator)
Returns a Menu object use to build a path to a menu item to open.
-
#method_missing(name, *args)
Redirects all method calls not part of the public API to the Functions directly.
-
#minimize
todo - replace with UIA version.
-
#minimized? ⇒ Boolean
todo - replace with UIA version.
- #move_mouse(x, y)
-
#pid
todo - replace with UIA version.
- #radio(locator)
-
#restore
todo - replace with UIA version.
- #select_list(locator)
-
#send_keys(args)
Activates the window and sends keys to it.
- #table(locator)
-
#text
todo - replace with UIA version.
- #text_field(locator)
-
#title
todo - replace with UIA version.
- #value_control(locator)
-
#visible? ⇒ Boolean
todo - replace with UIA version.
Constructor Details
#initialize(container, locators) ⇒ Window
this method is not meant to be accessed directly, but only through Window#initialize!
Possible locators are :title, :text, :hwnd, :pid, :class and :index. todo - update list of valid locators for UIA Creates the window object.
29 30 31 32 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 29 def initialize(container, locators) @container = container extract(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.
181 182 183 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 181 def method_missing(name, *args) Functions.respond_to?(name) ? Functions.send(name, *args) : super end |
Instance Attribute Details
#locators (readonly)
Locators of the window.
14 15 16 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 14 def locators @locators end |
Instance Method Details
#activate
61 62 63 64 65 66 67 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 61 def activate return if !exists? || active? restore if minimized? Functions.activate_window(hwnd) restore if minimized? sleep 1 end |
#active? ⇒ Boolean
todo - replace with UIA version
71 72 73 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 71 def active? exists? && Functions.foreground_window == hwnd end |
#bounding_rectangle
189 190 191 192 193 194 195 196 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 189 def bounding_rectangle window = UiaDll::element_from_handle(hwnd) boundary = FFI::MemoryPointer.new :long, 4 UiaDll::bounding_rectangle(window, boundary) boundary.read_array_of_long(4) end |
#button(locator)
159 160 161 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 159 def (locator) Button.new(self, locator) end |
#checkbox(locator)
236 237 238 239 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 236 def checkbox(locator) @container.wait_until_present Checkbox.new(self, locator) end |
#child(locators) ⇒ RAutomation::Window
This is an Win32 adapter specific method, not part of the public API
todo - replace with UIA version Creates the child window object.
259 260 261 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 259 def child(locators) RAutomation::Window.new Functions.child_window_locators(hwnd, locators) end |
#class_names
55 56 57 58 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 55 def class_names classes = UiaDll::children_class_names(UiaDll::SearchCriteria.from_locator(hwnd, :hwnd => hwnd)) classes.delete_if(&:empty?).sort end |
#click_mouse
202 203 204 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 202 def click_mouse() UiaDll::click_mouse end |
#close
todo - replace with UIA version
153 154 155 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 153 def close Functions.close_window(hwnd) end |
#control(locator)
211 212 213 214 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 211 def control(locator) @container.wait_until_present Control.new(self, locator) end |
#controls(locator)
216 217 218 219 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 216 def controls(locator) @container.wait_until_present Controls.new(self, locator) end |
#count_children(element)
185 186 187 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 185 def count_children(element) UiaDll::find_children(element, nil) end |
#exists? ⇒ Boolean
todo - replace with UIA version
83 84 85 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 83 def exists? hwnd && Functions.window_exists(hwnd) end |
#hwnd
Searches only for visible windows.
todo - replace with UIA version Retrieves handle of the window.
38 39 40 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 38 def hwnd @hwnd ||= Functions.window_hwnd(@locators) end |
#label(locator)
206 207 208 209 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 206 def label(locator) @container.wait_until_present Label.new(self, locator) end |
#list_box(locator)
221 222 223 224 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 221 def list_box(locator) @container.wait_until_present ListBox.new(self, locator) end |
#list_item(locator)
226 227 228 229 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 226 def list_item(locator) @container.wait_until_present ListItem.new(self, locator) end |
#maximize
todo - replace with UIA version
95 96 97 98 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 95 def maximize Functions.show_window(hwnd, Constants::SW_MAXIMIZE) sleep 1 end |
#menu(locator)
Returns a Menu object use to build a path to a menu item to open.
175 176 177 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 175 def (locator) Menu.new(self, locator) end |
#minimize
todo - replace with UIA version
102 103 104 105 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 102 def minimize Functions.show_window(hwnd, Constants::SW_MINIMIZE) sleep 1 end |
#minimized? ⇒ Boolean
todo - replace with UIA version
109 110 111 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 109 def minimized? Functions.minimized(hwnd) end |
#move_mouse(x, y)
198 199 200 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 198 def move_mouse(x, y) UiaDll::move_mouse(x, y) end |
#pid
todo - replace with UIA version
44 45 46 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 44 def pid Functions.window_pid(hwnd) end |
#radio(locator)
241 242 243 244 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 241 def radio(locator) @container.wait_until_present Radio.new(self, locator) end |
#restore
todo - replace with UIA version
115 116 117 118 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 115 def restore Functions.show_window(hwnd, Constants::SW_RESTORE) sleep 1 end |
#select_list(locator)
231 232 233 234 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 231 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.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 127 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)
246 247 248 249 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 246 def table(locator) @container.wait_until_present Table.new(self, locator) end |
#text
todo - replace with UIA version
77 78 79 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 77 def text Functions.window_text(hwnd) end |
#text_field(locator)
169 170 171 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 169 def text_field(locator) TextField.new(self, locator) end |
#title
todo - replace with UIA version
50 51 52 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 50 def title Functions.window_title(hwnd) end |
#value_control(locator)
163 164 165 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 163 def value_control(locator) ValueControl.new(self, locator) end |
#visible? ⇒ Boolean
todo - replace with UIA version
89 90 91 |
# File 'lib/rautomation/adapter/ms_uia/window.rb', line 89 def visible? Functions.window_visible(hwnd) end |