class TestCentricity::TextField

Public Class Methods

new(name, parent, locator, context) click to toggle source
Calls superclass method TestCentricity::UIElement::new
# File lib/testcentricity/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_elements/textfield.rb, line 89
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)
    send_keys(:tab)
    sleep(0.5)
    length = get_value.length
    if 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_elements/textfield.rb, line 64
def get_max
  obj, = find_element
  object_not_found_exception(obj, nil)
  max = obj.native.attribute('max')
  max.to_i unless max.blank?
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_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_elements/textfield.rb, line 51
def get_min
  obj, = find_element
  object_not_found_exception(obj, nil)
  min = obj.native.attribute('min')
  min.to_i unless min.blank?
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_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_elements/textfield.rb, line 77
def get_step
  obj, = find_element
  object_not_found_exception(obj, nil)
  step = obj.native.attribute('step')
  step.to_i unless step.blank?
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_elements/textfield.rb, line 14
def read_only?
  obj, = find_element
  object_not_found_exception(obj, nil)
  !!obj.native.attribute('readonly')
end