Class: Calabash::IBase

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

Overview

The ‘IBase` class is a base class that can be used to easily implement page object classes on iOS (hence the I). Delegates to the cucumber World object for missing methods (e.g. embed or puts). Mixes in Cucumber::Operations. For Calabash Android there is a corresponding `ABase`. For more detailed documentation on using the Page Object Pattern (POP) with Calabash, please see: /. Note we recommend using POP even if you’re not targeting multiple platforms as it tends to lead to more maintainable test suites.

Constant Summary

Constants included from Cucumber::WaitHelpers

Cucumber::WaitHelpers::CALABASH_CONDITIONS, Cucumber::WaitHelpers::DEFAULT_OPTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cucumber::Operations

extended

Methods included from Cucumber::IPad

#ensure_ipad_emulation_1x, #ensure_ipad_emulation_scale

Methods included from Cucumber::DatePicker

#countdown_mode?, #date_and_time_mode?, #date_mode?, #date_time_from_picker, #maximum_date_time_from_picker, #minimum_date_time_from_picker, #picker_set_date_time, #should_see_date_picker, #time_mode?

Methods included from Cucumber::Core

#await_page, #backdoor, #calabash_exit, #calabash_info, #calabash_warn, #clear_text, #client_version, #console_attach, #deprecated, #device_agent, #dismiss_ipad_keyboard, #double_tap, #flash, #flick, #html, #identifier, #keyboard_enter_char, #keyboard_enter_text, #label, #location_for_place, #pan, #pan_coordinates, #pinch, #query, #rotate, #rotate_home_button_to, #scroll, #scroll_to_cell, #scroll_to_collection_view_item, #scroll_to_collection_view_item_with_mark, #scroll_to_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, #shake, #slider_set_value, #start_test_server_in_background, #swipe, #tap_keyboard_action_key, #tap_keyboard_delete_key, #tap_mark, #tap_point, #touch, #touch_hold, #two_finger_tap, #user_pref

Methods included from Cucumber::KeyboardHelpers

#docked_keyboard_visible?, #keyboard_visible?, #lookup_key_name, #split_keyboard_visible?, #undocked_keyboard_visible?, #wait_for_keyboard, #wait_for_no_keyboard

Methods included from Cucumber::StatusBarHelpers

#device_orientation, #landscape?, #portrait?, #status_bar_details, #status_bar_orientation

Methods included from Cucumber::UIA

#uia, #uia_call, #uia_call_windows, #uia_keyboard_visible?, #uia_names, #uia_orientation, #uia_query, #uia_query_windows, #uia_rotate, #uia_rotate_home_button_to, #uia_set_responder_value, #uia_wait_for_keyboard

Methods included from Cucumber::FailureHelpers

#fail, #screenshot, #screenshot_and_raise, #screenshot_embed

Methods included from Cucumber::QueryHelpers

#escape_backslashes, #escape_newlines, #escape_quotes, #escape_string

Methods included from Cucumber::EnvironmentHelpers

#default_device, #device_family_iphone?, #ios10?, #ios11?, #ios5?, #ios6?, #ios7?, #ios8?, #ios9?, #ios_gte_11?, #ios_version, #ipad?, #ipad_pro?, #iphone?, #iphone_35in?, #iphone_4in?, #iphone_6?, #iphone_6_plus?, #iphone_app_emulated_on_ipad?, #ipod?, #screen_dimensions, #simulator?, #uia_available?, #uia_not_available?, #xamarin_test_cloud?

Methods included from Cucumber::KeychainHelpers

#keychain_accounts, #keychain_accounts_for_service, #keychain_clear, #keychain_clear_accounts_for_service, #keychain_delete_password, #keychain_password, #keychain_set_password

Methods included from Cucumber::WaitHelpers

#touch_transition, #until_element_does_not_exist, #until_element_exists, #wait_error, #wait_for, #wait_for_element_does_not_exist, #wait_for_element_exists, #wait_for_elements_do_not_exist, #wait_for_elements_exist, #wait_for_no_network_indicator, #wait_for_none_animating, #wait_for_transition, #wait_poll, #wait_tap, #when_element_exists

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

Constructor Details

#initialize(world, transition_duration = 0.5) ⇒ IBase

Create a new page object.

Parameters:

  • world (Object)

    the cucumber World object

  • transition_duration (Number) (defaults to: 0.5)

    the number of seconds to for page transitions



40
41
42
43
# File 'lib/calabash-cucumber/ibase.rb', line 40

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)



217
218
219
# File 'lib/calabash-cucumber/ibase.rb', line 217

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

Instance Attribute Details

#transition_durationNumber

Note:

By default, this value is not used. To use this additional wait time, you need to include ‘:await_animation => true` in the options hash that is passed the `await` and `transition` methods.

