Module: Capybara::Lightpanda::Utils::Wait
- Defined in:
- lib/capybara/lightpanda/utils/wait.rb
Overview
Block-based polling helper. Borrowed from selenium-webdriver’s Wait class (rb/lib/selenium/webdriver/common/wait.rb). Sibling of Utils::Attempt — Attempt retries on a specific error class, Wait loops until the block returns truthy.
Constant Summary collapse
- DEFAULT_INTERVAL =
0.1
Class Method Summary collapse
- .monotonic_time ⇒ Object
-
.until(timeout:, interval: DEFAULT_INTERVAL, ignore: [], message: nil) ⇒ Object
Polls the block until it returns a truthy value or ‘timeout` seconds elapse.
Class Method Details
.monotonic_time ⇒ Object
42 43 44 |
# File 'lib/capybara/lightpanda/utils/wait.rb', line 42 def self.monotonic_time ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end |
.until(timeout:, interval: DEFAULT_INTERVAL, ignore: [], message: nil) ⇒ Object
Polls the block until it returns a truthy value or ‘timeout` seconds elapse. Exceptions whose class is listed in `ignore` are swallowed between polls; the most recent one is appended to the timeout message so the failure stays diagnosable.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/capybara/lightpanda/utils/wait.rb', line 21 def self.until(timeout:, interval: DEFAULT_INTERVAL, ignore: [], message: nil) deadline = monotonic_time + timeout last_error = nil loop do begin result = yield return result if result rescue *Array(ignore) => e last_error = e end break if monotonic_time > deadline sleep interval end msg = || "timed out after #{timeout}s" msg = "#{msg} (#{last_error.})" if last_error raise Capybara::Lightpanda::TimeoutError, msg end |