Class: TestCentricity::AppElements::AppUIElement

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Assertions
Defined in:
lib/testcentricity_apps/app_elements/app_element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent, locator, context) ⇒ AppUIElement

Returns a new instance of AppUIElement.



19
20
21
22
23
24
25
26
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 19

def initialize(name, parent, locator, context)
  @name = name
  @parent = parent
  @locator = locator
  @context = context
  @type = nil
  reset_mru_cache
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



16
17
18
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 16

def context
  @context
end

#locatorObject (readonly)

Returns the value of attribute locator.



16
17
18
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 16

def locator
  @locator
end

#mru_app_sessionObject

Returns the value of attribute mru_app_session.



17
18
19
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 17

def mru_app_session
  @mru_app_session
end

#mru_locatorObject

Returns the value of attribute mru_locator.



17
18
19
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 17

def mru_locator
  @mru_locator
end

#mru_objectObject

Returns the value of attribute mru_object.



17
18
19
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 17

def mru_object
  @mru_object
end

#mru_parentObject

Returns the value of attribute mru_parent.



17
18
19
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 17

def mru_parent
  @mru_parent
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 16

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



16
17
18
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 16

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



16
17
18
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 16

def type
  @type
end

Instance Method Details

#clearObject



80
81
82
83
84
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 80

def clear
  obj = element
  object_not_found_exception(obj)
  obj.clear
end

#clickObject

Click on a UI element

Examples:

.click


458
459
460
461
462
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 458

def click
  obj = element
  object_not_found_exception(obj)
  obj.click
end

#countInteger

Return the number of occurrences of an object with an ambiguous locator that evaluates to multiple UI elements.

Examples:

num_items = store_item.count

Returns:

  • (Integer)


448
449
450
451
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 448

def count
  objs = find_elements(@locator.keys[0], @locator.values[0])
  objs.count
end

#disabled?Boolean

Is UI object disabled (not enabled)?

Examples:

refresh_button.disabled?

Returns:

  • (Boolean)


220
221
222
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 220

def disabled?
  !enabled?
end

#double_tapObject

Double-tap on a UI element

Examples:

refresh_chart_button.double_tap


483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 483

def double_tap
  obj = element
  object_not_found_exception(obj)
  if Environ.is_macos?
    Environ.appium_driver.execute_script('macos: doubleClick', { elementId: cell_obj.id })
  else
    driver.action
          .click_and_hold(obj)
          .release
          .pause(duration: 0.2)
          .click_and_hold(obj)
          .release
          .perform
  end
end

#drag_and_drop(target, duration = 0.3) ⇒ Object

Drag the UI object to the specified target object. If the optional duration parameter is not specified, the duration defaults to 0.3 seconds (300 milliseconds).

Examples:

puzzle_21_piece.drag_and_drop(puzzle_21_slot)

Parameters:

  • target (String)

    target object to drag to

  • duration (Float) (defaults to: 0.3)

    OPTIONAL duration of drag in seconds



577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 577

def drag_and_drop(target, duration = 0.3)
  drag = element
  object_not_found_exception(drag)
  drop = target.element
  drag_x = drag.location.x
  drag_y = drag.location.y
  drop_x = drop.location.x
  drop_y = drop.location.y
  driver.action
        .click_and_hold(drag)
        .move_by(drop_x - drag_x, drop_y - drag_y, duration: duration)
        .release
        .perform
end

#drag_by(right_offset, down_offset, duration = 0.3) ⇒ Object

Drag the UI object by the specified offset. If the optional duration parameter is not specified, the duration defaults to 0.3 seconds (300 milliseconds).

Examples:

puzzle_21_piece.drag_by(-100, -300)

Parameters:

  • right_offset (Integer)

    x coordinate offset

  • down_offset (Integer)

    y coordinate offset

  • duration (Float) (defaults to: 0.3)

    OPTIONAL duration of drag in seconds



559
560
561
562
563
564
565
566
567
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 559

def drag_by(right_offset, down_offset, duration = 0.3)
  obj = element
  object_not_found_exception(obj)
  driver.action
        .click_and_hold(obj)
        .move_by(right_offset, down_offset, duration: duration)
        .release
        .perform
end

#elementObject



682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 682

