Class: Calabash::IBase
- Inherits:
-
Object
- Object
- Calabash::IBase
- 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:
http://developer.xamarin.com/guides/testcloud/calabash/xplat-best-practices/.
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
-
#transition_duration ⇒ Number
The number of seconds to allow for page complete animations after this page trait becomes visible.
-
#world ⇒ Object
A reference to the Cucumber World variable.
Instance Method Summary collapse
-
#await(wait_opts = {}) ⇒ IBase
Waits for this page's
traitto become visible. -
#current_page? ⇒ Boolean
Returns true if the current view shows this page's
trait. -
#initialize(world, transition_duration = 0.5) ⇒ IBase
constructor
Create a new page object.
-
#page(clz, *args) ⇒ Object
A variant of Cucumber::Core#page that works inside page objects.
-
#trait ⇒ String
abstract
Specifies a query that recognizes this page.
-
#transition(transition_options = {}) ⇒ IBase
Performs a transition from receiver page to another by performing a
tapgesture or a user specifiedaction.
Methods included from Cucumber::Operations
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.
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_duration ⇒ Number
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.
33 34 35 |
# File 'lib/calabash-cucumber/ibase.rb', line 33 def transition_duration @transition_duration end |
#world ⇒ Object
A reference to the Cucumber World variable.
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.
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.
86 87 88 |
# File 'lib/calabash-cucumber/ibase.rb', line 86 def current_page? element_exists(trait) end |
#page(clz, *args) ⇒ Object
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.
100 101 102 |
# File 'lib/calabash-cucumber/ibase.rb', line 100 def page(clz, *args) clz.new(world, *args) end |
#trait ⇒ String
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.
- Override the
traitmethod. - Implement a
titlemethod.
If you implement a title method, this method will return:
"navigationItemView marked:'#{self.title}'"
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
If a tap and and action are defined, the action will be
ignored.
If transition_options[:page] 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.
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(={}) uiquery = [:tap] action = [:action] page_arg = [:page] should_await = .has_key?(:await) ? [:await] : true if action.nil? && uiquery.nil? raise "Called transition without providing a gesture (:tap or :action) #{transition_options}" end if uiquery = [:tap_options] || {} touch(uiquery, ) else action.call() end page_obj = page_arg.is_a?(Class) ? page(page_arg) : page_arg page_obj ||= self if should_await wait_opts = [: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 |