Class: Calabash::ABase

Inherits:
Object
  • Object
show all
Includes:
Calabash::Android::Operations
Defined in:
lib/calabash-android/abase.rb

Constant Summary

Constants included from Calabash::Android::WaitHelpers

Calabash::Android::WaitHelpers::DEFAULT_OPTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Calabash::Android::Operations

#app_to_background, #backdoor, #cell_swipe, #check_element_does_not_exist, #check_element_exists, #check_view_with_mark_exists, #classes, #clear_app_data, #clear_preferences, #client_version, #connect_to_test_server, #current_activity, #default_device, #deprecated_actions, #disconnect_from_test_server, #done, #each_item, #element_does_not_exist, #element_exists, #element_is_not_hidden, #evaluate_javascript, #execute_uiquery, #fail, #find_scrollable_view, #flash, #get_preferences, #hide_soft_keyboard, #html, #http, #install_app, #interpolate, #label, #load_playback_data, #log, #macro, #make_http_request, #map, #ni, #performAction, #perform_action, #playback, #press_back_button, #press_button, #press_down_button, #press_enter_button, #press_left_button, #press_menu_button, #press_right_button, #press_up_button, #press_user_action_button, #pull, #push, #query, #record_begin, #record_end, #reinstall_apps, #reinstall_test_server, #removed_actions, #rotate, #screenshot, #screenshot_and_raise, #screenshot_embed, #scroll, #scroll_down, #scroll_to, #scroll_to_row, #scroll_up, #select_context_menu_item, #select_item_from_spinner, #select_options_menu_item, #server_version, #set_date, #set_default_device, #set_gps_coordinates, #set_gps_coordinates_from_location, #set_preferences, #set_text, #set_time, #shutdown_test_server, #start_test_server_in_background, #step_deprecated, #swipe, #uninstall_apps, #update_app, #url_for, #view_with_mark_exists, #wake_up

Methods included from Calabash::Android::WaitHelpers

#handle_error_with_options, #screenshot_and_retry, #until_element_does_not_exist, #until_element_exists, #wait_error, #wait_for, #wait_for_activity, #wait_for_element_does_not_exist, #wait_for_element_exists, #wait_for_elements_do_not_exist, #wait_for_elements_exist, #wait_for_text, #wait_for_text_to_disappear, #wait_poll, #when_element_exists

Methods included from Calabash::Android::TouchHelpers

#double_tap, #drag, #execute_gesture, #find_coordinate, #flick, #flick_down, #flick_left, #flick_right, #flick_up, #long_press, #long_press_when_element_exists, #pan, #pan_down, #pan_left, #pan_right, #pan_up, #pinch, #pinch_in, #pinch_out, #query_result?, #tap, #tap_mark, #tap_when_element_exists, #touch

Methods included from Calabash::Android::TextHelpers

#assert_text, #clear_text, #clear_text_in, #enter_text, #escape_quotes, #has_text?, #keyboard_enter_char, #keyboard_enter_text

Methods included from Calabash::Android::EnvironmentHelpers

#xamarin_test_cloud?

Constructor Details

#initialize(world, transition_duration = 0.5) ⇒ ABase

Returns a new instance of ABase.



7
8
9
10
# File 'lib/calabash-android/abase.rb', line 7

def initialize(world, transition_duration=0.5)
  self.world = world
  self.transition_duration = transition_duration
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



85
86
87
# File 'lib/calabash-android/abase.rb', line 85

def method_missing(name, *args, &block)
  world.send(name, *args, &block)
end

Instance Attribute Details

#transition_durationObject

Returns the value of attribute transition_duration.



5
6
7
# File 'lib/calabash-android/abase.rb', line 5

def transition_duration
  @transition_duration
end

#worldObject

Returns the value of attribute world.



5
6
7
# File 'lib/calabash-android/abase.rb', line 5

def world
  @world
end

Instance Method Details

#await(wait_opts = {}) ⇒ Object



25
26
27
28
# File 'lib/calabash-android/abase.rb', line 25

def await(wait_opts={})
  wait_for_elements_exist([trait], wait_opts)
  self
end

#await_screenshot(wait_opts = {}, screenshot_opts = {}) ⇒ Object



78
79
80
81
# File 'lib/calabash-android/abase.rb', line 78

def await_screenshot(wait_opts={}, screenshot_opts={})
  await(wait_opts)
  screenshot_embed(screenshot_opts)
end

#current_page?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/calabash-android/abase.rb', line 17

def current_page?
  element_exists(trait)
end

#page(clz, *args) ⇒ Object



21
22
23
# File 'lib/calabash-android/abase.rb', line 21

def page(clz, *args)
  clz.new(world, *args)
end

#traitObject



12
13
14
15
# File 'lib/calabash-android/abase.rb', line 12

def trait
  raise "You should define a trait method or a title method" unless respond_to?(:title)
  "* marked:'#{self.title}'"
end

#transition(transition_options = {}) ⇒ Object

Performs a transition from receiver page to another by performing a +:tap+ gesture or a user specified +:action+. Caller must supply a hash of options +transition_options+ to describe the transition. Transition options may have the following keys

+:tap+: A uiquery used to perform a tap gesture to begin transition +:action+: A proc to use begin transition (either :tap or :action must be supplied) +:page+: A page object or page object class to transition to (target page). If a class is provided this is instantiated using the +page+ method of self. If no +:page+ is supplied, +self+ is used. +:await+: If specified and truthy will await the +:page+ after performing gesture (usually to wait for animation to finish) +:tap_options+: If +:tap+ is provided used to pass as options to touch +:wait_options+: When awaiting target page, pass these options to the +await+ method

Returns the transition target page

Note it is assumed that the target page is a Calabash::ABase (or acts accordingly)



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/calabash-android/abase.rb', line 48

def transition(transition_options={})
  uiquery = transition_options[:tap]
  action = transition_options[:action]
  page_arg = transition_options[:page]
  should_await = transition_options.has_key?(:await) ? transition_options[:await] : true

  if action.nil? && uiquery.nil?
    raise "Called transition without providing a gesture (:tap or :action) #{transition_options}"
  end

  if uiquery
    tap_options = transition_options[:tap_options] || {}
    touch(uiquery, tap_options)
  else
    action.call()
  end

  page_obj = page_arg.is_a?(Class) ? page(page_arg) : page_arg
  page_obj ||= self

  if should_await
    unless page_obj == self
      wait_opts = transition_options[:wait_options] || {}
      page_obj.await(wait_opts)
    end
  end

  page_obj
end