def element
  reset_mru_cache if @mru_app_session != Environ.app_session_id
  obj = if @context == :section
          parent_obj = nil
          parent_locator = @parent.get_locator

          if @mru_locator == @locator && @mru_parent == parent_locator && !@mru_object.nil?
            return @mru_object
          end

          parent_locator.each do |locators|

            if locators.keys[0] == :object
              parent_obj = locators.values[0]
              break
            end

            parent_obj = if parent_obj.nil?
                           find_element(locators.keys[0], locators.values[0])
                         else
                           parent_obj.find_element(locators.keys[0], locators.values[0])
                         end
          end
          puts "Found parent object '#{@parent.get_name}' - #{@parent.get_locator}" if ENV['DEBUG']
          parent_obj.find_element(@locator.keys[0], @locator.values[0])
        else
          return @mru_object if @mru_locator == @locator && !@mru_object.nil?

          find_element(@locator.keys[0], @locator.values[0])
        end
  puts "Found object '#{@name}' - #{@locator}" if ENV['DEBUG']
  @mru_object = obj
  @mru_locator = @locator
  @mru_parent = parent_locator
  @mru_app_session = Environ.app_session_id
  obj
rescue
  puts "Did not find object '#{@name}' - #{@locator}" if ENV['DEBUG']
  nil
end

#enabled?Boolean

Is UI object enabled?

Examples:

.enabled?

Returns:

  • (Boolean)


208
209
210
211
212
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 208

def enabled?
  obj = element
  object_not_found_exception(obj)
  obj.enabled?
end

#exists?Boolean

Does UI object exists?

Examples:

empty_cart_image.exists?

Returns:

  • (Boolean)


166
167
168
169
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 166

def exists?
  obj = element
  !obj.nil?
end

#get_attribute(attrib) ⇒ Object



230
231
232
233
234
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 230

def get_attribute(attrib)
  obj = element
  object_not_found_exception(obj)
  obj.attribute(attrib)
end

#get_captionObject Also known as: caption



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 107

def get_caption
  obj = element
  object_not_found_exception(obj)
  if Environ.is_macos?
    return obj.title
  elsif AppiumConnect.is_webview?
    caption = case obj.tag_name.downcase
              when 'input', 'select', 'textarea'
                obj.value
              else
                obj.text
              end
  elsif Environ.is_ios?
    caption = case obj.tag_name
              when 'XCUIElementTypeNavigationBar'
                obj.attribute(:name)
              else
                obj.attribute(:label)
              end
    caption = '' if caption.nil?
  else
    caption = obj.text
    if caption.blank?
      case obj.attribute(:class)
      when 'android.view.ViewGroup'
        caption_obj = obj.find_element(:xpath, '//android.widget.TextView')
        caption = caption_obj.text
      when 'android.widget.Button'
        caption_obj = obj.find_element(:xpath, '//android.widget.TextView')
        caption = caption_obj.text
        if caption.blank?
          caption_obj = obj.find_element(:xpath, '//android.widget.ViewGroup/android.widget.TextView')
          caption = caption_obj.text
        end
      end
    end
  end

  caption
end

#get_locatorObject



39
40
41
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 39

def get_locator
  @locator
end

#get_nameObject



43
44
45
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 43

def get_name
  @name
end

#get_object_typeObject



35
36
37
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 35

def get_object_type
  @type
end

#get_valueObject Also known as: value



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 86

def get_value
  obj = element
  object_not_found_exception(obj)
  if Environ.is_macos?
    value = obj.value
    value = obj.title if value.nil?
    return value
  elsif AppiumConnect.is_webview?
    case obj.tag_name.downcase
    when 'input', 'select', 'textarea'
      obj.value
    else
      obj.text
    end
  else
    obj.text
  end
end

#heightInteger

Return height of object.

Examples:

button_height = my_button.height

Returns:

  • (Integer)


412
413
414
415
416
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 412

def height
  obj = element
  object_not_found_exception(obj)
  obj.size.height
end

#hidden?Boolean

Is UI object hidden (not visible)?

Examples:

remember_me_checkbox.hidden?

Returns:

  • (Boolean)


198
199
200
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 198

def hidden?
  !visible?
end

#hoverObject

Hover over a UI element. MacOS apps only.

Examples:

chart_image.hover


542
543
544
545
546
547
548
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 542

def hover
  raise "Hover is not supported for #{Environ.device_os} platforms" unless Environ.is_macos?

  obj = element
  object_not_found_exception(obj)
  Environ.appium_driver.execute_script('macos: hover', { elementId: obj.id })
end

#idObject



47
48
49
50
51
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 47

