class RAutomation::Adapter::Win32::Window
Attributes
Locators
of the window.
Public Class Methods
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/win_32/window.rb, line 39 def initialize(container, locators) @container = container extract(locators) end
# 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
Public Instance Methods
@see RAutomation::Window#activate
# 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
@see RAutomation::Window#active?
# File lib/rautomation/adapter/win_32/window.rb, line 79 def active? exists? && Functions.foreground_window == hwnd end
# File lib/rautomation/adapter/win_32/window.rb, line 231 def checkbox(locator={}) @container.wait_until_present Checkbox.new(self, locator) end
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/win_32/window.rb, line 253 def child(locators) RAutomation::Window.new Functions.child_window_locators(hwnd, locators) end
@see RAutomation::Window#class_names
# 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
@see RAutomation::Window#close
# File lib/rautomation/adapter/win_32/window.rb, line 176 def close Functions.close_window(hwnd) end
# File lib/rautomation/adapter/win_32/window.rb, line 216 def control(locator={}) @container.wait_until_present Control.new(self, locator) end
@return [Hash] Hash[:left, :top, :width, :height] with window coordinates
# 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
@see RAutomation::Window#exists?
# File lib/rautomation/adapter/win_32/window.rb, line 89 def exists? result = hwnd && Functions.window_exists(hwnd) !!result end
Retrieves handle of the window. @note Searches only for visible windows. @see RAutomation::Window#hwnd
# File lib/rautomation/adapter/win_32/window.rb, line 47 def hwnd @hwnd ||= Functions.window_hwnd(@locators) end
Win32
adapter specific API methods
# File lib/rautomation/adapter/win_32/window.rb, line 206 def label(locator={}) @container.wait_until_present Label.new(self, locator) end
# File lib/rautomation/adapter/win_32/window.rb, line 221 def list_box(locator={}) @container.wait_until_present ListBox.new(self, locator) end
@see RAutomation::Window#maximize
# File lib/rautomation/adapter/win_32/window.rb, line 100 def maximize Functions.show_window(hwnd, Constants::SW_MAXIMIZE) sleep 1 end
Redirects all method calls not part of the public API to the {Functions} directly. @see RAutomation::Window#method_missing
# File lib/rautomation/adapter/win_32/window.rb, line 201 def method_missing(name, *args) Functions.respond_to?(name) ? Functions.send(name, *args) : super end
@see RAutomation::Window#minimize
# File lib/rautomation/adapter/win_32/window.rb, line 106 def minimize Functions.show_window(hwnd, Constants::SW_MINIMIZE) sleep 1 end
@see RAutomation::Window#minimized?
# File lib/rautomation/adapter/win_32/window.rb, line 112 def minimized? Functions.minimized(hwnd) end
Retrieves the {Mouse} object for automating mouse movements and clicks @raise [UnknownWindowException] if the window doesn't exist.
# File lib/rautomation/adapter/win_32/window.rb, line 182 def mouse @container.wait_until_present Mouse.new(self) end
Moves/resizes the window. @note All coordinates are optional and if not specified current coordinates will be used @param [Hash] coords for specifying the coordinates. @option coords [Integer] :left Window
coordinate from the left side of screen @option coords [Integer] :top Window
coordinate from the top of the screen @option coords [Integer] :width Width of window @option coords [Integer] :height Height of window
# 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
# File lib/rautomation/adapter/win_32/window.rb, line 211 def password_field(locator) @container.wait_until_present PasswordField.new(self, locator) end
# File lib/rautomation/adapter/win_32/window.rb, line 52 def pid Functions.window_pid(hwnd) end
# File lib/rautomation/adapter/win_32/window.rb, line 236 def radio(locator={}) @container.wait_until_present Radio.new(self, locator) end
@see RAutomation::Window#restore
# File lib/rautomation/adapter/win_32/window.rb, line 117 def restore Functions.show_window(hwnd, Constants::SW_RESTORE) sleep 1 end
# File lib/rautomation/adapter/win_32/window.rb, line 226 def select_list(locator={}) @container.wait_until_present SelectList.new(self, locator) end
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/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
# File lib/rautomation/adapter/win_32/window.rb, line 241 def table(locator={}) @container.wait_until_present Table.new(self, locator) end
# File lib/rautomation/adapter/win_32/window.rb, line 84 def text Functions.window_text(hwnd) end
@see TextField#initialize @see RAutomation::Window#text_field
# File lib/rautomation/adapter/win_32/window.rb, line 195 def text_field(locator) TextField.new(self, locator) end
@see RAutomation::Window#title
# File lib/rautomation/adapter/win_32/window.rb, line 57 def title Functions.window_title(hwnd) end
@see RAutomation::Window#visible?
# File lib/rautomation/adapter/win_32/window.rb, line 95 def visible? Functions.window_visible(hwnd) end
Private Instance Methods
# File lib/rautomation/adapter/win_32/window.rb, line 259 def press_key key Functions.send_key(key, 0, 0, nil) key end
# File lib/rautomation/adapter/win_32/window.rb, line 264 def release_key key Functions.send_key(key, 0, Constants::KEYEVENTF_KEYUP, nil) key end
# File lib/rautomation/adapter/win_32/window.rb, line 269 def send_key key press_key key release_key key key end