Sha256: 760076938ccc905e51de024bc2ad74105f33fceac5ec694ebf7fae2746168859

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

module RAutomation
  class TextField
    # @private
    # This constructor is meant to be accessed only through {Window#text_field} method.
    def initialize(window, locators) #:nodoc:
      @window = window
      @locators = locators
      @text_field = @window.text_field(@locators)
    end

    # Sets text of the text field.
    # @param [String] text of the field to set.
    # @raise [UnknownTextFieldException] if the text field doesn't exist.
    def set(text)
      wait_until_exists
      @text_field.set(text)
    end

    # Clears text field's text.
    # @raise [UnknownTextFieldException] if the text field doesn't exist.
    def clear
      wait_until_exists
      @text_field.clear
    end

    # Returns text field's current value (text).
    # @return [String] the value (text) of the text field.
    # @raise [UnknownTextFieldException] if the text field doesn't exist.
    def value
      wait_until_exists
      @text_field.value
    end

    # Checks if the text field exists.
    # @return [Boolean] true if text field exists, false otherwise.
    def exists?
      @text_field.exists?
    end

    alias_method :exist?, :exists?

    private

    def wait_until_exists
      WaitHelper.wait_until(RAutomation::Window.wait_timeout) {exists?}
    rescue WaitHelper::TimeoutError
      raise UnknownTextFieldException, "Text field #{@locators.inspect} doesn't exist on window #{@window.locators.inspect}!" unless exists?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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