Module: Appium::Core::Wait
- Defined in:
- lib/appium_lib_core/common/wait.rb,
lib/appium_lib_core/common/wait/timer.rb
Defined Under Namespace
Modules: Timer Classes: TimeoutError
Constant Summary collapse
- DEFAULT_TIMEOUT =
30- DEFAULT_INTERVAL =
0.5
Class Method Summary collapse
-
.until(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: nil, ignored: nil, object: nil) ⇒ Object
Check every interval seconds to see if yield doesn’t raise an exception.
-
.until_true(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: nil, ignored: nil, object: nil) ⇒ Object
Check every interval seconds to see if yield returns a truthy value.
Class Method Details
.until(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: nil, ignored: nil, object: nil) ⇒ Object
Check every interval seconds to see if yield doesn’t raise an exception. Give up after timeout seconds.
If only a number is provided then it’s treated as the timeout value.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/appium_lib_core/common/wait.rb', line 31 def until(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: nil, ignored: nil, object: nil) ignored = Array(ignored || ::Exception) last_error = nil begin run_with_timer(timeout, interval) { return yield(object) } rescue ::Errno::ECONNREFUSED => e raise e rescue *ignored => last_error # rubocop:disable Lint/HandleExceptions # swallowed end msg = timeout, msg << " (#{last_error.message})" if last_error raise TimeoutError, msg end |
.until_true(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: nil, ignored: nil, object: nil) ⇒ Object
Check every interval seconds to see if yield returns a truthy value. Note this isn’t a strict boolean true, any truthy value is accepted. false and nil are considered failures. Give up after timeout seconds.
If only a number is provided then it’s treated as the timeout value.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/appium_lib_core/common/wait.rb', line 71 def until_true(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: nil, ignored: nil, object: nil) ignored = Array(ignored || ::Exception) last_error = nil begin run_with_timer(timeout, interval) do result = yield(object) return result if result end rescue ::Errno::ECONNREFUSED => e raise e rescue *ignored => last_error # rubocop:disable Lint/HandleExceptions # swallowed end msg = timeout, msg << " (#{last_error.message})" if last_error raise TimeoutError, msg end |