Class: TestCentricity::Elements::TextField

Inherits:
UIElement show all
Defined in:
lib/testcentricity_web/web_elements/textfield.rb

Direct Known Subclasses

Range

Constant Summary

Constants inherited from UIElement

UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS

Instance Attribute Summary

Attributes inherited from UIElement

#alt_locator, #base_object, #context, #locator, #locator_type, #mru_driver, #mru_locator, #mru_object, #mru_parent, #name, #original_style, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#aria_autocomplete, #aria_busy?, #aria_checked?, #aria_colcount, #aria_controls, #aria_describedby, #aria_disabled?, #aria_expanded?, #aria_haspopup?, #aria_hidden?, #aria_invalid?, #aria_keyshortcuts, #aria_label, #aria_labelledby, #aria_live, #aria_modal?, #aria_multiline?, #aria_multiselectable?, #aria_orientation, #aria_pressed?, #aria_readonly?, #aria_required?, #aria_roledescription, #aria_rowcount, #aria_selected?, #aria_sort, #aria_valuemax, #aria_valuemin, #aria_valuenow, #aria_valuetext, #clear_alt_locator, #click, #click_at, #content_editable?, #count, #crossorigin, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #exists?, #find_element, #focused?, #get_attribute, #get_locator, #get_locator_type, #get_name, #get_native_attribute, #get_object_type, #get_value, #height, #hidden?, #highlight, #hover, #hover_at, #obscured?, #required?, #reset_mru_cache, #right_click, #role, #scroll_to, #send_keys, #set, #set_alt_locator, #set_locator_type, #style, #tabindex, #title, #unhighlight, #verify_value, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #wait_while_busy, #width, #x, #y

Constructor Details

#initialize(name, parent, locator, context) ⇒ TextField

Returns a new instance of TextField.



4
5
6
7
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 4

def initialize(name, parent, locator, context)
  super
  @type = :textfield
end

Instance Method Details

#clearObject

Clear the contents of a text field

Examples:

first_name_field.clear


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 142

def clear
  field_type = get_native_attribute('tagName')
  field_type = field_type.downcase.to_sym unless field_type.nil?
  case field_type
  when :textarea
    set('')
    sleep(0.5)
    send_keys(:tab)
  when :div, nil
    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_maxInteger

Return max attribute of a number type text field.

Examples:

max_points_value = points_field.get_max

Returns:

  • (Integer)


101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 101

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_lengthInteger

Return maxlength character count of a text field.

Examples:

max_num_chars = comments_field.get_max_length

Returns:

  • (Integer)


27
28
29
30
31
32
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 27

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_minInteger

Return min attribute of a number type text field.

Examples:

min_points_value = points_field.get_min

Returns:

  • (Integer)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 80

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_placeholderString

Return placeholder text of a text field.

Examples:

placeholder_message = username_field.get_placeholder

Returns:



40
41
42
43
44
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 40

def get_placeholder
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('placeholder')
end

#get_stepInteger

Return step attribute of a number type text field.

Examples:

points_step = points_field.get_step

Returns:

  • (Integer)


122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 122

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?Boolean

Is text field set to read-only?

Examples:

comments_field.read_only?

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 15

def read_only?
  obj, = find_element
  object_not_found_exception(obj, nil)
  !!obj.native.attribute('readonly')
end

#validation_messageString

Return validationMessage property of a textfield, which is the message the browser displays to the user when a textfield's validity is checked and fails. Note that each web browser provides a default localized message for this property, and message strings can vary between different browsers (Chrome/Edge vs Firefox vs Safari).

Examples:

message = username_field.validation_message

Returns:



54
55
56
57
58
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 54

def validation_message
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.native.attribute('validationMessage')
end

#validity?(validity_state) ⇒ Boolean

Return Boolean value representing

Examples:

username_field.validity?(:valid)
username_field.validity?(:valueMissing)

Parameters:

  • validity_state (Symbol)

    property to verify

Returns:

  • (Boolean)


68
69
70
71
72
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 68

def validity?(validity_state)
  obj, = find_element
  object_not_found_exception(obj, nil)
  page.execute_script("return arguments[0].validity.#{validity_state}", obj)
end