Class: Calabash::IBase

Inherits:
Object
  • Object
show all
Includes:
Cucumber::Operations
Defined in:
lib/calabash-cucumber/ibase.rb

Constant Summary

Constants included from Cucumber::Core

Cucumber::Core::CAL_HTTP_RETRY_COUNT, Cucumber::Core::DATA_PATH, Cucumber::Core::RETRYABLE_ERRORS

Constants included from Cucumber::KeyboardHelpers

Cucumber::KeyboardHelpers::KEYPLANE_NAMES

Constants included from Cucumber::WaitHelpers

Cucumber::WaitHelpers::CALABASH_CONDITIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cucumber::Operations

#assert_home_direction, #await_page, #escape_quotes, #home_direction, #html, #identifier, #label, #set_text, #set_user_pref, #simple_touch, #tap, #user_pref

Methods included from Cucumber::Location

#location_for_place, #set_location

Methods included from Cucumber::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

Methods included from Cucumber::KeyboardHelpers

#_do_keyplane, #await_keyboard, #current_keyplane, #done, #keyboard_enter_char, #keyboard_enter_text, #search_keyplanes_and_enter_char

Methods included from Cucumber::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 Cucumber::WaitHelpers

#handle_error_with_options, #touch_transition, #wait_for, #wait_for_condition, #wait_for_elements_do_not_exist, #wait_for_elements_exist, #wait_for_no_network_indicator, #wait_for_none_animating, #wait_for_transition, #wait_poll

Constructor Details

#initialize(world, transition_duration = 0.5) ⇒ IBase

Returns a new instance of IBase.



9
10
11
12
# File 'lib/calabash-cucumber/ibase.rb', line 9

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)



94
95
96
# File 'lib/calabash-cucumber/ibase.rb', line 94

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

Instance Attribute Details

#transition_durationObject

Returns the value of attribute transition_duration.



7
8
9
# File 'lib/calabash-cucumber/ibase.rb', line 7

def transition_duration
  @transition_duration
end

#worldObject

Returns the value of attribute world.



7
8
9
# File 'lib/calabash-cucumber/ibase.rb', line 7

def world
  @world
end

Instance Method Details

#await(wait_opts = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/calabash-cucumber/ibase.rb', line 27

def await(wait_opts={})
  wait_for_elements_exist([trait], wait_opts)
  unless wait_opts.has_key?(:await_animation) && !wait_opts[:await_animation]
    sleep(transition_duration)
  end
  self
end

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



87
88
89
90
# File 'lib/calabash-cucumber/ibase.rb', line 87

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

#current_page?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/calabash-cucumber/ibase.rb', line 19

def current_page?
  element_exists(trait)
end

#page(clz, *args) ⇒ Object



23
24
25
# File 'lib/calabash-cucumber/ibase.rb', line 23

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

#traitObject



14
15
16
17
# File 'lib/calabash-cucumber/ibase.rb', line 14

def trait
  raise "You should define a trait method or a title method" unless respond_to?(:title)
  "navigationItemView 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::IBase (or acts accordingly)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/calabash-cucumber/ibase.rb', line 53

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
    wait_opts = transition_options[:wait_options] || {}
    if page_obj == self
      unless wait_opts.has_key?(:await_animation) && !wait_opts[:await_animation]
        sleep(transition_duration)
      end
    else
      page_obj.await(wait_opts)
    end
  end

  page_obj
end