The number of seconds to allow for page complete animations after this page trait becomes visible.

Returns:

  • (Number)

    the number of seconds to allow for page transitions

See Also:



33
34
35
# File 'lib/calabash-cucumber/ibase.rb', line 33

def transition_duration
  @transition_duration
end

#worldObject

A reference to the Cucumber World variable.

Returns:

  • (Object)

    the Cucumber World instance



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

def world
  @world
end

Instance Method Details

#await(wait_opts = {}) ⇒ IBase

Waits for this page’s ‘trait` to become visible.

After this page appears, you can optionally wait for ‘self.transition_duration` more seconds.

Parameters:

Options Hash (wait_opts):

  • :await_animation (Boolean) — default: false

    if true, will wait for ‘self.transition_duration` after this page’s ‘trait` appears

Returns:

See Also:



121
122
123
124
125
126
127
# File 'lib/calabash-cucumber/ibase.rb', line 121

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

#current_page?Boolean

Returns true if the current view shows this page’s ‘trait`.

Returns:

  • (Boolean)

    true if ‘element_exists(trait)`

See Also:



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

def current_page?
  element_exists(trait)
end

#page(clz, *args) ⇒ Object

Note:

It is assumed that ‘clz` will be a subclass of Calabash::IBase or will

A variant of Cucumber::Core#page that works inside page objects.

behave as such.

Parameters:

  • clz (Class)

    the page object class to instantiate (passing the cucumber world and ‘args`)

  • args (Array)

    optional additional arguments to pass to the page object constructor

Returns:

  • (Object)

    a fresh instance of ‘Class clz` which has been passed a reference to the cucumber World object.

See Also:



100
101
102
# File 'lib/calabash-cucumber/ibase.rb', line 100

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

#traitString

This method is abstract.
Note:

It is recommended that you override this method method in your in your subclasses (option 1 below). Relying on the UINavigationBar title is risky because Apple’s UINavigationBar API changes often.

Specifies a query that recognizes this page.

In your subclass, you have two options to implement this abstract method.

  1. Override the ‘trait` method.

  2. Implement a ‘title` method.

If you implement a ‘title` method, this method will return: `“navigationItemView marked:’#Calabash::IBase.selfself.title‘”`

Examples:

"view marked:'home'"
"tableView marked:'playlist'"
"button marked:'login'"

Returns:

  • (String)

    a query string that identifies this page

Raises:

  • (RuntimeError)

    if the subclass does not respond to ‘title` or the subclass does not override the `trait` method

See Also:



74
75
76
77
78
79
80
81
# File 'lib/calabash-cucumber/ibase.rb', line 74

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

#transition(transition_options = {}) ⇒ IBase

Note:

If a ‘tap` and and `action` are defined, the `action` will be ignored.

Note:

If ‘transition_options` is defined, then it is assumed its value will be a subclass of Calabash::IBase or will behave as such.

Performs a transition from receiver page to another by performing a ‘tap` gesture or a user specified `action`.

Callers must supply a hash of options ‘transition_options` to describe the transition.

Examples:

Use this pattern to wait for ‘transition_duration` after the

the target page's trait becomes visible.

opts = {:tap => "button marked:'login'",
        :wait_options => {:await_animation => true},
        :page => LoginPage}
transition(opts)

Parameters:

  • transition_options (Hash) (defaults to: {})

    options for controlling the transition

Options Hash (transition_options):

  • :tap (String)

    A uiquery used to perform a tap gesture to begin transition.

  • :action (Proc)

    A proc to use begin transition.

  • :page (IBase, Class, nil)

    A page object or page object ‘class` to transition to (target page). If a `class` is provided it is instantiated using the `self.page` method. If no `page` is supplied, `self` is used.

  • :await (Boolean)

    If true the ‘page`’s await will be called after performing the transition that triggers the transition. This is useful for waiting for animations to complete. Defaults to ‘true`.

  • :tap_options (Hash)

    if a ‘tap` gesture is defined then these options will be passed to `touch`.

  • :wait_options (Hash)

    if the :await key is true, then these options are passed to the ‘page.await` method.

Returns:

  • (IBase)

    the page that is transitioned to

Raises:

  • (RuntimeError)

    if ‘transition_options` does not include a non-nil :tap or :action key



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/calabash-cucumber/ibase.rb', line 176

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