Class: TestCentricity::Elements::UIElement
- Includes:
- Capybara::DSL, Test::Unit::Assertions
- Defined in:
- lib/testcentricity_web/web_elements/ui_element.rb
Direct Known Subclasses
Button, CheckBox, FileField, Image, Label, Link, List, Media, Radio, SelectList, Table, TextField
Constant Summary collapse
- XPATH_SELECTORS =
['//', '[@', '[contains(']
- CSS_SELECTORS =
%w[# :nth-child( :first-child :last-child :nth-of-type( :first-of-type :last-of-type ^= $= *= :contains(]
Instance Attribute Summary collapse
-
#alt_locator ⇒ Object
Returns the value of attribute alt_locator.
-
#base_object ⇒ Object
Returns the value of attribute base_object.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#locator ⇒ Object
readonly
Returns the value of attribute locator.
-
#locator_type ⇒ Object
Returns the value of attribute locator_type.
-
#mru_driver ⇒ Object
Returns the value of attribute mru_driver.
-
#mru_locator ⇒ Object
Returns the value of attribute mru_locator.
-
#mru_object ⇒ Object
Returns the value of attribute mru_object.
-
#mru_parent ⇒ Object
Returns the value of attribute mru_parent.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#original_style ⇒ Object
Returns the value of attribute original_style.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#aria_autocomplete ⇒ Boolean
Return state of UI object's aria-autocomplete property.
-
#aria_busy? ⇒ Boolean
Return state of UI object's aria-busy property.
-
#aria_checked? ⇒ Boolean
Return state of UI object's aria-checked property.
-
#aria_colcount ⇒ Integer
Return state of UI object's aria-colcount property.
-
#aria_controls ⇒ String
Return state of UI object's aria-controls property.
-
#aria_describedby ⇒ String
Return state of UI object's aria-describedby property.
-
#aria_disabled? ⇒ Boolean
Return state of UI object's aria-disabled property.
-
#aria_expanded? ⇒ Boolean
Return state of UI object's aria-expanded property.
-
#aria_haspopup? ⇒ Boolean
Return state of UI object's aria-haspopup property.
-
#aria_hidden? ⇒ Boolean
Return state of UI object's aria-hidden property.
-
#aria_invalid? ⇒ Boolean
Return state of UI object's aria-invalid property.
-
#aria_keyshortcuts ⇒ String
Return state of UI object's aria-keyshortcuts property.
-
#aria_label ⇒ String
Return state of UI object's aria-label property.
-
#aria_labelledby ⇒ String
Return state of UI object's aria-labelledby property.
-
#aria_live ⇒ String
Return state of UI object's aria-live property.
-
#aria_modal? ⇒ Boolean
Return state of UI object's aria-modal property.
-
#aria_multiline? ⇒ Boolean
Return state of UI object's aria-multiline property.
-
#aria_multiselectable? ⇒ Boolean
Return state of UI object's aria-multiselectable property.
-
#aria_orientation ⇒ String
Return state of UI object's aria-orientation property.
-
#aria_pressed? ⇒ Boolean
Return state of UI object's aria-pressed property.
-
#aria_readonly? ⇒ Boolean
Return state of UI object's aria-readonly property.
-
#aria_required? ⇒ Boolean
Return state of UI object's aria-required property.
-
#aria_roledescription ⇒ String
Return state of UI object's aria-roledescription property.
-
#aria_rowcount ⇒ Integer
Return state of UI object's aria-rowcount property.
-
#aria_selected? ⇒ Boolean
Return state of UI object's aria-selected property.
-
#aria_sort ⇒ String
Return state of UI object's aria-sort property.
-
#aria_valuemax ⇒ Integer
Return state of UI object's aria-valuemax property.
-
#aria_valuemin ⇒ Integer
Return state of UI object's aria-valuemin property.
-
#aria_valuenow ⇒ Integer
Return state of UI object's aria-valuenow property.
-
#aria_valuetext ⇒ String
Return state of UI object's aria-valuetext property.
- #clear_alt_locator ⇒ Object
-
#click ⇒ Object
Click on an object.
-
#click_at(x, y) ⇒ Object
Click at a specific location within an object.
-
#content_editable? ⇒ Boolean
Return state of UI object's contenteditable property.
-
#count(visible = true) ⇒ Object
Return the number of occurrences of an object with an ambiguous locator that evaluates to multiple UI elements.
-
#crossorigin ⇒ Object
Return crossorigin property.
-
#disabled? ⇒ Boolean
Is UI object disabled (not enabled)?.
-
#displayed? ⇒ Boolean
Is UI object displayed in browser window?.
-
#double_click ⇒ Object
Double-click on an object.
- #drag_and_drop(target, right_offset = nil, down_offset = nil) ⇒ Object
- #drag_by(right_offset, down_offset) ⇒ Object
-
#draggable? ⇒ Boolean
Return state of UI object's draggable property.
-
#enabled? ⇒ Boolean
Is UI object enabled?.
-
#exists?(visible = true) ⇒ Boolean
Does UI object exists?.
- #find_element(visible = true) ⇒ Object
-
#focused? ⇒ Boolean
Does UI object have the current focus?.
- #get_attribute(attrib) ⇒ Object
- #get_locator ⇒ Object
- #get_locator_type ⇒ Object
-
#get_max ⇒ Integer
Return max attribute of a number type text field or a progress bar.
- #get_name ⇒ Object
- #get_native_attribute(attrib) ⇒ Object
- #get_object_type ⇒ Object
- #get_value(visible = true) ⇒ Object (also: #get_caption, #caption, #value)
-
#hasHorizontalOverflow? ⇒ Boolean
Is UI object's text content truncated horizontally?.
-
#hasVerticalOverflow? ⇒ Boolean
Is UI object's text content truncated vertically?.
-
#height ⇒ Integer
Return height of object.
-
#hidden? ⇒ Boolean
Is UI object hidden (not visible)?.
-
#highlight(duration = 1) ⇒ Object
Highlight an object with a 3 pixel wide, red dashed border for the specified wait time.
-
#hover(visible = true) ⇒ Object
Hover the cursor over an object.
-
#hover_at(x, y, visible = true) ⇒ Object
Hover at a specific location within an object.
-
#initialize(name, parent, locator, context) ⇒ UIElement
constructor
A new instance of UIElement.
-
#obscured? ⇒ Boolean
Is UI object obscured (not currently in viewport and not clickable)?.
-
#required? ⇒ Boolean
Is UI object's required attribute set?.
- #reset_mru_cache ⇒ Object
-
#right_click ⇒ Object
Right-click on an object.
-
#role ⇒ String
Return state of UI object's role property.
-
#scroll_to(position) ⇒ Object
Scroll the object to its top, middle, or bottom.
-
#send_keys(*keys) ⇒ Object
Send keystrokes to this object.
- #set(value) ⇒ Object
- #set_alt_locator(temp_locator) ⇒ Object
- #set_locator_type(locator = nil) ⇒ Object
-
#style ⇒ String
Return UI object's style property.
-
#tabindex ⇒ String
Return state of UI object's tabindex property.
-
#title ⇒ String
Return UI object's title property.
-
#unhighlight ⇒ Object
Restore a highlighted object's original style.
- #verify_value(expected, enqueue = false) ⇒ Object (also: #verify_caption)
-
#visible? ⇒ Boolean
Is UI object visible?.
-
#wait_until_enabled(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is enabled, or until the specified wait time has expired.
-
#wait_until_exists(seconds = nil, post_exception = true) ⇒ Object
Wait until the object exists, or until the specified wait time has expired.
-
#wait_until_gone(seconds = nil, post_exception = true) ⇒ Object
Wait until the object no longer exists, or until the specified wait time has expired.
-
#wait_until_hidden(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is hidden, or until the specified wait time has expired.
-
#wait_until_value_changes(seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value changes to a different value, or until the specified wait time has expired.
-
#wait_until_value_is(value, seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value equals the specified value, or until the specified wait time has expired.
-
#wait_until_visible(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is visible, or until the specified wait time has expired.
-
#wait_while_busy(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is no longer in a busy state, or until the specified wait time has expired.
-
#width ⇒ Integer
Return width of object.
-
#x ⇒ Integer
Return x coordinate of object's location.
-
#y ⇒ Integer
Return y coordinate of object's location.
Constructor Details
#initialize(name, parent, locator, context) ⇒ UIElement
Returns a new instance of UIElement.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 54 def initialize(name, parent, locator, context) @name = name @parent = parent @locator = locator @context = context @type = nil @alt_locator = nil @original_style = nil reset_mru_cache set_locator_type end |
Instance Attribute Details
#alt_locator ⇒ Object
Returns the value of attribute alt_locator.
47 48 49 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 47 def alt_locator @alt_locator end |
#base_object ⇒ Object
Returns the value of attribute base_object.
48 49 50 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 48 def base_object @base_object end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 46 def context @context end |
#locator ⇒ Object (readonly)
Returns the value of attribute locator.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 46 def locator @locator end |
#locator_type ⇒ Object
Returns the value of attribute locator_type.
47 48 49 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 47 def locator_type @locator_type end |
#mru_driver ⇒ Object
Returns the value of attribute mru_driver.
49 50 51 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 49 def mru_driver @mru_driver end |
#mru_locator ⇒ Object
Returns the value of attribute mru_locator.
49 50 51 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 49 def mru_locator @mru_locator end |
#mru_object ⇒ Object
Returns the value of attribute mru_object.
49 50 51 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 49 def mru_object @mru_object end |
#mru_parent ⇒ Object
Returns the value of attribute mru_parent.
49 50 51 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 49 def mru_parent @mru_parent end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 46 def name @name end |
#original_style ⇒ Object
Returns the value of attribute original_style.
47 48 49 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 47 def original_style @original_style end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 46 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 46 def type @type end |
Instance Method Details
#aria_autocomplete ⇒ Boolean
Return state of UI object's aria-autocomplete property
967 968 969 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 967 def aria_autocomplete get_attribute('aria-autocomplete') end |
#aria_busy? ⇒ Boolean
Return state of UI object's aria-busy property
1097 1098 1099 1100 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1097 def aria_busy? state = get_attribute('aria-busy') state.boolean? ? state : state == 'true' end |
#aria_checked? ⇒ Boolean
Return state of UI object's aria-checked property
1053 1054 1055 1056 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1053 def aria_checked? state = get_attribute('aria-checked') state.boolean? ? state : state == 'true' end |
#aria_colcount ⇒ Integer
Return state of UI object's aria-colcount property
853 854 855 856 857 858 859 860 861 862 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 853 def aria_colcount cols = get_attribute('aria-colcount') unless cols.blank? if cols.is_int? cols.to_i else cols end end end |
#aria_controls ⇒ String
Return state of UI object's aria-controls property
977 978 979 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 977 def aria_controls get_attribute('aria-controls') end |
#aria_describedby ⇒ String
Return state of UI object's aria-describedby property
806 807 808 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 806 def aria_describedby get_attribute('aria-describedby') end |
#aria_disabled? ⇒ Boolean
Return state of UI object's aria-disabled property
987 988 989 990 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 987 def aria_disabled? state = get_attribute('aria-disabled') state.boolean? ? state : state == 'true' end |
#aria_expanded? ⇒ Boolean
Return state of UI object's aria-expanded property
1020 1021 1022 1023 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1020 def state = get_attribute('aria-expanded') state.boolean? ? state : state == 'true' end |
#aria_haspopup? ⇒ Boolean
Return state of UI object's aria-haspopup property
1064 1065 1066 1067 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1064 def aria_haspopup? state = get_attribute('aria-haspopup') state.boolean? ? state : state == 'true' end |
#aria_hidden? ⇒ Boolean
Return state of UI object's aria-hidden property
1009 1010 1011 1012 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1009 def aria_hidden? state = get_attribute('aria-hidden') state.boolean? ? state : state == 'true' end |
#aria_invalid? ⇒ Boolean
Return state of UI object's aria-invalid property
1042 1043 1044 1045 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1042 def aria_invalid? state = get_attribute('aria-invalid') state.boolean? ? state : state == 'true' end |
#aria_keyshortcuts ⇒ String
Return state of UI object's aria-keyshortcuts property
947 948 949 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 947 def aria_keyshortcuts get_attribute('aria-keyshortcuts') end |
#aria_label ⇒ String
Return state of UI object's aria-label property
786 787 788 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 786 def aria_label get_attribute('aria-label') end |
#aria_labelledby ⇒ String
Return state of UI object's aria-labelledby property
796 797 798 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 796 def aria_labelledby get_attribute('aria-labelledby') end |
#aria_live ⇒ String
Return state of UI object's aria-live property
816 817 818 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 816 def aria_live get_attribute('aria-live') end |
#aria_modal? ⇒ Boolean
Return state of UI object's aria-modal property
1108 1109 1110 1111 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1108 def aria_modal? state = get_attribute('aria-modal') state.boolean? ? state : state == 'true' end |
#aria_multiline? ⇒ Boolean
Return state of UI object's aria-multiline property
1119 1120 1121 1122 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1119 def aria_multiline? state = get_attribute('aria-multiline') state.boolean? ? state : state == 'true' end |
#aria_multiselectable? ⇒ Boolean
Return state of UI object's aria-multiselectable property
1130 1131 1132 1133 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1130 def aria_multiselectable? state = get_attribute('aria-multiselectable') state.boolean? ? state : state == 'true' end |
#aria_orientation ⇒ String
Return state of UI object's aria-orientation property
937 938 939 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 937 def aria_orientation get_attribute('aria-orientation') end |
#aria_pressed? ⇒ Boolean
Return state of UI object's aria-pressed property
1075 1076 1077 1078 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1075 def aria_pressed? state = get_attribute('aria-pressed') state.boolean? ? state : state == 'true' end |
#aria_readonly? ⇒ Boolean
Return state of UI object's aria-readonly property
1086 1087 1088 1089 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1086 def aria_readonly? state = get_attribute('aria-readonly') state.boolean? ? state : state == 'true' end |
#aria_required? ⇒ Boolean
Return state of UI object's aria-required property
1031 1032 1033 1034 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1031 def aria_required? state = get_attribute('aria-required') state.boolean? ? state : state == 'true' end |
#aria_roledescription ⇒ String
Return state of UI object's aria-roledescription property
957 958 959 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 957 def aria_roledescription get_attribute('aria-roledescription') end |
#aria_rowcount ⇒ Integer
Return state of UI object's aria-rowcount property
836 837 838 839 840 841 842 843 844 845 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 836 def aria_rowcount rows = get_attribute('aria-rowcount') unless rows.blank? if rows.is_int? rows.to_i else rows end end end |
#aria_selected? ⇒ Boolean
Return state of UI object's aria-selected property
998 999 1000 1001 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 998 def aria_selected? state = get_attribute('aria-selected') state.boolean? ? state : state == 'true' end |
#aria_sort ⇒ String
Return state of UI object's aria-sort property
826 827 828 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 826 def aria_sort get_attribute('aria-sort') end |
#aria_valuemax ⇒ Integer
Return state of UI object's aria-valuemax property
870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 870 def aria_valuemax max = get_attribute('aria-valuemax') unless max.blank? if max.is_int? max.to_i elsif max.is_float? max.to_f else max end end end |
#aria_valuemin ⇒ Integer
Return state of UI object's aria-valuemin property
889 890 891 892 893 894 895 896 897 898 899 900 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 889 def aria_valuemin min = get_attribute('aria-valuemin') unless min.blank? if min.is_int? min.to_i elsif min.is_float? min.to_f else min end end end |
#aria_valuenow ⇒ Integer
Return state of UI object's aria-valuenow property
908 909 910 911 912 913 914 915 916 917 918 919 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 908 def aria_valuenow result = get_attribute('aria-valuenow') unless result.blank? if result.is_int? result.to_i elsif result.is_float? result.to_f else result end end end |
#aria_valuetext ⇒ String
Return state of UI object's aria-valuetext property
927 928 929 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 927 def aria_valuetext get_attribute('aria-valuetext') end |
#clear_alt_locator ⇒ Object
118 119 120 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 118 def clear_alt_locator @alt_locator = nil end |
#click ⇒ Object
Click on an object
127 128 129 130 131 132 133 134 135 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 127 def click obj, type = find_element object_not_found_exception(obj, type) begin obj.click rescue StandardError obj.click_at(10, 10) end end |
#click_at(x, y) ⇒ Object
Click at a specific location within an object
166 167 168 169 170 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 166 def click_at(x, y) obj, = find_element raise "UI #{object_ref_message} not found" unless obj obj.click_at(x, y) end |
#content_editable? ⇒ Boolean
Return state of UI object's contenteditable property
1141 1142 1143 1144 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1141 def content_editable? state = get_attribute('contenteditable') state.boolean? ? state : state == 'true' end |
#count(visible = true) ⇒ Object
Return the number of occurrences of an object with an ambiguous locator that evaluates to multiple UI elements.
487 488 489 490 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 487 def count(visible = true) obj_locator = @alt_locator.nil? ? @locator : @alt_locator page.all(@locator_type, obj_locator, wait: 0.01, visible: visible, minimum: 0).count end |
#crossorigin ⇒ Object
Return crossorigin property
1152 1153 1154 1155 1156 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1152 def crossorigin obj, = find_element object_not_found_exception(obj, @type) obj.native.attribute('crossorigin') end |
#disabled? ⇒ Boolean
Is UI object disabled (not enabled)?
252 253 254 255 256 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 252 def disabled? obj, type = find_element object_not_found_exception(obj, type) obj.disabled? end |
#displayed? ⇒ Boolean
Is UI object displayed in browser window?
556 557 558 559 560 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 556 def displayed? obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.displayed? end |
#double_click ⇒ Object
Double-click on an object
142 143 144 145 146 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 142 def double_click obj, type = find_element object_not_found_exception(obj, type) page.driver.browser.action.double_click(obj.native).perform end |
#drag_and_drop(target, right_offset = nil, down_offset = nil) ⇒ Object
672 673 674 675 676 677 678 679 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 672 def drag_and_drop(target, right_offset = nil, down_offset = nil) source, type = find_element object_not_found_exception(source, type) page.driver.browser.action.click_and_hold(source.native).perform sleep(1) target_drop, = target.find_element page.driver.browser.action.move_to(target_drop.native, right_offset.to_i, down_offset.to_i).release.perform end |
#drag_by(right_offset, down_offset) ⇒ Object
664 665 666 667 668 669 670 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 664 def drag_by(right_offset, down_offset) obj, type = find_element object_not_found_exception(obj, type) page.driver.browser.action.click_and_hold(obj.native).perform sleep(1) obj.drag_by(right_offset, down_offset) end |
#draggable? ⇒ Boolean
Return state of UI object's draggable property
568 569 570 571 572 573 574 575 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 568 def draggable? state = get_attribute(:draggable) if state.is_a?(String) state.to_bool elsif state.boolean? state end end |
#enabled? ⇒ Boolean
Is UI object enabled?
242 243 244 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 242 def enabled? !disabled? end |
#exists?(visible = true) ⇒ Boolean
Does UI object exists?
208 209 210 211 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 208 def exists?(visible = true) obj, = find_object(visible) !obj.nil? end |
#find_element(visible = true) ⇒ Object
1171 1172 1173 1174 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1171 def find_element(visible = true) wait = Selenium::WebDriver::Wait.new(timeout: .default_max_wait_time) wait.until { find_object(visible) } end |
#focused? ⇒ Boolean
Does UI object have the current focus?
289 290 291 292 293 294 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 289 def focused? obj, type = find_element(visible = :all) object_not_found_exception(obj, type) focused_obj = page.driver.browser.switch_to.active_element focused_obj == obj.native end |
#get_attribute(attrib) ⇒ Object
1158 1159 1160 1161 1162 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1158 def get_attribute(attrib) obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj[attrib] end |
#get_locator ⇒ Object
106 107 108 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 106 def get_locator @locator end |
#get_locator_type ⇒ Object
88 89 90 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 88 def get_locator_type @locator_type end |
#get_max ⇒ Integer
Return max attribute of a number type text field or a progress bar.
735 736 737 738 739 740 741 742 743 744 745 746 747 748 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 735 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_name ⇒ Object
110 111 112 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 110 def get_name @name end |
#get_native_attribute(attrib) ⇒ Object
1164 1165 1166 1167 1168 1169 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1164 def get_native_attribute(attrib) reset_mru_cache obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.native.attribute(attrib) end |
#get_object_type ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 92 def get_object_type if @type @type else obj, type = find_element object_not_found_exception(obj, type) if obj.tag_name obj.tag_name elsif obj.native.attribute('type') obj.native.attribute('type') end end end |
#get_value(visible = true) ⇒ Object Also known as: get_caption, caption, value
601 602 603 604 605 606 607 608 609 610 611 612 613 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 601 def get_value(visible = true) obj, type = find_element(visible) object_not_found_exception(obj, type) value = case obj.tag_name.downcase when 'input', 'select', 'textarea' obj.value when 'progress' obj.value.to_i else obj.text end value.is_a?(String) ? value.gsub(/[[:space:]]+/, ' ').strip : value end |
#hasHorizontalOverflow? ⇒ Boolean
Is UI object's text content truncated horizontally?
583 584 585 586 587 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 583 def hasHorizontalOverflow? scroll_width = get_attribute(:scrollWidth) client_width = get_attribute(:clientWidth) scroll_width > client_width end |
#hasVerticalOverflow? ⇒ Boolean
Is UI object's text content truncated vertically?
595 596 597 598 599 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 595 def hasVerticalOverflow? scroll_height = get_attribute(:scrollHeight) client_height = get_attribute(:clientHeight) scroll_height > client_height end |
#height ⇒ Integer
Return height of object.
510 511 512 513 514 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 510 def height obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.get_height end |
#hidden? ⇒ Boolean
Is UI object hidden (not visible)?
232 233 234 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 232 def hidden? !visible? end |
#highlight(duration = 1) ⇒ Object
Highlight an object with a 3 pixel wide, red dashed border for the specified wait time. If wait time is zero, then the highlight will remain until the page is refreshed
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 688 def highlight(duration = 1) obj, type = find_element object_not_found_exception(obj, type) # store original style so it can be reset later @original_style = obj.native.attribute('style') # style element with red border page.execute_script( 'arguments[0].setAttribute(arguments[1], arguments[2])', obj, 'style', 'border: 3px solid red; border-style: dashed;' ) # keep element highlighted for duration and then revert to original style if duration.positive? sleep duration page.execute_script( 'arguments[0].setAttribute(arguments[1], arguments[2])', obj, 'style', @original_style ) end end |
#hover(visible = true) ⇒ Object
Hover the cursor over an object
639 640 641 642 643 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 639 def hover(visible = true) obj, type = find_element(visible) object_not_found_exception(obj, type) obj.hover end |
#hover_at(x, y, visible = true) ⇒ Object
Hover at a specific location within an object
658 659 660 661 662 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 658 def hover_at(x, y, visible = true) obj, = find_element(visible) raise "UI #{object_ref_message} not found" unless obj obj.hover_at(x, y) end |
#obscured? ⇒ Boolean
Is UI object obscured (not currently in viewport and not clickable)?
277 278 279 280 281 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 277 def obscured? obj, type = find_element object_not_found_exception(obj, type) obj.obscured? end |
#required? ⇒ Boolean
Is UI object's required attribute set?
264 265 266 267 268 269 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 264 def required? obj, type = find_element object_not_found_exception(obj, type) state = get_attribute(:required) state.boolean? ? state : state == 'true' end |
#reset_mru_cache ⇒ Object
66 67 68 69 70 71 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 66 def reset_mru_cache @mru_object = nil @mru_locator = nil @mru_parent = nil @mru_driver = nil end |
#right_click ⇒ Object
Right-click on an object
153 154 155 156 157 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 153 def right_click obj, type = find_element object_not_found_exception(obj, type) page.driver.browser.action.context_click(obj.native).perform end |
#role ⇒ String
Return state of UI object's role property
766 767 768 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 766 def role get_attribute('role') end |
#scroll_to(position) ⇒ Object
Scroll the object to its top, middle, or bottom
178 179 180 181 182 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 178 def scroll_to(position) obj, type = find_element object_not_found_exception(obj, type) page.scroll_to(obj, align: position) end |
#send_keys(*keys) ⇒ Object
Send keystrokes to this object.
196 197 198 199 200 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 196 def send_keys(*keys) obj, type = find_element object_not_found_exception(obj, type) obj.send_keys(*keys) end |
#set(value) ⇒ Object
184 185 186 187 188 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 184 def set(value) obj, type = find_element object_not_found_exception(obj, type) obj.set(value) end |
#set_alt_locator(temp_locator) ⇒ Object
114 115 116 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 114 def set_alt_locator(temp_locator) @alt_locator = temp_locator end |
#set_locator_type(locator = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 73 def set_locator_type(locator = nil) locator = @locator if locator.nil? is_xpath = XPATH_SELECTORS.any? { |selector| locator.include?(selector) } is_css = CSS_SELECTORS.any? { |selector| locator.include?(selector) } @locator_type = if is_xpath && !is_css :xpath elsif is_css && !is_xpath :css elsif !is_css && !is_xpath :css else :css end end |
#style ⇒ String
Return UI object's style property
756 757 758 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 756 def style get_attribute('style') end |
#tabindex ⇒ String
Return state of UI object's tabindex property
776 777 778 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 776 def tabindex get_attribute('tabindex') end |
#title ⇒ String
Return UI object's title property
546 547 548 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 546 def title get_attribute(:title) end |
#unhighlight ⇒ Object
Restore a highlighted object's original style
717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 717 def unhighlight obj, type = find_element object_not_found_exception(obj, type) return if @original_style.nil? page.execute_script( 'arguments[0].setAttribute(arguments[1], arguments[2])', obj, 'style', @original_style ) end |
#verify_value(expected, enqueue = false) ⇒ Object Also known as: verify_caption
619 620 621 622 623 624 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 619 def verify_value(expected, enqueue = false) actual = get_value enqueue ? ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected UI #{object_ref_message}") : assert_equal(expected.strip, actual.strip, "Expected UI #{object_ref_message} to display '#{expected}' but found '#{actual}'") end |
#visible? ⇒ Boolean
Is UI object visible?
219 220 221 222 223 224 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 219 def visible? obj, = find_element exists = obj # the object is visible if it exists and it is not invisible exists && obj.visible? end |
#wait_until_enabled(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is enabled, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 391 def wait_until_enabled(seconds = nil, post_exception = true) timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache enabled? end rescue StandardError if post_exception raise "UI #{object_ref_message} remained disabled after #{timeout} seconds" unless enabled? else enabled? end end |
#wait_until_exists(seconds = nil, post_exception = true) ⇒ Object
Wait until the object exists, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 303 def wait_until_exists(seconds = nil, post_exception = true) timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache exists? end rescue StandardError if post_exception raise "Could not find UI #{object_ref_message} after #{timeout} seconds" unless exists? else exists? end end |
#wait_until_gone(seconds = nil, post_exception = true) ⇒ Object
Wait until the object no longer exists, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 325 def wait_until_gone(seconds = nil, post_exception = true) timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache !exists? end rescue StandardError if post_exception raise "UI #{object_ref_message} remained visible after #{timeout} seconds" if exists? else exists? end end |
#wait_until_hidden(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is hidden, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 369 def wait_until_hidden(seconds = nil, post_exception = true) timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache hidden? end rescue StandardError if post_exception raise "UI #{object_ref_message} remained visible after #{timeout} seconds" if visible? else visible? end end |
#wait_until_value_changes(seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value changes to a different value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 460 def wait_until_value_changes(seconds = nil, post_exception = true) value = get_value timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache get_value != value end rescue StandardError if post_exception raise "Value of UI #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_value == value else get_value == value end end |
#wait_until_value_is(value, seconds = nil, post_exception = true) ⇒ Object
Wait until the object's value equals the specified value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 438 def wait_until_value_is(value, seconds = nil, post_exception = true) timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache compare(value, get_value) end rescue StandardError if post_exception raise "Value of UI #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value else get_value == value end end |
#wait_until_visible(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is visible, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 347 def wait_until_visible(seconds = nil, post_exception = true) timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache visible? end rescue StandardError if post_exception raise "Could not find UI #{object_ref_message} after #{timeout} seconds" unless visible? else visible? end end |
#wait_while_busy(seconds = nil, post_exception = true) ⇒ Object
Wait until the object is no longer in a busy state, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 413 def wait_while_busy(seconds = nil, post_exception = true) timeout = seconds.nil? ? .default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache aria_busy? end rescue StandardError if post_exception raise "UI #{object_ref_message} remained in busy state after #{timeout} seconds" if aria_busy? else aria_busy? end end |
#width ⇒ Integer
Return width of object.
498 499 500 501 502 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 498 def width obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.get_width end |
#x ⇒ Integer
Return x coordinate of object's location.
522 523 524 525 526 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 522 def x obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.get_x end |
#y ⇒ Integer
Return y coordinate of object's location.
534 535 536 537 538 |
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 534 def y obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.get_y end |