def id
  obj = element
  object_not_found_exception(obj)
  obj.id
end

#identifierObject



150
151
152
153
154
155
156
157
158
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 150

def identifier
  if Environ.is_macos?
    obj = element
    object_not_found_exception(obj)
    obj.identifier
  else
    raise 'identifier is not a supported attribute'
  end
end

#long_press(duration = 1) ⇒ Object

Long press on a UI element

Examples:

header_image.long_press(1.5)

Parameters:

  • duration (Float) (defaults to: 1)

    duration of long press in seconds



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 505

def long_press(duration = 1)
  obj = element
  object_not_found_exception(obj)
  if Environ.is_ios?
    begin
      Environ.appium_driver.execute_script('mobile: touchAndHold', { elementId: obj.id, duration: duration })
    rescue => err
      puts "Retrying longpress due to error: #{err}"
    else
      return
    end
  end
  driver.action
        .click_and_hold(obj)
        .pause(duration: duration)
        .release
        .perform
end

#reset_mru_cacheObject



28
29
30
31
32
33
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 28

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

#right_clickObject

Right click on a UI element. MacOS apps only.

Examples:

chart_image.right_click


529
530
531
532
533
534
535
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 529

def right_click
  raise "Right click is not supported for #{Environ.device_os} platforms" unless Environ.is_macos?

  obj = element
  object_not_found_exception(obj)
  Environ.appium_driver.execute_script('macos: rightClick', { elementId: obj.id })
end

#scroll_into_view(scroll_mode = :vertical) ⇒ Object

Scroll the UI object until it is visible. If scroll_mode is not specified, then vertical scrolling will be used.

Examples:

place_order_button.scroll_into_view(scroll_mode = :horizontal)

Parameters:

  • scroll_mode (Symbol) (defaults to: :vertical)

    :vertical (default) or :horizontal



598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 598

def scroll_into_view(scroll_mode = :vertical)
  return if visible?

  case scroll_mode
  when :vertical
    start_direction = :down
    end_direction = :up
  when :horizontal
    start_direction = :right
    end_direction = :left
  else
    raise "#{scroll_mode} is not a valid selector"
  end
  try_count = 8
  direction = start_direction
  while hidden?
    ScreenManager.current_screen.swipe_gesture(direction, distance = 0.1)
    try_count -= 1
    if try_count.zero?
      if direction == end_direction
        break
      else
        direction = end_direction
        try_count = 8
      end
    end
  end
end

#selected?Boolean

Returns:

  • (Boolean)


224
225
226
227
228
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 224

def selected?
  obj = element
  object_not_found_exception(obj)
  obj.selected?
end

#send_keys(value) ⇒ Object

Send keystrokes to this UI element.

Examples:

color_picker_wheel.send_keys('Lime green')

Parameters:



74
75
76
77
78
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 74

def send_keys(value)
  obj = element
  object_not_found_exception(obj)
  obj.send_keys(value)
end

#set(value) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 53

def set(value)
  obj = element
  object_not_found_exception(obj)
  if value.is_a?(Array)
    obj.send_keys(value[0])
    if value[1].is_a?(Integer)
      press_keycode(value[1])
    else
      obj.send_keys(value[1])
    end
  elsif value.is_a?(String)
    obj.send_keys(value)
  end
end

#swipe_gesture(direction, distance = 0.5) ⇒ Object

Perform a swipe gesture on the UI object in the specified direction. The swipe start point is the center of the UI object, and the swipe end point is the distance specified.

A distance of 1 specifies a swipe gesture with a distance that is the full screen height (vertical swipe), or full screen width (horizontal swipe). A distance of 0.5 specifies a swipe gesture with a distance that is half the screen width or height.

If distance is a value less than zero, then the distance of the swipe gesture will be half the height (vertical) or width (horizontal) of the UI element being swiped. This is useful for preforming swipes/scrolls in vertical or horizontal list objects.

Examples:

carousel_list.swipe_gesture(direction = :right, distance = 1)

Parameters:

  • direction (Symbol)

    :up, :down, :left, or :right

  • distance (Float) (defaults to: 0.5)

    scroll distance relative to the screen height or width



643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 643

