Class: TestCentricity::Elements::UIElement

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL, Test::Unit::Assertions
Defined in:
lib/testcentricity_web/web_elements/ui_element.rb

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

Instance Method Summary collapse

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_locatorObject

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_objectObject

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

#contextObject (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

#locatorObject (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_typeObject

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_locatorObject

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_objectObject

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_parentObject

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

#nameObject (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_styleObject

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

#parentObject (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

#typeObject (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_autocompleteInteger

Return state of UI object's aria-autocomplete property

Examples:

email_field.aria_autocomplete

Returns:

  • (Integer)


863
864
865
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 863

def aria_autocomplete
  get_attribute('aria-autocomplete')
end

#aria_busy?Boolean

Return state of UI object's aria-busy property

Examples:

home_phone_field.aria_busy?

Returns:

  • (Boolean)


993
994
995
996
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 993

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

Examples:

allow_new_users_checkbox.aria_checked?

Returns:

  • (Boolean)


949
950
951
952
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 949

def aria_checked?
  state = get_attribute('aria-checked')
  state.boolean? ? state : state == 'true'
end

#aria_colcountInteger

Return state of UI object's aria-colcount property

Examples:

user_grid.aria_colcount

Returns:

  • (Integer)


783
784
785
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 783

def aria_colcount
  get_attribute('aria-colcount')
end

#aria_controlsInteger

Return state of UI object's aria-controls property

Examples:

video_menu.aria_controls

Returns:

  • (Integer)


873
874
875
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 873

def aria_controls
  get_attribute('aria-controls')
end

#aria_describedbyString

Return state of UI object's aria-describedby property

Examples:

buy_now_button.aria_describedby

Returns:



743
744
745
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 743

def aria_describedby
  get_attribute('aria-describedby')
end

#aria_disabled?Boolean

Return state of UI object's aria-disabled property

Examples:

buy_now_button.aria_disabled?

Returns:

  • (Boolean)


883
884
885
886
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 883

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

Examples:

catalog_tree.aria_expanded?

Returns:

  • (Boolean)


916
917
918
919
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 916

def aria_expanded?
  state = get_attribute('aria-expanded')
  state.boolean? ? state : state == 'true'
end

#aria_haspopup?Boolean

Return state of UI object's aria-haspopup property

Examples:

user_avatar.aria_haspopup?

Returns:

  • (Boolean)


960
961
962
963
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 960

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

Examples:

nutrition_info_tab.aria_hidden?

Returns:

  • (Boolean)


905
906
907
908
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 905

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

Examples:

home_phone_field.aria_invalid?

Returns:

  • (Boolean)


938
939
940
941
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 938

def aria_invalid?
  state = get_attribute('aria-invalid')
  state.boolean? ? state : state == 'true'
end

#aria_keyshortcutsInteger

Return state of UI object's aria-keyshortcuts property

Examples:

play_button.aria_keyshortcuts

Returns:

  • (Integer)


843
844
845
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 843

def aria_keyshortcuts
  get_attribute('aria-keyshortcuts')
end

#aria_labelString

Return state of UI object's aria-label property

Examples:

buy_now_button.aria_label

Returns:



723
724
725
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 723

def aria_label
  get_attribute('aria-label')
end

#aria_labelledbyString

Return state of UI object's aria-labelledby property

Examples:

buy_now_button.aria_labelledby

Returns:



733
734
735
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 733

def aria_labelledby
  get_attribute('aria-labelledby')
end

#aria_liveString

Return state of UI object's aria-live property

Examples:

properties_list.aria_live

Returns:



753
754
755
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 753

def aria_live
  get_attribute('aria-live')
end

#aria_modal?Boolean

Return state of UI object's aria-modal property

Examples:

add_user_modal.aria_modal?

Returns:

  • (Boolean)


1004
1005
1006
1007
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1004

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

Examples:

description_field.aria_multiline?

Returns:

  • (Boolean)


1015
1016
1017
1018
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1015

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

Examples:

channels_select.aria_multiselectable?

Returns:

  • (Boolean)


1026
1027
1028
1029
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1026

