class RAutomation::Window

Attributes

adapter[R]

Currently used {Adapter}.

Public Class Methods

new(locators) click to toggle source

Creates the window object.

Possible window locators may depend of the used platform and adapter, but following examples will use :title, :class and :hwnd.

@example Use window with some title:

RAutomation::Window.new(:title => "some title")

@example Use window with Regexp title:

RAutomation::Window.new(:title => /some title/i)

@example Use window with handle (hwnd):

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

@example Use multiple locators, every locator will be matched (AND-ed) to the window:

RAutomation::Window.new(:title => "some title", :class => "IEFrame")

@note Refer to all possible locators in each {Adapter} documentation.

locators may also include a key called :adapter to change default adapter, which is dependent of the platform, to automate windows and their controls.

It is also possible to change the default adapter by using environment variable called RAUTOMATION_ADAPTER

@note This constructor doesn't check for window's existance. @note Only visible windows are supported. @note If given locators include :hwnd then every other possible locator is ignored. @param [Hash] locators locators for the window.

# File lib/rautomation/window.rb, line 65
def initialize(locators)
  @adapter = locators.delete(:adapter) || ENV["RAUTOMATION_ADAPTER"] && ENV["RAUTOMATION_ADAPTER"].to_sym || default_adapter
  @window = Adapter.const_get(normalize(@adapter)).const_get(:Window).new(self, locators)
end
wait_timeout() click to toggle source

Retrieve current timeout in seconds to wait before {WaitHelper::TimeoutError} is raised. @return [Integer] timeout in seconds

# File lib/rautomation/window.rb, line 82
def wait_timeout
  @@wait_timeout
end
wait_timeout=(timeout) click to toggle source

Change the timeout to wait before {WaitHelper::TimeoutError} is raised. @param [Integer] timeout in seconds.

# File lib/rautomation/window.rb, line 76
def wait_timeout=(timeout)
  @@wait_timeout = timeout
end
windows(locators = {}) click to toggle source

@param locators (see initialize) @return [Windows] all windows.

# File lib/rautomation/window.rb, line 20
def windows(locators = {})
  Windows.new(nil, locators)
end

Public Instance Methods

activate() click to toggle source

Activates the Window, e.g. brings it to the top of other windows.

# File lib/rautomation/window.rb, line 117
def activate
  @window.activate
end
active?() click to toggle source

Checks if the window is active, e.g. on the top of other windows. @return [Boolean] true if the window is active, false otherwise.

# File lib/rautomation/window.rb, line 123
def active?
  @window.active?
end
button(locators={}) click to toggle source

Retrieves {Button} on the window. @note Refer to specific {Adapter} documentation for possible locator parameters. @param [Hash] locators for the {Button}. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 205
def button(locators={})
  wait_until_present
  Button.new(@window, locators)
end
class_names() click to toggle source

@return [Array<String>] all {Window} class names in a sorted array. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 111
def class_names
  wait_until_present
  @window.class_names
end
close() click to toggle source

Closes the window if it exists.

# File lib/rautomation/window.rb, line 196
def close
  return unless @window.exists?
  @window.close
end
exist?()
Alias for: exists?
exists?() click to toggle source

Checks if the window exists (does have to be visible). @return [Boolean] true if the window exists, false otherwise.

# File lib/rautomation/window.rb, line 137
def exists?
  @window.exists?
end
Also aliased as: exist?
hwnd() click to toggle source

@return [Integer] handle of the window which is used internally for other methods. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 90
def hwnd
  wait_until_present
  @window.hwnd
end
maximize() click to toggle source

Maximizes the window. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 160
def maximize
  wait_until_present
  @window.maximize
end
method_missing(name, *args) click to toggle source

Allows to execute specific {Adapter} methods not part of the public API.

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

Minimizes the window. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 167
def minimize
  wait_until_present
  @window.minimize
end
minimized?() click to toggle source

Checks if window is minimized. @return [Boolean] true if window is minimized, false otherwise. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 175
def minimized?
  wait_until_present
  @window.minimized?
end
pid() click to toggle source

@return [Integer] process identifier (PID) of the window. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 97
def pid
  wait_until_present
  @window.pid
end
present?() click to toggle source

Checks if the window exists and is visible. @return [Boolean] true if window exists and is visible, false otherwise

# File lib/rautomation/window.rb, line 154
def present?
  exists? && visible?
end
restore() click to toggle source

Restores the window size and position. @note If the window is minimized, makes it visible again. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 183
def restore
  wait_until_present
  @window.restore
end
send_keys(*keys) click to toggle source

Sends keyboard keys to the window. Refer to specific {Adapter} documentation for all possible values. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 190
def send_keys(*keys)
  wait_until_present
  @window.send_keys(keys)
end
text() click to toggle source

Returns visible text of the Window. @return [String] visible text of the window. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 130
def text
  wait_until_present
  @window.text
end
text_field(locators={}) click to toggle source

Retrieves {TextField} on the window. @note Refer to specific {Adapter} documentation for possible locators parameters. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 213
def text_field(locators={})
  wait_until_present
  TextField.new(@window, locators)
end
title() click to toggle source

@return [String] title of the window. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 104
def title
  wait_until_present
  @window.title
end
visible?() click to toggle source

Checks if window is visible. @note Window is also visible, if it is behind other windows or minimized. @return [Boolean] true if window is visible, false otherwise. @raise [UnknownWindowException] if the window doesn't exist.

# File lib/rautomation/window.rb, line 147
def visible?
  wait_until_exists
  @window.visible?
end
wait_until_exists() click to toggle source
# File lib/rautomation/window.rb, line 229
def wait_until_exists
  WaitHelper.wait_until {exists?}
rescue WaitHelper::TimeoutError
  raise UnknownWindowException, "Window with locator #{@window.locators.inspect} doesn't exist!"
end
wait_until_present() click to toggle source
# File lib/rautomation/window.rb, line 223
def wait_until_present
  WaitHelper.wait_until {present?}
rescue WaitHelper::TimeoutError
  raise UnknownWindowException, "Window with locator #{@window.locators.inspect} doesn't exist or is not visible!"
end
windows(locators = @window.locators) click to toggle source

Retrieves all windows with similar locators to the current window. @param locators (see initialize) @return [Windows] all windows matching current window's locators if no

explicit locators specified or windows matching the specified _locators_.
# File lib/rautomation/window.rb, line 29
def windows(locators = @window.locators)
  Windows.new(nil, locators)
end

Private Instance Methods

normalize(adapter) click to toggle source
# File lib/rautomation/window.rb, line 237
def normalize adapter
  adapter.to_s.split("_").map {|word| word.capitalize}.join
end