class RAutomation::Window
Attributes
Currently used {Adapter}.
Public Class Methods
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
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
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
@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
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
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
@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
Closes the window if it exists.
# File lib/rautomation/window.rb, line 196 def close return unless @window.exists? @window.close end
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
@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
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
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
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
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
@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
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
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
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
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
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
@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
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
# 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
# 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
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
# File lib/rautomation/window.rb, line 237 def normalize adapter adapter.to_s.split("_").map {|word| word.capitalize}.join end