def aria_multiselectable?
  state = get_attribute('aria-multiselectable')
  state.boolean? ? state : state == 'true'
end

#aria_orientationInteger

Return state of UI object's aria-orientation property

Examples:

volume_slider.aria_orientation

Returns:

  • (Integer)


833
834
835
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 833

def aria_orientation
  get_attribute('aria-orientation')
end

#aria_pressed?Boolean

Return state of UI object's aria-pressed property

Examples:

option1_button.aria_pressed?

Returns:

  • (Boolean)


971
972
973
974
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 971

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

Examples:

home_phone_field.aria_readonly?

Returns:

  • (Boolean)


982
983
984
985
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 982

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

Examples:

home_phone_field.aria_required?

Returns:

  • (Boolean)


927
928
929
930
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 927

def aria_required?
  state = get_attribute('aria-required')
  state.boolean? ? state : state == 'true'
end

#aria_roledescriptionInteger

Return state of UI object's aria-roledescription property

Examples:

editor_button.aria_roledescription

Returns:

  • (Integer)


853
854
855
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 853

def aria_roledescription
  get_attribute('aria-roledescription')
end

#aria_rowcountInteger

Return state of UI object's aria-rowcount property

Examples:

user_grid.aria_rowcount

Returns:

  • (Integer)


773
774
775
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 773

def aria_rowcount
  get_attribute('aria-rowcount')
end

#aria_selected?Boolean

Return state of UI object's aria-selected property

Examples:

nutrition_info_tab.aria_selected?

Returns:

  • (Boolean)


894
895
896
897
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 894

def aria_selected?
  state = get_attribute('aria-selected')
  state.boolean? ? state : state == 'true'
end

#aria_sortString

Return state of UI object's aria-sort property

Examples:

name_column.aria_sort

Returns:



763
764
765
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 763

def aria_sort
  get_attribute('aria-sort')
end

#aria_valuemaxInteger

Return state of UI object's aria-valuemax property

Examples:

volume_slider.aria_valuemax

Returns:

  • (Integer)


793
794
795
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 793

def aria_valuemax
  get_attribute('aria-valuemax')
end

#aria_valueminInteger

Return state of UI object's aria-valuemin property

Examples:

volume_slider.aria_valuemin

Returns:

  • (Integer)


803
804
805
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 803

def aria_valuemin
  get_attribute('aria-valuemin')
end

#aria_valuenowInteger

Return state of UI object's aria-valuenow property

Examples:

volume_slider.aria_valuenow

Returns:

  • (Integer)


813
814
815
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 813

def aria_valuenow
  get_attribute('aria-valuenow')
end

#aria_valuetextInteger

Return state of UI object's aria-valuetext property

Examples:

volume_slider.aria_valuetext

Returns:

  • (Integer)


823
824
825
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 823

def aria_valuetext
  get_attribute('aria-valuetext')
end

#clear_alt_locatorObject



117
118
119
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 117

def clear_alt_locator
  @alt_locator = nil
end

#clickObject

Click on an object

Examples:

basket_link.click


126
127
128
129
130
131
132
133
134
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 126

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

Examples:

basket_item_image.click_at(10, 10)

Parameters:

  • x (Integer)

    X offset

  • y (Integer)

    Y offset



165
166
167
168
169
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 165

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

Examples:

description_field.content_editable?

Returns:

  • (Boolean)


1037
1038
1039
1040
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1037

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.

Examples:

num_uploads = upload_progress_bars.count(:all)

Parameters:

  • visible (Boolean, Symbol) (defaults to: true)

    Only find elements with the specified visibility:

    • true - only finds visible elements.
    • false - finds invisible and visible elements.
    • :all - same as false; finds visible and invisible elements.
    • :hidden - only finds invisible elements.
    • :visible - same as true; only finds visible elements.


486
487
488
489
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 486

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

#crossoriginObject

Return crossorigin property

Examples:

with_creds = media_player.crossorigin == 'use-credentials'

Returns:

  • crossorigin value



1048
1049
1050
1051
1052
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1048

def crossorigin
  obj, = find_element
  object_not_found_exception(obj, @type)
  obj.native.attribute('crossorigin')
end

