Module: Calabash::Cucumber::WaitHelpers
- Includes:
- Core, TestsHelpers
- Included in:
- Operations
- Defined in:
- lib/calabash-cucumber/wait_helpers.rb
Defined Under Namespace
Classes: WaitError
Constant Summary collapse
- CALABASH_CONDITIONS =
{:none_animating => "NONE_ANIMATING", :no_network_indicator => "NO_NETWORK_INDICATOR"}
Constants included from Core
Core::CAL_HTTP_RETRY_COUNT, Core::DATA_PATH, Core::RETRYABLE_ERRORS
Instance Method Summary collapse
- #handle_error_with_options(ex, timeout_message, screenshot_on_error) ⇒ Object
- #touch_transition(touch_q, done_queries, check_options = {}, animation_options = {}) ⇒ 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_condition(options = {}) ⇒ 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_for_no_network_indicator(options = {}) ⇒ Object
- #wait_for_none_animating(options = {}) ⇒ Object
-
#wait_for_transition(done_queries, check_options = {}, animation_options = {}) ⇒ Object
may be called with a string (query) or an array of strings.
- #wait_poll(opts, &block) ⇒ Object
Methods included from TestsHelpers
#check_element_does_not_exist, #check_element_exists, #check_view_with_mark_exists, #classes, #each_cell, #each_cell_and_back, #element_does_not_exist, #element_exists, #fail, #navigation_path, #query_map, #screenshot, #screenshot_and_raise, #screenshot_embed, #view_with_mark_exists
Methods included from Core
#backdoor, #background, #calabash_exit, #cell_swipe, #client_version, #current_rotation, #default_device, #flash, #http, #init_request, #interpolate, #load_playback_data, #load_recording, #macro, #make_http_request, #map, #move_wheel, #perform, #picker, #pinch, #playback, #prepare_dialog_action, #query, #query_all, #record_begin, #record_end, #recording_name_for, #rotate, #scroll, #scroll_to_cell, #scroll_to_row, #scroll_to_row_with_mark, #send_uia_command, #server_version, #start_test_server_in_background, #stop_test_server, #swipe, #touch, #url_for
Instance Method Details
#handle_error_with_options(ex, timeout_message, screenshot_on_error) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 144 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 |
#touch_transition(touch_q, done_queries, check_options = {}, animation_options = {}) ⇒ Object
139 140 141 142 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 139 def touch_transition(touch_q, done_queries,={},={}) touch(touch_q) wait_for_transition(done_queries,,) 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
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 43 44 45 46 47 48 49 50 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 17 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] if .key?(:screenshot_on_error) screenshot_on_error = [:screenshot_on_error] end 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_condition(options = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 84 def wait_for_condition( = {}) [:timeout] = [:timeout] || 30 [:query] = [:query] || "view" if .has_key?(:condition) opt_condition = [:condition] if opt_condition.is_a?(Symbol) target_condition = CALABASH_CONDITIONS[opt_condition] elsif opt_condition.is_a?(String) target_condition = [:condition] end [:condition] = target_condition end [:condition] = [:condition] || CALABASH_CONDITIONS[:none_animating] [:post_timeout] = [:post_timeout] || 0.1 [:frequency] = [:frequency] || 0.3 [:retry_frequency] = [:retry_frequency] || 0.3 [:count] = [:count] || 2 [:timeout_message] = [:timeout_message] || "Timeout waiting for condition (#{[:condition]})" [:screenshot_on_error] = [:screenshot_on_error] || true begin Timeout::timeout([:timeout],WaitError) do loop do res = http({:method => :post, :path => 'condition'}, ) res = JSON.parse(res) break if res['outcome'] == 'SUCCESS' sleep([:retry_frequency]) if [:retry_frequency] > 0 end sleep([:post_timeout]) if [:post_timeout] > 0 end rescue WaitError => e (e,[:timeout_message], [: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
77 78 79 80 81 82 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 77 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
70 71 72 73 74 75 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 70 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_for_no_network_indicator(options = {}) ⇒ Object
127 128 129 130 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 127 def wait_for_no_network_indicator( = {}) [:condition] = CALABASH_CONDITIONS[:no_network_indicator] wait_for_condition() end |
#wait_for_none_animating(options = {}) ⇒ Object
122 123 124 125 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 122 def wait_for_none_animating( = {}) [:condition] = CALABASH_CONDITIONS[:none_animating] wait_for_condition() end |
#wait_for_transition(done_queries, check_options = {}, animation_options = {}) ⇒ Object
may be called with a string (query) or an array of strings
133 134 135 136 137 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 133 def wait_for_transition(done_queries, ={},={}) done_queries = [*done_queries] wait_for_elements_exist(done_queries,) wait_for_none_animating() end |
#wait_poll(opts, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 52 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 |