Module: Dekiru::Capybara::Helpers::WaitForPositionStable

Included in:
Dekiru::Capybara::Helpers
Defined in:
lib/dekiru/capybara/helpers/wait_for_position_stable.rb

Defined Under Namespace

Classes: StableTimer

Instance Method Summary collapse

Instance Method Details

#wait_for_element_position_stable(element, wait: ::Capybara.default_max_wait_time, stable_wait: 0.5) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dekiru/capybara/helpers/wait_for_position_stable.rb', line 34

def wait_for_element_position_stable(element, wait: ::Capybara.default_max_wait_time, stable_wait: 0.5)
  stable_timer = StableTimer.new(stable_wait)
  timer = ::Capybara::Helpers.timer(expire_in: wait)
  loop do
    rect = element.rect
    break if stable_timer.stable?(rect)
    raise 'Timeout to wait animation finished' if timer.expired?

    sleep 0.1
  end
end

#wait_for_position_stable(selector, locator, **options) ⇒ Object



46
47
48
49
# File 'lib/dekiru/capybara/helpers/wait_for_position_stable.rb', line 46

def wait_for_position_stable(selector, locator, **options)
  element = find(selector, locator, **options.except(:stable_wait))
  wait_for_element_position_stable(element, **options.slice(:wait, :stable_wait))
end