class RAutomation::Adapter::MsUia::Window

Attributes

locators[R]

Locators of the window.

Public Class Methods

new(container, locators) click to toggle source
Possible locators are :title, :text, :hwnd, :pid, :class and :index.

todo - update list of valid locators for UIA

Creates the window object.
@note this method is not meant to be accessed directly, but only through {RAutomation::Window#initialize}!
@param [Hash] locators for searching the window.
@option locators [String, Regexp] :title Title of the window
@option locators [String, Regexp] :text Visible text of the window
@option locators [String, Regexp] :class Internal class name of the window
@option locators [String, Integer] :hwnd Window handle in decimal format
@option locators [String, Integer] :pid Window process ID (PID)
@option locators [String, Integer] :index 0-based index to specify n-th window if all other criteria match
  all other criteria match
@see RAutomation::Window#initialize
# File lib/rautomation/adapter/ms_uia/window.rb, line 29
def initialize(container, locators)
  @container = container
  extract(locators)
end

Public Instance Methods

activate() click to toggle source

@see RAutomation::Window#activate

# 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?() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#active?
# File lib/rautomation/adapter/ms_uia/window.rb, line 71
def active?
  exists? && Functions.foreground_window == hwnd
end
bounding_rectangle() click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 195
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) click to toggle source

@see Button#initialize @see RAutomation::Window#button

# File lib/rautomation/adapter/ms_uia/window.rb, line 159
def button(locator)
  Button.new(self, locator)
end
checkbox(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 242
def checkbox(locator)
  @container.wait_until_present
  Checkbox.new(self, locator)
end
child(locators) click to toggle source

todo - replace with UIA version

Creates the child window object.
@note This is an Win32 adapter specific method, not part of the public API
@example
  RAutomation::Window.new(:title => /Windows Internet Explorer/i).
    child(:title => /some popup/)
@param (see Window#initialize)
@return [RAutomation::Window] child window, popup or regular window.
# File lib/rautomation/adapter/ms_uia/window.rb, line 265
def child(locators)
  RAutomation::Window.new Functions.child_window_locators(hwnd, locators)
end
class_names() click to toggle source

@see RAutomation::Window#class_names

# 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() click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 208
def click_mouse()
  UiaDll::click_mouse
end
close() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#close
# File lib/rautomation/adapter/ms_uia/window.rb, line 153
def close
  Functions.close_window(hwnd)
end
control(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 217
def control(locator)
  @container.wait_until_present
  Control.new(self, locator)
end
controls(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 222
def controls(locator)
  @container.wait_until_present
  Controls.new(self, locator)
end
exists?() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#exists?
# File lib/rautomation/adapter/ms_uia/window.rb, line 83
def exists?
  hwnd && Functions.window_exists(hwnd)
end
hwnd() click to toggle source

todo - replace with UIA version

Retrieves handle of the window.
@note Searches only for visible windows.
@see RAutomation::Window#hwnd
# File lib/rautomation/adapter/ms_uia/window.rb, line 38
def hwnd
  @hwnd ||= Functions.window_hwnd(@locators)
end
label(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 212
def label(locator)
  @container.wait_until_present
  Label.new(self, locator)
end
list_box(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 227
def list_box(locator)
  @container.wait_until_present
  ListBox.new(self, locator)
end
list_item(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 232
def list_item(locator)
  @container.wait_until_present
  ListItem.new(self, locator)
end
maximize() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#maximize
# File lib/rautomation/adapter/ms_uia/window.rb, line 95
def maximize
  Functions.show_window(hwnd, Constants::SW_MAXIMIZE)
  sleep 1
end
menu(locator) click to toggle source

Returns a {Menu} object use to build a path to a menu item to open. @param [Hash] locator for the {Menu}. Only :text is allowed.

method_missing(name, *args) click to toggle source

Redirects all method calls not part of the public API to the {Functions} directly. @see RAutomation::Window#method_missing

Calls superclass method
# File lib/rautomation/adapter/ms_uia/window.rb, line 191
def method_missing(name, *args)
  Functions.respond_to?(name) ? Functions.send(name, *args) : super
end
minimize() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#minimize
# File lib/rautomation/adapter/ms_uia/window.rb, line 102
def minimize
  Functions.show_window(hwnd, Constants::SW_MINIMIZE)
  sleep 1
end
minimized?() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#minimized?
# File lib/rautomation/adapter/ms_uia/window.rb, line 109
def minimized?
  Functions.minimized(hwnd)
end
move_mouse(x, y) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 204
def move_mouse(x, y)
  UiaDll::move_mouse(x, y)
end
pid() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#pid
# File lib/rautomation/adapter/ms_uia/window.rb, line 44
def pid
  Functions.window_pid(hwnd)
end
radio(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 247
def radio(locator)
  @container.wait_until_present
  Radio.new(self, locator)
end
restore() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#restore
# 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) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 237
def select_list(locator)
  @container.wait_until_present
  SelectList.new(self, locator)
end
send_keys(args) click to toggle source

Activates the window and sends keys to it.

@example

RAutomation::Window.new(:title => //).send_keys "hello!"
RAutomation::Window.new(:title => //).send_keys [:control, "a"], "world!"

Refer to {Keys::KEYS} for all the special keycodes. @see RAutomation::Window#send_keys

# 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
spinner(locator) click to toggle source

@see Spinner#initialize

# File lib/rautomation/adapter/ms_uia/window.rb, line 173
def spinner(locator)
  Spinner.new(self, locator)
end
tab_control(locator) click to toggle source

@see TabControl#initialize

# File lib/rautomation/adapter/ms_uia/window.rb, line 168
def tab_control(locator)
  TabControl.new(self, locator)
end
table(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 252
def table(locator)
  @container.wait_until_present
  Table.new(self, locator)
end
text() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#text
# File lib/rautomation/adapter/ms_uia/window.rb, line 77
def text
  Functions.window_text(hwnd)
end
text_field(locator) click to toggle source

@see TextField#initialize @see RAutomation::Window#text_field

# File lib/rautomation/adapter/ms_uia/window.rb, line 179
def text_field(locator)
  TextField.new(self, locator)
end
title() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#title
# File lib/rautomation/adapter/ms_uia/window.rb, line 50
def title
  Functions.window_title(hwnd)
end
value_control(locator) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 163
def value_control(locator)
  ValueControl.new(self, locator)
end
visible?() click to toggle source

todo - replace with UIA version

@see RAutomation::Window#visible?
# File lib/rautomation/adapter/ms_uia/window.rb, line 89
def visible?
  Functions.window_visible(hwnd)
end

Private Instance Methods

press_key(key) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 271
def press_key key
  Functions.send_key(key, 0, 0, nil)
  key
end
release_key(key) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 276
def release_key key
  Functions.send_key(key, 0, Constants::KEYEVENTF_KEYUP, nil)
  key
end
send_key(key) click to toggle source
# File lib/rautomation/adapter/ms_uia/window.rb, line 281
def send_key key
  press_key key
  release_key key
  key
end