Class: TestCentricity::Elements::Image
- Defined in:
- lib/testcentricity_web/web_elements/image.rb
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
-
#alt ⇒ String
Return image alt property.
-
#broken? ⇒ Boolean
Is image broken?.
-
#initialize(name, parent, locator, context) ⇒ Image
constructor
A new instance of Image.
-
#loaded? ⇒ Boolean
(also: #is_loaded?)
Is image loaded?.
-
#src ⇒ String
Return image src property.
-
#wait_until_loaded(seconds = nil, post_exception = true) ⇒ Object
Wait until the image is fully loaded, or until the specified wait time has expired.
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) ⇒ Image
Returns a new instance of Image.
4 5 6 7 |
# File 'lib/testcentricity_web/web_elements/image.rb', line 4 def initialize(name, parent, locator, context) super @type = :image end |
Instance Method Details
#alt ⇒ String
Return image alt property
67 68 69 70 71 |
# File 'lib/testcentricity_web/web_elements/image.rb', line 67 def alt obj, = find_element object_not_found_exception(obj, nil) obj.native.attribute('alt') end |
#broken? ⇒ Boolean
Is image broken?
30 31 32 33 34 35 36 37 38 |
# File 'lib/testcentricity_web/web_elements/image.rb', line 30 def broken? obj, = find_element object_not_found_exception(obj, nil) result = page.execute_script( 'return arguments[0].complete && typeof arguments[0].naturalWidth != "undefined" && arguments[0].naturalWidth > 0', obj ) !result end |
#loaded? ⇒ Boolean Also known as: is_loaded?
Is image loaded?
15 16 17 18 19 20 |
# File 'lib/testcentricity_web/web_elements/image.rb', line 15 def loaded? obj, = find_element object_not_found_exception(obj, nil) state = obj.native.attribute('complete') state.boolean? ? state : state == 'true' end |
#src ⇒ String
Return image src property
79 80 81 82 83 |
# File 'lib/testcentricity_web/web_elements/image.rb', line 79 def src obj, = find_element object_not_found_exception(obj, nil) obj.native.attribute('src') end |
#wait_until_loaded(seconds = nil, post_exception = true) ⇒ Object
Wait until the image is fully loaded, or until the specified wait time has expired.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/testcentricity_web/web_elements/image.rb', line 46 def wait_until_loaded(seconds = nil, post_exception = true) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until do reset_mru_cache is_loaded? end rescue if post_exception raise "Image #{} failed to load within #{timeout} seconds" unless loaded? else loaded? end end |