Module: Calabash::Cucumber::WaitHelpers
- Includes:
- Core, Logging, TestsHelpers
- Included in:
- Operations
- Defined in:
- lib/calabash-cucumber/wait_helpers.rb
Overview
A collection of methods that help you wait for things.
Defined Under Namespace
Classes: WaitError
Constant Summary collapse
- CALABASH_CONDITIONS =
Currently two conditions that can be waited for using ‘wait_for_condition`: `:none_animating` no UIKit object is animating and `:no_network_indicator` status bar network indicator not showing.
{:none_animating => 'NONE_ANIMATING', :no_network_indicator => 'NO_NETWORK_INDICATOR'}
- DEFAULT_OPTS =
The default options used in the “wait*” methods
{ # default upper limit on how long to wait :timeout => 30, # default polling frequency for waiting :retry_frequency => 0.3, # default extra wait after the condition becomes true :post_timeout => 0, # default message if timeout occurs :timeout_message => 'Timed out waiting...', # Calabash will generate a screenshot by default if waiting times out :screenshot_on_error => true }
Instance Method Summary collapse
-
#touch_transition(touch_q, done_queries, check_options = {}, animation_options = {}) ⇒ Object
Combines touching an element and ‘wait_for_transition`.
-
#until_element_does_not_exist(uiquery, opts = {}) ⇒ Object
Performs a lambda action until the element (a query string) disappears.
-
#until_element_exists(uiquery, opts = {}) ⇒ Object
Performs a lambda action until the element (a query string) appears.
-
#wait_error(msg) ⇒ WaitError, Object
if
msg
is a String, a new WaitError is returned. -
#wait_for(options_or_timeout = DEFAULT_OPTS, &block) ⇒ nil
Waits for a condition to be true.
-
#wait_for_element_does_not_exists(element_query, options = {}) ⇒ nil
Waits for a Calabash query to return an empty result (typically a UI element to disappear).
-
#wait_for_element_exists(element_query, options = {}) ⇒ nil
Waits for a Calabash query to return a non-empty result (typically a UI element to be visible).
-
#wait_for_elements_do_not_exist(elements_arr, options = {}) ⇒ nil
Waits for one or more Calabash queries to all return empty results (typically a UI elements to disappear).
-
#wait_for_elements_exist(elements_arr, options = {}) ⇒ nil
Waits for one or more Calabash queries to all return non-empty results (typically a UI elements to be visible).
-
#wait_for_no_network_indicator(options = {}) ⇒ nil
Waits for the status-bar network indicator to stop animating (network activity done).
-
#wait_for_none_animating(options = {}) ⇒ nil
Waits for all elements to stop animating (EXPERIMENTAL).
-
#wait_for_transition(done_queries, check_options = {}, animation_options = {}) ⇒ Object
Combines waiting for elements and waiting for animations.
-
#wait_poll(opts, &block) ⇒ nil
Repeatedly runs an action (for side-effects) until a condition is satisfied.
-
#when_element_exists(uiquery, opts = {}) ⇒ Object
Performs a lambda action once the element exists.
Methods included from TestsHelpers
#check_element_does_not_exist, #check_element_exists, #check_view_with_mark_exists, #classes, #each_cell, #element_does_not_exist, #element_exists, #view_with_mark_exists
Methods included from FailureHelpers
#fail, #screenshot, #screenshot_and_raise, #screenshot_embed
Methods included from Core
#await_page, #backdoor, #calabash_exit, #clear_text, #client_version, #console_attach, #double_tap, #flash, #flick, #html, #identifier, #label, #location_for_place, #page, #pan, #pinch, #query, #query_all, #scroll, #scroll_to_cell, #scroll_to_collection_view_item, #scroll_to_collection_view_item_with_mark, #scroll_to_row, #scroll_to_row_with_mark, #send_app_to_background, #server_log_level, #server_version, #set_location, #set_server_log_level, #set_text, #set_user_pref, #start_test_server_in_background, #swipe, #tap, #tap_mark, #tap_point, #touch, #touch_hold, #two_finger_tap, #user_pref, #wait_tap
Methods included from PlaybackHelpers
#interpolate, #playback, #record_begin, #record_end
Methods included from Logging
#calabash_info, #calabash_warn
Methods included from RotationHelpers
#rotate, #rotate_home_button_to
Methods included from StatusBarHelpers
#device_orientation, #landscape?, #portrait?, #status_bar_orientation
Methods included from UIA
#uia, #uia_call, #uia_call_windows, #uia_names, #uia_query, #uia_query_windows
Methods included from QueryHelpers
Methods included from EnvironmentHelpers
#default_device, #device_family_iphone?, #ios5?, #ios6?, #ios7?, #ios8?, #ipad?, #iphone?, #iphone_4in?, #iphone_5?, #iphone_app_emulated_on_ipad?, #ipod?, #simulator?, #uia_available?, #uia_not_available?, #xamarin_test_cloud?
Instance Method Details
#touch_transition(touch_q, done_queries, check_options = {}, animation_options = {}) ⇒ Object
Combines touching an element and ‘wait_for_transition`
332 333 334 335 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 332 def touch_transition(touch_q, done_queries,={},={}) touch(touch_q) wait_for_transition(done_queries,,) end |
#until_element_does_not_exist(uiquery, opts = {}) ⇒ Object
Performs a lambda action until the element (a query string) disappears. The default action is to do nothing.
Raises an error if no uiquery is specified.
368 369 370 371 372 373 374 375 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 368 def until_element_does_not_exist(uiquery, opts = {}) condition = lambda {element_does_not_exist(uiquery)} extra_opts = { :until => condition, :action => lambda {} } opts = DEFAULT_OPTS.merge(extra_opts).merge(opts) wait_poll(opts) do opts[:action].call end end |
#until_element_exists(uiquery, opts = {}) ⇒ Object
Performs a lambda action until the element (a query string) appears. The default action is to do nothing. Similar to ‘wait_poll`.
Raises an error if no uiquery is specified.
349 350 351 352 353 354 355 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 349 def until_element_exists(uiquery, opts = {}) extra_opts = { :until_exists => uiquery, :action => lambda {} } opts = DEFAULT_OPTS.merge(extra_opts).merge(opts) wait_poll(opts) do opts[:action].call end end |
#wait_error(msg) ⇒ WaitError, Object
if msg
is a String, a new WaitError is returned. Otherwise msg
itself is returned.
435 436 437 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 435 def wait_error(msg) (msg.is_a?(String) ? WaitError.new(msg) : msg) end |
#wait_for(options_or_timeout = DEFAULT_OPTS, &block) ⇒ nil
Waits for a condition to be true. The condition is specified by a given block that is called repeatedly. If the block returns a ‘trueish’ value the condition is considered true and ‘wait_for` immediately returns. There is a `:timeout` option that specifies a maximum number of seconds to wait. If the given block doesn’t return a ‘trueish’ value before the ‘:timeout` seconds has elapsed, the waiting fails and raises a WaitError error.
The ‘options` hash controls the details of waiting (see `options_or_timeout` below). DEFAULT_OPTS specifies the default waiting options.
‘wait_for` is a low-level building-block for waiting and often there are higher-level waiting methods what use `wait_for` in their implementation (e.g. `wait_for_element_exists`).
83 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 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 83 def wait_for(=DEFAULT_OPTS, &block) #note Hash is preferred, number acceptable for backwards compat default_timeout = 30 timeout = || default_timeout post_timeout=0 retry_frequency=0.3 = nil screenshot_on_error = true if .is_a?(Hash) timeout = [:timeout] || default_timeout retry_frequency = [:retry_frequency] || retry_frequency post_timeout = [:post_timeout] || post_timeout = [: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 msg = || e if screenshot_on_error sleep(retry_frequency) return screenshot_and_retry(msg, &block) else raise wait_error(msg) end rescue Exception => e (e, nil, screenshot_on_error) end end |
#wait_for_element_does_not_exists(element_query, options = {}) ⇒ nil
Waits for a Calabash query to return an empty result (typically a UI element to disappear). Uses ‘wait_for`.
215 216 217 218 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 215 def wait_for_element_does_not_exists(element_query, ={}) [:timeout_message] = [:timeout_message] || "Timeout waiting for element to not exist: #{element_query}" wait_for() { element_does_not_exist(element_query) } end |
#wait_for_element_exists(element_query, options = {}) ⇒ nil
Waits for a Calabash query to return a non-empty result (typically a UI element to be visible). Uses ‘wait_for`.
178 179 180 181 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 178 def wait_for_element_exists(element_query, ={}) [:timeout_message] = [:timeout_message] || "Timeout waiting for element: #{element_query}" wait_for() { element_exists(element_query) } end |
#wait_for_elements_do_not_exist(elements_arr, options = {}) ⇒ nil
Waits for one or more Calabash queries to all return empty results (typically a UI elements to disappear). Uses ‘wait_for`.
232 233 234 235 236 237 238 239 240 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 232 def wait_for_elements_do_not_exist(elements_arr, ={}) if elements_arr.is_a?(String) elements_arr = [elements_arr] end [: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 = {}) ⇒ nil
Waits for one or more Calabash queries to all return non-empty results (typically a UI elements to be visible). Uses ‘wait_for`.
194 195 196 197 198 199 200 201 202 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 194 def wait_for_elements_exist(elements_arr, ={}) if elements_arr.is_a?(String) elements_arr = [elements_arr] end [: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 = {}) ⇒ nil
Waits for the status-bar network indicator to stop animating (network activity done).
311 312 313 314 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 311 def wait_for_no_network_indicator( = {}) [:condition] = CALABASH_CONDITIONS[:no_network_indicator] wait_for_condition() end |
#wait_for_none_animating(options = {}) ⇒ nil
Waits for all elements to stop animating (EXPERIMENTAL).
301 302 303 304 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 301 def wait_for_none_animating( = {}) [:condition] = CALABASH_CONDITIONS[:none_animating] wait_for_condition() end |
#wait_for_transition(done_queries, check_options = {}, animation_options = {}) ⇒ Object
Combines waiting for elements and waiting for animations.
320 321 322 323 324 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 320 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) ⇒ nil
Repeatedly runs an action (for side-effects) until a condition is satisfied. Similar to ‘wait_for` but specifies both a condition to wait for and an action to repeatedly perform to make the condition true (e.g. scrolling). The return value of the action is ignored.
The block represents the action and options :until or :until_exists specify the condition to wait for. Same options as ‘wait_for` can be provided.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 149 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 |
#when_element_exists(uiquery, opts = {}) ⇒ Object
Performs a lambda action once the element exists. The default behavior is to touch the specified element.
Raises an error if no uiquery is specified.
388 389 390 391 392 |
# File 'lib/calabash-cucumber/wait_helpers.rb', line 388 def when_element_exists(uiquery, opts = {}) action = opts[:action] || lambda { touch(uiquery) } wait_for_element_exists(uiquery, opts) action.call end |