Module: Unobtainium::MultiWait::DriverModule
- Defined in:
- lib/unobtainium-multiwait/multiwait.rb
Overview
Driver module implementing multi wait functionality.
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options. This hash is also used to detect if any of the Hashes passed to #multiwait is an options Hash; it is considered one if it contains any of the keys specified here.
{ # If true, raises on error instead of returning nil raise_on_error: false, # If true, returns the error object instead of nil return_errors: false, # If :all is specified, the method waits for all elements to # appear or times out. # If :first is specified, the method returns when the first # element appears. wait_for: :all, # Defaults to only finding :displayed? elements. You can use any method # that Selenium::WebDriver::Element responds to, or :exists? if you only # care whether the element exists. check_element: :displayed?, # The default wait timeout in seconds. timeout: 10, }.freeze
Instance Attribute Summary collapse
-
#multiwait_options ⇒ Object
Current options for multiwait.
Class Method Summary collapse
-
.matches?(impl) ⇒ Boolean
Returns true if the implementation has ‘#find_element`, false otherwise.
Instance Method Summary collapse
-
#multiwait(*args) ⇒ Object
(also: #wait)
Wait for multiple elements.
Instance Attribute Details
#multiwait_options ⇒ Object
Current options for multiwait
51 52 53 |
# File 'lib/unobtainium-multiwait/multiwait.rb', line 51 def @multiwait_options end |
Class Method Details
.matches?(impl) ⇒ Boolean
Returns true if the implementation has ‘#find_element`, false otherwise.
44 45 46 |
# File 'lib/unobtainium-multiwait/multiwait.rb', line 44 def matches?(impl) return impl.respond_to?(:find_element) end |
Instance Method Details
#multiwait(*args) ⇒ Object Also known as: wait
Wait for multiple elements. Each argument is a Hash of selector options that are passed to #find_element. If one argument contains keys from the DEFAULT_OPTIONS Hash, it is instead treated as an options Hash for the #multiwait method.
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 |
# File 'lib/unobtainium-multiwait/multiwait.rb', line 62 def multiwait(*args) # Parse options , selectors = (*args) # Pass some options to multifind multifind_opts = { raise_on_error: [:raise_on_error], return_errors: [:return_error], check_element: [:check_element], } # Wait for elements results = [] wait = ::Selenium::WebDriver::Wait.new(timeout: [:timeout]) begin wait.until do results = multifind(*selectors, multifind_opts) got_it, results = multiwait_filter_results(, results) if got_it return results end end rescue ::Selenium::WebDriver::Error::TimeOutError => err if [:raise_on_error] raise end if [:return_errors] results.map! { |result| result.nil? ? err : result } end end return results end |