require 'rspec' require 'calabash-cucumber' # Common assertions used while working with Calabash-Cucumber module Assertions WAIT_TIMEOUT =(ENV['WAIT_TIMEOUT'] || 30).to_f extend Calabash::Cucumber::Operations # Verifies if a view exists def Assertions.view_exists? (view_id) !query("view marked:'#{view_id}'").empty? end # Waits for a view to exists on the page def Assertions.wait_for_view_to_exist (view_id, timeout=WAIT_TIMEOUT) msg = "waited for '#{timeout}' seconds but did not see '#{view_id}'" wait_for(:timeout => timeout, :retry_frequency => 0.2, :post_timeout => 0.1, :timeout_message => msg) do view_exists? view_id end end # Waits for a view to exists on the page def Assertions.wait_for_view_does_not_exist (view_id, timeout=WAIT_TIMEOUT) msg = "waited for '#{timeout}' seconds but did not see '#{view_id}'" wait_for_element_does_not_exists(:timeout => timeout, :retry_frequency => 0.2, :post_timeout => 0.1, :timeout_message => msg) do view_exists? view_id end end # Waits for the page to load def Assertions.wait_for_the_page_to_load(text, timeout=WAIT_TIMEOUT) wait_for(:timeout => timeout) {element_exists("view marked:'#{text}'")} end # Waits for the element that contains a specific text def Assertions.wait_for_element_contains_text(text, timeout=WAIT_TIMEOUT) wait_for(:timeout => timeout) {element_exists("label {text CONTAINS '#{text}'")} end # Waits for the element that begins with a specific text def Assertions.wait_for_element_beginswith_text(text, timeout=WAIT_TIMEOUT) wait_for(:timeout => timeout) {element_exists("label {text BEGINSWITH '#{text}'")} end # Waits for the element that ends with a specific text def Assertions.wait_for_element_endswith_text(text, timeout=WAIT_TIMEOUT) wait_for(:timeout => timeout) {element_exists("label {text ENDSWITH '#{text}'")} end # Waits for a specific text to load on the page def Assertions.wait_for_specific_text_to_load(text, timeout=WAIT_TIMEOUT) wait_for(:timeout => timeout) {element_exists("* marked:'#{text}'")} end end