Class: TestCentricity::UIElement
- Includes:
- Capybara::DSL, Test::Unit::Assertions
- Defined in:
- lib/testcentricity_web/web_elements/ui_elements_helper.rb
Direct Known Subclasses
Button, CheckBox, FileField, Image, Label, Link, List, Media, Radio, SelectList, Table, TextField
Constant Summary collapse
- XPATH_SELECTORS =
['//', '[@', '[contains(']
- CSS_SELECTORS =
['#', ':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.
-
#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 ⇒ Integer
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 ⇒ Integer
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 ⇒ Integer
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 ⇒ Integer
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 ⇒ Integer
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 ⇒ Integer
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.
-
#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
-
#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_name ⇒ Object
- #get_native_attribute(attrib) ⇒ Object
- #get_object_type ⇒ Object
- #get_value(visible = true) ⇒ Object (also: #get_caption, #caption, #value)
-
#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.
-
#inspect ⇒ String
Return a human readable representation of the UI element.
-
#obscured? ⇒ Boolean
Is UI object obscured (not currently in viewport and not clickable)?.
-
#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_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.
-
#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.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 52 def initialize(name, parent, locator, context) @name = name @parent = parent @locator = locator @context = context @type = nil @alt_locator = nil @original_style = nil set_locator_type end |
Instance Attribute Details
#alt_locator ⇒ Object
Returns the value of attribute alt_locator.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 46 def alt_locator @alt_locator end |
#base_object ⇒ Object
Returns the value of attribute base_object.
47 48 49 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 47 def base_object @base_object end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
45 46 47 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 45 def context @context end |
#locator ⇒ Object (readonly)
Returns the value of attribute locator.
45 46 47 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 45 def locator @locator end |
#locator_type ⇒ Object
Returns the value of attribute locator_type.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 46 def locator_type @locator_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 45 def name @name end |
#original_style ⇒ Object
Returns the value of attribute original_style.
46 47 48 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 46 def original_style @original_style end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
45 46 47 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 45 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
45 46 47 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 45 def type @type end |
Instance Method Details
#aria_autocomplete ⇒ Integer
Return state of UI object's aria-autocomplete property
809 810 811 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 809 def aria_autocomplete get_attribute('aria-autocomplete') end |
#aria_busy? ⇒ Boolean
Return state of UI object's aria-busy property
939 940 941 942 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 939 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
895 896 897 898 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 895 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
729 730 731 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 729 def aria_colcount get_attribute('aria-colcount') end |
#aria_controls ⇒ Integer
Return state of UI object's aria-controls property
819 820 821 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 819 def aria_controls get_attribute('aria-controls') end |
#aria_describedby ⇒ String
Return state of UI object's aria-describedby property
689 690 691 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 689 def aria_describedby get_attribute('aria-describedby') end |
#aria_disabled? ⇒ Boolean
Return state of UI object's aria-disabled property
829 830 831 832 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 829 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
862 863 864 865 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 862 def state = get_attribute('aria-expanded') state.boolean? ? state : state == 'true' end |
#aria_haspopup? ⇒ Boolean
Return state of UI object's aria-haspopup property
906 907 908 909 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 906 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
851 852 853 854 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 851 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
884 885 886 887 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 884 def aria_invalid? state = get_attribute('aria-invalid') state.boolean? ? state : state == 'true' end |
#aria_keyshortcuts ⇒ Integer
Return state of UI object's aria-keyshortcuts property
789 790 791 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 789 def aria_keyshortcuts get_attribute('aria-keyshortcuts') end |
#aria_label ⇒ String
Return state of UI object's aria-label property
669 670 671 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 669 def aria_label get_attribute('aria-label') end |
#aria_labelledby ⇒ String
Return state of UI object's aria-labelledby property
679 680 681 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 679 def aria_labelledby get_attribute('aria-labelledby') end |
#aria_live ⇒ String
Return state of UI object's aria-live property
699 700 701 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 699 def aria_live get_attribute('aria-live') end |
#aria_modal? ⇒ Boolean
Return state of UI object's aria-modal property
950 951 952 953 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 950 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
961 962 963 964 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 961 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
972 973 974 975 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 972 def aria_multiselectable? state = get_attribute('aria-multiselectable') state.boolean? ? state : state == 'true' end |
#aria_orientation ⇒ Integer
Return state of UI object's aria-orientation property
779 780 781 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 779 def aria_orientation get_attribute('aria-orientation') end |
#aria_pressed? ⇒ Boolean
Return state of UI object's aria-pressed property
917 918 919 920 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 917 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
928 929 930 931 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 928 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
873 874 875 876 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 873 def aria_required? state = get_attribute('aria-required') state.boolean? ? state : state == 'true' end |
#aria_roledescription ⇒ Integer
Return state of UI object's aria-roledescription property
799 800 801 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 799 def aria_roledescription get_attribute('aria-roledescription') end |
#aria_rowcount ⇒ Integer
Return state of UI object's aria-rowcount property
719 720 721 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 719 def aria_rowcount get_attribute('aria-rowcount') end |
#aria_selected? ⇒ Boolean
Return state of UI object's aria-selected property
840 841 842 843 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 840 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
709 710 711 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 709 def aria_sort get_attribute('aria-sort') end |
#aria_valuemax ⇒ Integer
Return state of UI object's aria-valuemax property
739 740 741 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 739 def aria_valuemax get_attribute('aria-valuemax') end |
#aria_valuemin ⇒ Integer
Return state of UI object's aria-valuemin property
749 750 751 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 749 def aria_valuemin get_attribute('aria-valuemin') end |
#aria_valuenow ⇒ Integer
Return state of UI object's aria-valuenow property
759 760 761 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 759 def aria_valuenow get_attribute('aria-valuenow') end |
#aria_valuetext ⇒ Integer
Return state of UI object's aria-valuetext property
769 770 771 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 769 def aria_valuetext get_attribute('aria-valuetext') end |
#clear_alt_locator ⇒ Object
108 109 110 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 108 def clear_alt_locator @alt_locator = nil end |
#click ⇒ Object
Click on an object
117 118 119 120 121 122 123 124 125 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 117 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
156 157 158 159 160 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 156 def click_at(x, y) obj, = find_element raise "UI #{} not found" unless obj obj.click_at(x, y) end |
#content_editable? ⇒ Boolean
Return state of UI object's contenteditable property
983 984 985 986 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 983 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.
433 434 435 436 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 433 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 |
#disabled? ⇒ Boolean
Is UI object disabled (not enabled)?
261 262 263 264 265 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 261 def disabled? obj, type = find_element object_not_found_exception(obj, type) obj.disabled? end |
#displayed? ⇒ Boolean
Is UI object displayed in browser window?
502 503 504 505 506 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 502 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
132 133 134 135 136 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 132 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
576 577 578 579 580 581 582 583 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 576 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
568 569 570 571 572 573 574 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 568 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 |
#enabled? ⇒ Boolean
Is UI object enabled?
251 252 253 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 251 def enabled? !disabled? end |
#exists?(visible = true) ⇒ Boolean
Does UI object exists?
198 199 200 201 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 198 def exists?(visible = true) obj, = find_object(visible) !obj.nil? end |
#find_element(visible = true) ⇒ Object
1000 1001 1002 1003 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 1000 def find_element(visible = true) wait = Selenium::WebDriver::Wait.new(timeout: Capybara.default_max_wait_time) wait.until { find_object(visible) } end |
#focused? ⇒ Boolean
Does UI object have the current focus?
285 286 287 288 289 290 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 285 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
988 989 990 991 992 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 988 def get_attribute(attrib) obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj[attrib] end |
#get_locator ⇒ Object
96 97 98 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 96 def get_locator @locator end |
#get_locator_type ⇒ Object
78 79 80 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 78 def get_locator_type @locator_type end |
#get_name ⇒ Object
100 101 102 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 100 def get_name @name end |
#get_native_attribute(attrib) ⇒ Object
994 995 996 997 998 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 994 def get_native_attribute(attrib) obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.native.attribute(attrib) end |
#get_object_type ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 82 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: value , ,
508 509 510 511 512 513 514 515 516 517 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 508 def get_value(visible = true) obj, type = find_element(visible) object_not_found_exception(obj, type) case obj.tag_name.downcase when 'input', 'select', 'textarea' obj.value else obj.text end end |
#height ⇒ Integer
Return height of object.
456 457 458 459 460 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 456 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)?
241 242 243 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 241 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
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 592 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
543 544 545 546 547 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 543 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
562 563 564 565 566 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 562 def hover_at(x, y, visible = true) obj, = find_element(visible) raise "UI #{} not found" unless obj obj.hover_at(x, y) end |
#inspect ⇒ String
Return a human readable representation of the UI element
298 299 300 301 302 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 298 def inspect obj, type = find_element object_not_found_exception(obj, type) obj.inspect end |
#obscured? ⇒ Boolean
Is UI object obscured (not currently in viewport and not clickable)?
273 274 275 276 277 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 273 def obscured? obj, type = find_element object_not_found_exception(obj, type) obj.obscured? end |
#right_click ⇒ Object
Right-click on an object
143 144 145 146 147 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 143 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
649 650 651 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 649 def role get_attribute('role') end |
#scroll_to(position) ⇒ Object
Scroll the object to its top, middle, or bottom
168 169 170 171 172 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 168 def scroll_to(position) obj, type = find_element object_not_found_exception(obj, type) obj.scroll_to(position) end |
#send_keys(*keys) ⇒ Object
Send keystrokes to this object.
186 187 188 189 190 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 186 def send_keys(*keys) obj, type = find_element object_not_found_exception(obj, type) obj.send_keys(*keys) end |
#set(value) ⇒ Object
174 175 176 177 178 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 174 def set(value) obj, type = find_element object_not_found_exception(obj, type) obj.set(value) end |
#set_alt_locator(temp_locator) ⇒ Object
104 105 106 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 104 def set_alt_locator(temp_locator) @alt_locator = temp_locator end |
#set_locator_type(locator = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 63 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
639 640 641 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 639 def style get_attribute('style') end |
#tabindex ⇒ String
Return state of UI object's tabindex property
659 660 661 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 659 def tabindex get_attribute('tabindex') end |
#title ⇒ String
Return UI object's title property
492 493 494 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 492 def title get_attribute(:title) end |
#unhighlight ⇒ Object
Restore a highlighted object's original style
621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 621 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:
523 524 525 526 527 528 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 523 def verify_value(expected, enqueue = false) actual = get_value enqueue ? ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected UI #{}") : assert_equal(expected.strip, actual.strip, "Expected UI #{} to display '#{expected}' but found '#{actual}'") end |
#visible? ⇒ Boolean
Is UI object visible?
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 209 def visible? obj, type = find_element exists = obj invisible = false if type == :css Capybara.using_wait_time 0.1 do # is object itself hidden with .ui-helper-hidden class? self_hidden = page.has_css?("#{@locator}.ui-helper-hidden") # is parent of object hidden, thus hiding the object? parent_hidden = page.has_css?(".ui-helper-hidden > #{@locator}") # is grandparent of object, or any other ancestor, hidden? other_ancestor_hidden = page.has_css?(".ui-helper-hidden * #{@locator}") # if any of the above conditions are true, then object is invisible invisible = self_hidden || parent_hidden || other_ancestor_hidden end else invisible = !obj.visible? if exists end # the object is visible if it exists and it is not invisible if exists && !invisible true else false 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.
311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 311 def wait_until_exists(seconds = nil, post_exception = true) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { exists? } rescue StandardError if post_exception raise "Could not find UI #{} 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.
330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 330 def wait_until_gone(seconds = nil, post_exception = true) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { !exists? } rescue StandardError if post_exception raise "UI #{} 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.
368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 368 def wait_until_hidden(seconds = nil, post_exception = true) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { hidden? } rescue StandardError if post_exception raise "UI #{} 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.
409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 409 def wait_until_value_changes(seconds = nil, post_exception = true) value = get_value timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { get_value != value } rescue StandardError if post_exception raise "Value of UI #{} 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.
390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 390 def wait_until_value_is(value, seconds = nil, post_exception = true) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { compare(value, get_value) } rescue StandardError if post_exception raise "Value of UI #{} 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.
349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 349 def wait_until_visible(seconds = nil, post_exception = true) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { visible? } rescue StandardError if post_exception raise "Could not find UI #{} after #{timeout} seconds" unless visible? else visible? end end |
#width ⇒ Integer
Return width of object.
444 445 446 447 448 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 444 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.
468 469 470 471 472 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 468 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.
480 481 482 483 484 |
# File 'lib/testcentricity_web/web_elements/ui_elements_helper.rb', line 480 def y obj, type = find_element(visible = false) object_not_found_exception(obj, type) obj.get_y end |