Class: Appom::Wait
Overview
Provides wait functionality with configurable timeout and retry interval.
The Wait class is used throughout Appom to wait for conditions to become true, such as waiting for elements to appear or disappear, or for elements to reach a certain state.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_TIMEOUT =
Default timeout in seconds
5- DEFAULT_INTERVAL =
Default retry interval in seconds
0.25
Instance Attribute Summary collapse
- #interval ⇒ Object readonly
-
#timeout ⇒ Numeric
readonly
The timeout value in seconds.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Wait
constructor
Create a new Wait instance.
-
#until { ... } ⇒ Object
Wait until the given block returns a truthy value.
Methods included from Logging
level, level=, #log_debug, #log_element_action, #log_error, #log_info, #log_wait_end, #log_wait_start, #log_warn, #logger
Constructor Details
#initialize(opts = {}) ⇒ Wait
Create a new Wait instance
42 43 44 45 |
# File 'lib/appom/wait.rb', line 42 def initialize(opts = {}) @timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT) @interval = opts.fetch(:interval, DEFAULT_INTERVAL) end |
Instance Attribute Details
#interval ⇒ Object (readonly)
31 |
# File 'lib/appom/wait.rb', line 31 attr_reader :timeout, :interval |
#timeout ⇒ Numeric (readonly)
31 32 33 |
# File 'lib/appom/wait.rb', line 31 def timeout @timeout end |
Instance Method Details
#until { ... } ⇒ Object
Wait until the given block returns a truthy value
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/appom/wait.rb', line 62 def until(&) end_time = Time.now + @timeout = '' last_error = nil start_time = Time.now log_wait_start('custom condition', @timeout) until Time.now > end_time begin result = yield if result duration = Time.now - start_time log_wait_end('custom condition', duration.round(3), success: true) return result end rescue StandardError => e last_error = e = e. end sleep @interval end duration = Time.now - start_time log_wait_end('custom condition', duration.round(3), success: false) # Handle exceptions differently based on type if last_error.is_a?(StandardError) && last_error.instance_of?(StandardError) # Wrap StandardError in WaitError with message included condition = "condition (last error: #{})" raise Appom::WaitError.new(condition, @timeout) elsif last_error # Raise specific exceptions directly (ArgumentError, RuntimeError, etc.) raise last_error else # No exceptions, just condition never became true condition = .empty? ? 'condition' : raise Appom::WaitError.new(condition, @timeout) end end |