class RAutomation::Adapter::Autoit::Window

Constants

LOCATORS

@private Special-cased locators

Attributes

locators[R]

Locators of the window.

Public Class Methods

autoit() click to toggle source

@private

# File lib/rautomation/adapter/autoit/window.rb, line 10
def autoit
  @@autoit
end
load_autoit() click to toggle source

@private

# File lib/rautomation/adapter/autoit/window.rb, line 15
def load_autoit
  @@autoit = WIN32OLE.new('AutoItX3.Control')
rescue WIN32OLERuntimeError
  dll = File.dirname(__FILE__) + "/../../../../ext/AutoItX/AutoItX3.dll"
  unless system("regsvr32.exe /s #{dll.gsub('/', '\\')}")
    raise "Start Ruby with administrative rights when using AutoIt adapter for the first time."
  end
  @@autoit = WIN32OLE.new('AutoItX3.Control')
end
new(container, locators) click to toggle source

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] :index 0-based index to specify n-th window if all other criteria match @see RAutomation::Window#initialize

# 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)
  extract(locators)
end

Public Instance Methods

activate() click to toggle source

@see RAutomation::Window#activate

# File lib/rautomation/adapter/autoit/window.rb, line 97
def activate
  @@autoit.WinWait(locator_hwnd, "", 1)
  @@autoit.WinActivate(locator_hwnd)
  sleep 1
end
active?() click to toggle source

@see RAutomation::Window#active?

# File lib/rautomation/adapter/autoit/window.rb, line 104
def active?
  @@autoit.WinActive(locator_hwnd) == 1
end
button(locator={}) click to toggle source

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

# File lib/rautomation/adapter/autoit/window.rb, line 172
def button(locator={})
  Button.new(self, locator)
end
class_names() click to toggle source

@see RAutomation::Window#class_names

# File lib/rautomation/adapter/autoit/window.rb, line 92
def class_names
  @@autoit.WinGetClassList(locator_hwnd).split("\n").sort
end
close() click to toggle source

@see RAutomation::Window#close

# File lib/rautomation/adapter/autoit/window.rb, line 160
def close
  @@autoit.WinClose(locator_hwnd)
  @@autoit.WinKill(locator_hwnd)
end
exists?() click to toggle source

@see RAutomation::Window#exists?

# File lib/rautomation/adapter/autoit/window.rb, line 114
def exists?
  @@autoit.WinExists(locator_hwnd) == 1
end
hwnd() click to toggle source

Retrieves handle of the window. @note Searches only for visible windows. @see RAutomation::Window#hwnd

# File lib/rautomation/adapter/autoit/window.rb, line 61
def hwnd
  @hwnd ||= begin
    locators = @autoit_locators
    if @locator_index || @locator_pid
      # @todo Come up with some better solution for this case
      locators = "[regexptitle:]" # match all, needed for the case when only :index or :pid is used
    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
locator_hwnd() click to toggle source

@private

# File lib/rautomation/adapter/autoit/window.rb, line 191
def locator_hwnd
  "[HANDLE:#{hwnd.to_i.to_s(16)}]"
end
maximize() click to toggle source

@see RAutomation::Window#maximize

# File lib/rautomation/adapter/autoit/window.rb, line 124
def maximize
  @@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_MAXIMIZE)
  sleep 1
end
method_missing(name, *args) click to toggle source

Redirects all method calls not part of the public API to the AutoIt directly. @example execute AutoIt's WinGetTitle function:

RAutomation::Window.new(:hwnd => 123456).WinGetTitle(...)

@see RAutomation::Window#method_missing

# File lib/rautomation/adapter/autoit/window.rb, line 186
def method_missing(name, *args)
  @@autoit.send(name, *args)
end
minimize() click to toggle source

@see RAutomation::Window#minimize

# File lib/rautomation/adapter/autoit/window.rb, line 130
def minimize
  @@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_MINIMIZE)
  sleep 1
end
minimized?() click to toggle source

@see RAutomation::Window#minimized?

# File lib/rautomation/adapter/autoit/window.rb, line 136
def minimized?
  @@autoit.WinGetState(locator_hwnd) & 16 == 16
end
mouse() click to toggle source
# File lib/rautomation/adapter/autoit/window.rb, line 165
def mouse
  @container.wait_until_present
  Mouse.new(self)
end
pid() click to toggle source

@see RAutomation::Window#pid

# File lib/rautomation/adapter/autoit/window.rb, line 82
def pid
  @@autoit.WinGetProcess(locator_hwnd).to_i
end
restore() click to toggle source

@see RAutomation::Window#restore

# File lib/rautomation/adapter/autoit/window.rb, line 141
def restore
  @@autoit.WinSetState(locator_hwnd, "", @@autoit.SW_RESTORE)
  sleep 1
end
send_keys(keys) click to toggle source

Activates the window and sends keys to it.

Refer to AutoIt documentation at www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm for keys syntax. @see RAutomation::Window#send_keys

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

@see RAutomation::Window#text

# File lib/rautomation/adapter/autoit/window.rb, line 109
def text
  @@autoit.WinGetText(locator_hwnd)
end
text_field(locator={}) click to toggle source

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

# File lib/rautomation/adapter/autoit/window.rb, line 178
def text_field(locator={})
  TextField.new(self, locator)
end
title() click to toggle source

@see RAutomation::Window#title

# File lib/rautomation/adapter/autoit/window.rb, line 87
def title
  @@autoit.WinGetTitle(locator_hwnd)
end
visible?() click to toggle source

@see RAutomation::Window#visible?

# File lib/rautomation/adapter/autoit/window.rb, line 119
def visible?
  @@autoit.WinGetState(locator_hwnd) & 2 == 2
end