Sha256: 5b27c2aacfc1e5d6d5d401f1148f433993e879f968f4ab55d65a04734a34068e

Contents?: true

Size: 2 KB

Versions: 4

Compression:

Stored size: 2 KB

Contents

module RAutomation
  module Adapter
    module Autoit
      class TextField
        include WaitHelper
        include Locators

        # @private
        # Special-cased locators
        LOCATORS = {
                [:class, Regexp] => :regexpclass,
                :index => :instance,
                :value => :text
        }

        # Creates the text field object.
        # @note this method is not meant to be accessed directly, but only through {RAutomation::Window#text_field}!
        # @param [RAutomation::Window] window this text field belongs to.
        # @param [Hash] locators for searching the text field.
        # @option locators [String, Regexp] :class Internal class name of the text field
        # @option locators [String, Regexp] :value Value (text) of the text field
        # @option locators [String, Fixnum] :id Internal ID of the text field
        # @option locators [String, Fixnum] :index 0-based index to specify n-th text field if all other criteria match
        # @see RAutomation::Window#text_field
        def initialize(window, locators)
          @window = window
          extract(locators)
        end

        # @see RAutomation::TextField#set
        def set(text)
          wait_until do
            @window.activate
            @window.active? &&
                    Window.autoit.ControlFocus(@window.locator_hwnd, "", @locators) == 1 &&
                    Window.autoit.ControlSetText(@window.locator_hwnd, "", @locators, text) == 1 &&
                    value == text
          end
        end

        # @see RAutomation::TextField#clear
        def clear
          set ""
        end

        # @see RAutomation::TextField#value
        def value
          Window.autoit.ControlGetText(@window.locator_hwnd, "", @locators)
        end

        # @see RAutomation::TextField#exists?
        def exists?
          not Window.autoit.ControlGetHandle(@window.locator_hwnd, "", @locators).empty?
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rautomation-0.4.0 lib/rautomation/adapter/autoit/text_field.rb
rautomation-0.3.0 lib/rautomation/adapter/autoit/text_field.rb
rautomation-0.2.1 lib/rautomation/adapter/autoit/text_field.rb
rautomation-0.2.0 lib/rautomation/adapter/autoit/text_field.rb