#disabled?Boolean

Is UI object disabled (not enabled)?

Examples:

.disabled?

Returns:

  • (Boolean)


251
252
253
254
255
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 251

def disabled?
  obj, type = find_element
  object_not_found_exception(obj, type)
  obj.disabled?
end

#displayed?Boolean

Is UI object displayed in browser window?

Examples:

basket_link.displayed??

Returns:

  • (Boolean)


555
556
557
558
559
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 555

def displayed?
  obj, type = find_element(visible = false)
  object_not_found_exception(obj, type)
  obj.displayed?
end

#double_clickObject

Double-click on an object

Examples:

file_image.double_click


141
142
143
144
145
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 141

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



630
631
632
633
634
635
636
637
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 630

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



622
623
624
625
626
627
628
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 622

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?

Examples:

.enabled?

Returns:

  • (Boolean)


241
242
243
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 241

def enabled?
  !disabled?
end

#exists?(visible = true) ⇒ Boolean

Does UI object exists?

Examples:

basket_link.exists?

Returns:

  • (Boolean)


207
208
209
210
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 207

def exists?(visible = true)
  obj, = find_object(visible)
  !obj.nil?
end

#find_element(visible = true) ⇒ Object



1067
1068
1069
1070
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1067

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?

Examples:

first_name_field.focused?

Returns:

  • (Boolean)


288
289
290
291
292
293
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 288

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



1054
1055
1056
1057
1058
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1054

def get_attribute(attrib)
  obj, type = find_element(visible = false)
  object_not_found_exception(obj, type)
  obj[attrib]
end

#get_locatorObject



105
106
107
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 105

def get_locator
  @locator
end

#get_locator_typeObject



87
88
89
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 87

def get_locator_type
  @locator_type
end

#get_nameObject



109
110
111
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 109

def get_name
  @name
end

#get_native_attribute(attrib) ⇒ Object



1060
1061
1062
1063
1064
1065
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 1060

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_typeObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 91

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



561
562
563
564
565
566
567
568
569
570
571
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 561

def get_value(visible = true)
  obj, type = find_element(visible)
  object_not_found_exception(obj, type)
  text = case obj.tag_name.downcase
         when 'input', 'select', 'textarea'
           obj.value
         else
           obj.text
         end
  text.gsub(/[[:space:]]+/, ' ').strip unless text.nil?
end

#heightInteger

Return height of object.

Examples:

button_height = my_button.height

Returns:

  • (Integer)


509
510
511
512
513
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 509

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

Examples:

remember_me_checkbox.hidden?

Returns:

  • (Boolean)


231
232
233
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 231

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

Examples:

error_message.highlight(3)

Parameters:

  • duration (Integer or Float) (defaults to: 1)

    wait time in seconds



646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 646

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

Examples:

basket_link.hover

Parameters:

  • visible (Boolean, Symbol) (defaults to: true)

    Only find elements with the specified visibility:

    • true - only finds visible elements.
    • false - finds invisible and visible elements.
    • :all - same as false; finds visible and invisible elements.
    • :hidden - only finds invisible elements.
    • :visible - same as true; only finds visible elements.


597
598
599
600
601
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 597

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

Examples:

timeline_bar.hover_at(100, 5)

Parameters:

  • x (Integer)

    X offset

  • y (Integer)

    Y offset

  • visible (Boolean, Symbol) (defaults to: true)

    Only find elements with the specified visibility:

    • true - only finds visible elements.
    • false - finds invisible and visible elements.
    • :all - same as false; finds visible and invisible elements.
    • :hidden - only finds invisible elements.
    • :visible - same as true; only finds visible elements.


616
617
618
619
620
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 616

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

Examples:

buy_now_button.obscured?

Returns:

  • (Boolean)


276
277
278
279
280
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 276

def obscured?
  obj, type = find_element
  object_not_found_exception(obj, type)
  obj.obscured?
end

#required?Boolean

Is UI object's required attribute set?

Examples:

first_name_field.required?

Returns:

  • (Boolean)


263
264
265
266
267
268
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 263

