Module: Calabash::Android::WaitHelpers
- Included in:
- Operations
- Defined in:
- lib/calabash-android/wait_helpers.rb
Defined Under Namespace
Classes: WaitError
Instance Method Summary collapse
- #handle_error_with_options(ex, timeout_message, screenshot_on_error) ⇒ Object
- #wait_for(options_or_timeout = {:timeout => 10, :retry_frequency => 0.2, :post_timeout => 0.1, :timeout_message => "Timed out waiting...", :screenshot_on_error => true}, &block) ⇒ Object
-
#wait_for_elements_do_not_exist(elements_arr, options = {}) ⇒ Object
options for wait_for apply.
-
#wait_for_elements_exist(elements_arr, options = {}) ⇒ Object
options for wait_for apply.
- #wait_poll(opts, &block) ⇒ Object
Instance Method Details
#handle_error_with_options(ex, timeout_message, screenshot_on_error) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/calabash-android/wait_helpers.rb', line 77 def (ex, , screenshot_on_error) msg = ( || ex) if ex msg = "#{msg} (#{ex.class})" end if screenshot_on_error screenshot_and_raise msg else raise msg end end |
#wait_for(options_or_timeout = {:timeout => 10, :retry_frequency => 0.2, :post_timeout => 0.1, :timeout_message => "Timed out waiting...", :screenshot_on_error => true}, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/calabash-android/wait_helpers.rb', line 11 def wait_for(= {:timeout => 10, :retry_frequency => 0.2, :post_timeout => 0.1, :timeout_message => "Timed out waiting...", :screenshot_on_error => true}, &block) #note Hash is preferred, number acceptable for backwards compat timeout= post_timeout=0.1 retry_frequency=0.2 = nil screenshot_on_error = true if .is_a?(Hash) timeout = [:timeout] || 10 retry_frequency = [:retry_frequency] || 0.2 post_timeout = [:post_timeout] || 0.1 = [:timeout_message] screenshot_on_error = [:screenshot_on_error] || true end begin Timeout::timeout(timeout, WaitError) do sleep(retry_frequency) until yield end sleep(post_timeout) if post_timeout > 0 rescue WaitError => e (e, , screenshot_on_error) rescue Exception => e (e, nil, screenshot_on_error) end end |
#wait_for_elements_do_not_exist(elements_arr, options = {}) ⇒ Object
options for wait_for apply
70 71 72 73 74 75 |
# File 'lib/calabash-android/wait_helpers.rb', line 70 def wait_for_elements_do_not_exist(elements_arr, ={}) [:timeout_message] = [:timeout_message] || "Timeout waiting for no elements matching: #{elements_arr.join(",")}" wait_for() do elements_arr.none? { |q| element_exists(q) } end end |
#wait_for_elements_exist(elements_arr, options = {}) ⇒ Object
options for wait_for apply
62 63 64 65 66 67 |
# File 'lib/calabash-android/wait_helpers.rb', line 62 def wait_for_elements_exist(elements_arr, ={}) [:timeout_message] = [:timeout_message] || "Timeout waiting for elements: #{elements_arr.join(",")}" wait_for() do elements_arr.all? { |q| element_exists(q) } end end |
#wait_poll(opts, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/calabash-android/wait_helpers.rb', line 44 def wait_poll(opts, &block) test = opts[:until] if test.nil? cond = opts[:until_exists] raise "Must provide :until or :until_exists" unless cond test = lambda { element_exists(cond) } end wait_for(opts) do if test.call() true else yield false end end end |