Class: Selenium::WebDriver::Wait
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/wait.rb |
Constant Summary
-
DEFAULT_INTERVAL =
# File 'rb/lib/selenium/webdriver/common/wait.rb', line 240.2
-
DEFAULT_TIMEOUT =
# File 'rb/lib/selenium/webdriver/common/wait.rb', line 235
Class Method Summary
-
.new(opts = {}) ⇒ Wait
constructor
Create a new
Wait
instance.
Instance Method Summary
-
#until ⇒ Object
Wait
until the given block returns a true value. - #current_time private
Constructor Details
.new(opts = {}) ⇒ Wait
Create a new Wait
instance
# File 'rb/lib/selenium/webdriver/common/wait.rb', line 36
def initialize(opts = {}) @timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT) @interval = opts.fetch(:interval, DEFAULT_INTERVAL) @message = opts[: ] @ignored = Array(opts[:ignore] || Error::NoSuchElementError) end
Instance Method Details
#current_time (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/wait.rb', line 78
def current_time Process.clock_gettime(Process::CLOCK_MONOTONIC) end
#until ⇒ Object
Wait
until the given block returns a true value.
# File 'rb/lib/selenium/webdriver/common/wait.rb', line 50
def until end_time = current_time + @timeout last_error = nil until current_time > end_time begin result = yield return result if result rescue *@ignored => last_error # rubocop:disable Naming/RescuedExceptionsVariableName # swallowed end sleep @interval end msg = if @message @message.dup else "timed out after #{@timeout} seconds" end msg << " (#{last_error.})" if last_error raise Error::TimeoutError, msg end