def required?
  obj, type = find_element
  object_not_found_exception(obj, type)
  state = get_attribute(:required)
  state.boolean? ? state : state == 'true'
end

#reset_mru_cacheObject



66
67
68
69
70
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 66

def reset_mru_cache
  @mru_object = nil
  @mru_locator = nil
  @mru_parent = nil
end

#right_clickObject

Right-click on an object

Examples:

basket_item_image.right_click


152
153
154
155
156
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 152

def right_click
  obj, type = find_element
  object_not_found_exception(obj, type)
  page.driver.browser.action.context_click(obj.native).perform
end

#roleString

Return state of UI object's role property

Examples:

buy_now_button.role

Returns:



703
704
705
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 703

def role
  get_attribute('role')
end

#scroll_to(position) ⇒ Object

Scroll the object to its top, middle, or bottom

Examples:

cue_list.scroll_to(:bottom)

Parameters:

  • position (Symbol)

    :top, :bottom, :center



177
178
179
180
181
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 177

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.

Examples:

comment_field.send_keys(:enter)

Parameters:



195
196
197
198
199
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 195

def send_keys(*keys)
  obj, type = find_element
  object_not_found_exception(obj, type)
  obj.send_keys(*keys)
end

#set(value) ⇒ Object



183
184
185
186
187
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 183

def set(value)
  obj, type = find_element
  object_not_found_exception(obj, type)
  obj.set(value)
end

#set_alt_locator(temp_locator) ⇒ Object



113
114
115
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 113

def set_alt_locator(temp_locator)
  @alt_locator = temp_locator
end

#set_locator_type(locator = nil) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 72

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

#styleString

Return UI object's style property

Examples:

buy_now_button.style

Returns:



693
694
695
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 693

def style
  get_attribute('style')
end

#tabindexString

Return state of UI object's tabindex property

Examples:

buy_now_button.tabindex

Returns:



713
714
715
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 713

def tabindex
  get_attribute('tabindex')
end

#titleString

Return UI object's title property

Examples:

buy_now_button.title

Returns:



545
546
547
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 545

def title
  get_attribute(:title)
end

#unhighlightObject

Restore a highlighted object's original style

Examples:

store_link.unhighlight


675
676
677
678
679
680
681
682
683
684
685
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 675

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



577
578
579
580
581
582
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 577

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?

Examples:

remember_me_checkbox.visible?

Returns:

  • (Boolean)


218
219
220
221
222
223
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 218

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.

Examples:

run_button.wait_until_enabled(10)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 390

def wait_until_enabled(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
    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.

Examples:

run_button.wait_until_exists(0.5)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 302

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 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.

Examples:

logout_button.wait_until_gone(5)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 324

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 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.

Examples:

run_button.wait_until_hidden(10)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/testcentricity_web/web_elements/ui_element.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 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.

Examples:

basket_grand_total_label.wait_until_value_changes(5)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 459

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 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.

Examples:

card_authorized_label.wait_until_value_is('Card authorized', 5)
  or
total_weight_field.wait_until_value_is({ greater_than: '250' }, 5)

Parameters:

  • value (String or Hash)

    value expected or comparison hash

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 437

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 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.

Examples:

run_button.wait_until_visible(0.5)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 346

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 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.

Examples:

.wait_while_busy(10)

Parameters:

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 412

def wait_while_busy(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
    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

#widthInteger

Return width of object.

Examples:

button_width = my_button.width

Returns:

  • (Integer)


497
498
499
500
501
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 497

def width
  obj, type = find_element(visible = false)
  object_not_found_exception(obj, type)
  obj.get_width
end

#xInteger

Return x coordinate of object's location.

Examples:

button_x = my_button.x

Returns:

  • (Integer)


521
522
523
524
525
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 521

def x
  obj, type = find_element(visible = false)
  object_not_found_exception(obj, type)
  obj.get_x
end

#yInteger

Return y coordinate of object's location.

Examples:

button_y = my_button.y

Returns:

  • (Integer)


533
534
535
536
537
# File 'lib/testcentricity_web/web_elements/ui_element.rb', line 533

def y
  obj, type = find_element(visible = false)
  object_not_found_exception(obj, type)
  obj.get_y
end