class TestCentricity::TextField

Public Class Methods

new(name, parent, locator, context) click to toggle source
Calls superclass method
# File lib/testcentricity_web/web_elements/textfield.rb, line 3
def initialize(name, parent, locator, context)
  super
  @type = :textfield
end

Public Instance Methods

clear() click to toggle source

Clear the contents of a text field

@example

first_name_field.clear
# File lib/testcentricity_web/web_elements/textfield.rb, line 113
def clear
  case get_native_attribute('tagName').downcase.to_sym
  when :textarea
    set('')
    sleep(0.5)
    send_keys(:tab)
  when :div
    set('')
  else
    length = get_value.length
    length.times do
      send_keys(:backspace)
    end
    sleep(0.5)
    if get_value.length > 0
      set('')
      sleep(0.5)
      send_keys(:tab)
    end
  end
end
get_max() click to toggle source

Return max attribute of a number type text field.

@return [Integer] @example

max_points_value = points_field.get_max
# File lib/testcentricity_web/web_elements/textfield.rb, line 72
def get_max
  obj, = find_element
  object_not_found_exception(obj, nil)
  max = obj.native.attribute('max')
  unless max.blank?
    if max.is_int?
      max.to_i
    elsif max.is_float?
      max.to_f
    else
      max
    end
  end
end
get_max_length() click to toggle source

Return maxlength character count of a text field.

@return [Integer] @example

max_num_chars = comments_field.get_max_length
# File lib/testcentricity_web/web_elements/textfield.rb, line 26
def get_max_length
  obj, = find_element
  object_not_found_exception(obj, nil)
  max_length = obj.native.attribute('maxlength')
  max_length.to_i unless max_length.blank?
end
get_min() click to toggle source

Return min attribute of a number type text field.

@return [Integer] @example

min_points_value = points_field.get_min
# File lib/testcentricity_web/web_elements/textfield.rb, line 51
def get_min
  obj, = find_element
  object_not_found_exception(obj, nil)
  min = obj.native.attribute('min')
  unless min.blank?
    if min.is_int?
      min.to_i
    elsif min.is_float?
      min.to_f
    else
      min
    end
  end
end
get_placeholder() click to toggle source

Return placeholder text of a text field.

@return [String] @example

placeholder_message = username_field.get_placeholder
# File lib/testcentricity_web/web_elements/textfield.rb, line 39
def get_placeholder
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('placeholder')
end
get_step() click to toggle source

Return step attribute of a number type text field.

@return [Integer] @example

points_step = points_field.get_step
# File lib/testcentricity_web/web_elements/textfield.rb, line 93
def get_step
  obj, = find_element
  object_not_found_exception(obj, nil)
  step = obj.native.attribute('step')
  unless step.blank?
    if step.is_int?
      step.to_i
    elsif step.is_float?
      step.to_f
    else
      step
    end
  end
end
read_only?() click to toggle source

Is text field set to read-only?

@return [Boolean] @example

comments_field.read_only?
# File lib/testcentricity_web/web_elements/textfield.rb, line 14
def read_only?
  obj, = find_element
  object_not_found_exception(obj, nil)
  !!obj.native.attribute('readonly')
end