Class: Appium::Core::Base::Wait
- Inherits:
-
Selenium::WebDriver::Wait
- Object
- Selenium::WebDriver::Wait
- Appium::Core::Base::Wait
- Defined in:
- lib/appium_lib_core/common/base/wait.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Wait
constructor
A new instance of Wait.
-
#until ⇒ Object
Wait code from the selenium Ruby gem github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb.
Constructor Details
#initialize(opts = {}) ⇒ Wait
Returns a new instance of Wait.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/appium_lib_core/common/base/wait.rb', line 8 def initialize(opts = {}) valid_keys = i(timeout interval ignore return_if_true) invalid_keys = [] opts.each_key { |key| invalid_keys << key unless valid_keys.include?(key) } # [:one, :two] => :one, :two unless invalid_keys.empty? raise "Invalid keys #{invalid_keys.to_s[1..-2]}. Valid keys are #{valid_keys.to_s[1..-2]}" end @timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT) @interval = opts.fetch(:interval, DEFAULT_INTERVAL) = opts[:message] @ignored = Array(opts[:ignore] || ::Exception) @return_if_true = opts[:return_if_true] super(timeout: @timeout, interval: @interval, message: , ignore: @ignored) end |
Instance Method Details
#until ⇒ Object
Wait code from the selenium Ruby gem github.com/SeleniumHQ/selenium/blob/cf501dda3f0ed12233de51ce8170c0e8090f0c20/rb/lib/selenium/webdriver/common/wait.rb
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/appium_lib_core/common/base/wait.rb', line 28 def until end_time = Time.now + @timeout last_error = nil until Time.now > end_time begin return yield unless @return_if_true result = yield return result if result rescue ::Errno::ECONNREFUSED => e raise e rescue *@ignored => last_error # swallowed end sleep @interval end msg = ? .dup : "timed out after #{@timeout} seconds" msg << " (#{last_error.message})" if last_error raise Selenium::WebDriver::Error::TimeOutError, msg end |