Class: Selenium::WebDriver::Wait
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Wait
- Defined in:
- rb/lib/selenium/webdriver/common/wait.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
5
- DEFAULT_INTERVAL =
0.2
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Wait
constructor
Create a new Wait instance.
-
#until ⇒ Object
Wait until the given block returns a true value.
Constructor Details
#initialize(opts = {}) ⇒ Wait
Create a new Wait instance
36 37 38 39 40 41 |
# 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[:message] @ignored = Array(opts[:ignore] || Error::NoSuchElementError) end |
Instance Method Details
#until ⇒ Object
Wait until the given block returns a true value.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# 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 |