def swipe_gesture(direction, distance = 0.5)
  raise 'Scroll distance must be less than 1' if distance > 1

  obj = element
  object_not_found_exception(obj)
  start_pt = [(obj.location.x + (obj.size.width * 0.5)).to_i, (obj.location.y + (obj.size.height * 0.5)).to_i]

  if distance.negative?
    top = (start_pt[1] - obj.size.height).to_i
    bottom = (start_pt[1] + obj.size.height).to_i
    left = (start_pt[0] - obj.size.width).to_i
    right = (start_pt[0] + obj.size.width).to_i
  else
    screen_size = window_size
    top = (start_pt[1] - ((screen_size.height * distance) * 0.5)).to_i
    bottom = (start_pt[1] + ((screen_size.height * distance) * 0.5)).to_i
    left = (start_pt[0] - ((screen_size.width * distance) * 0.5)).to_i
    right = (start_pt[0] + ((screen_size.width * distance) * 0.5)).to_i
  end

  end_pt = case direction
           when :up
             [start_pt[0], bottom]
           when :down
             [start_pt[0], top]
           when :left
             [right, start_pt[1]]
           when :right
             [left, start_pt[1]]
           end

  puts "Swipe start_pt = #{start_pt} / end_pt = #{end_pt}" if ENV['DEBUG']
  driver.action
        .click_and_hold(obj)
        .move_to_location(end_pt[0], end_pt[1], duration: 0.25)
        .pointer_up
        .perform
end

#tapObject

Tap on a UI element

Examples:

bar_chart_close.tap


469
470
471
472
473
474
475
476
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 469

def tap
  obj = element
  object_not_found_exception(obj)
  driver.action
        .click_and_hold(obj)
        .release
        .perform
end

#visible?Boolean

Is UI object visible?

Examples:

remember_me_checkbox.visible?

Returns:

  • (Boolean)


177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 177

def visible?
  obj = element
  return false if obj.nil?

  begin
    obj.displayed?
  rescue
    reset_mru_cache
    obj = element
    return false if obj.nil?

    obj.displayed?
  end
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 Environ.default_max_wait_time.

Examples:

run_button.wait_until_enabled(10)

Parameters:

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

    wait time in seconds



331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 331

def wait_until_enabled(seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until do
    reset_mru_cache
    enabled?
  end
rescue
  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 Environ.default_max_wait_time.

Examples:

run_button.wait_until_exists(0.5)

Parameters:

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

    wait time in seconds



243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 243

def wait_until_exists(seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until do
    reset_mru_cache
    exists?
  end
rescue
  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 Environ.default_max_wait_time.

Examples:

logout_button.wait_until_gone(5)

Parameters:

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

    wait time in seconds



265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 265

def wait_until_gone(seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until do
    reset_mru_cache
    !exists?
  end
rescue
  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 Environ.default_max_wait_time.

Examples:

run_button.wait_until_hidden(10)

Parameters:

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

    wait time in seconds



309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 309

def wait_until_hidden(seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until do
    reset_mru_cache
    hidden?
  end
rescue
  if post_exception
    raise "UI #{object_ref_message} remained visible after #{timeout} seconds" if visible?
  else
    hidden?
  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 Environ.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



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 378

def wait_until_value_changes(seconds = nil, post_exception = true)
  value = get_value
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until do
    reset_mru_cache
    get_value != value
  end
rescue
  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 Environ.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



356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 356

def wait_until_value_is(value, seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until do
    reset_mru_cache
    compare(value, get_value)
  end
rescue
  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 Environ.default_max_wait_time.

Examples:

run_button.wait_until_visible(0.5)

Parameters:

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

    wait time in seconds



287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 287

def wait_until_visible(seconds = nil, post_exception = true)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until do
    reset_mru_cache
    visible?
  end
rescue
  if post_exception
    raise "Could not find UI #{object_ref_message} after #{timeout} seconds" unless visible?
  else
    visible?
  end
end

#widthInteger

Return width of object.

Examples:

button_width = my_button.width

Returns:

  • (Integer)


400
401
402
403
404
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 400

def width
  obj = element
  object_not_found_exception(obj)
  obj.size.width
end

#x_locInteger

Return x coordinate of object's location.

Examples:

button_x = my_button.x_loc

Returns:

  • (Integer)


424
425
426
427
428
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 424

def x_loc
  obj = element
  object_not_found_exception(obj)
  obj.location.x
end

#y_locInteger

Return y coordinate of object's location.

Examples:

button_y = my_button.y_loc

Returns:

  • (Integer)


436
437
438
439
440
# File 'lib/testcentricity_apps/app_elements/app_element.rb', line 436

def y_loc
  obj = element
  object_not_found_exception(obj)
  obj.location.y
end