Class: TestCentricity::Elements::TextField
- Defined in:
- lib/testcentricity_web/web_elements/textfield.rb
Direct Known Subclasses
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
-
#clear ⇒ Object
Clear the contents of a text field.
-
#get_max ⇒ Integer
Return max attribute of a number type text field.
-
#get_max_length ⇒ Integer
Return maxlength character count of a text field.
-
#get_min ⇒ Integer
Return min attribute of a number type text field.
-
#get_placeholder ⇒ String
Return placeholder text of a text field.
-
#get_step ⇒ Integer
Return step attribute of a number type text field.
-
#initialize(name, parent, locator, context) ⇒ TextField
constructor
A new instance of TextField.
-
#read_only? ⇒ Boolean
Is text field set to read-only?.
-
#validation_message ⇒ String
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.
-
#validity?(validity_state) ⇒ Boolean
Return Boolean value representing.
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
#clear ⇒ Object
Clear the contents of a text field
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_max ⇒ Integer
Return max attribute of a number type text field.
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_length ⇒ Integer
Return maxlength character count of a text field.
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_min ⇒ Integer
Return min attribute of a number type text field.
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_placeholder ⇒ String
Return placeholder text of a text field.
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_step ⇒ Integer
Return step attribute of a number type text field.
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?
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_message ⇒ String
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).
54 55 56 57 58 |
# File 'lib/testcentricity_web/web_elements/textfield.rb', line 54 def obj, = find_element object_not_found_exception(obj, nil) obj.native.attribute('validationMessage') end |
#validity?(validity_state) ⇒ Boolean
Return Boolean value representing
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 |