calabash 2.0.0.pre11 → 2.0.0.prelegacy

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -5
  3. data/bin/calabash +4 -3
  4. data/lib/calabash/android/adb.rb +37 -34
  5. data/lib/calabash/android/application.rb +1 -1
  6. data/lib/calabash/android/build/builder.rb +1 -1
  7. data/lib/calabash/android/build/java_keystore.rb +1 -1
  8. data/lib/calabash/android/build/resigner.rb +1 -1
  9. data/lib/calabash/android/device.rb +46 -204
  10. data/lib/calabash/android/environment.rb +1 -14
  11. data/lib/calabash/android/gestures.rb +22 -6
  12. data/lib/calabash/android/interactions.rb +17 -14
  13. data/lib/calabash/android/legacy.rb +141 -4
  14. data/lib/calabash/android/lib/.irbrc +1 -9
  15. data/lib/calabash/android/lib/AndroidManifest.xml +2 -23
  16. data/lib/calabash/android/lib/TestServer.apk +0 -0
  17. data/lib/calabash/android/life_cycle.rb +3 -3
  18. data/lib/calabash/android/orientation.rb +8 -8
  19. data/lib/calabash/android/physical_buttons.rb +16 -19
  20. data/lib/calabash/android/server.rb +1 -6
  21. data/lib/calabash/android/text.rb +12 -12
  22. data/lib/calabash/android.rb +26 -92
  23. data/lib/calabash/application.rb +0 -3
  24. data/lib/calabash/cli/generate.rb +18 -8
  25. data/lib/calabash/cli/helpers.rb +9 -4
  26. data/lib/calabash/cli/run.rb +1 -1
  27. data/lib/calabash/console_helpers.rb +11 -179
  28. data/lib/calabash/device.rb +19 -4
  29. data/lib/calabash/gestures.rb +198 -292
  30. data/lib/calabash/http/retriable_client.rb +3 -18
  31. data/lib/calabash/http.rb +0 -1
  32. data/lib/calabash/interactions.rb +40 -3
  33. data/lib/calabash/ios/conditions.rb +1 -1
  34. data/lib/calabash/ios/console_helpers.rb +2 -2
  35. data/lib/calabash/ios/date_picker.rb +8 -10
  36. data/lib/calabash/ios/device/device_implementation.rb +21 -9
  37. data/lib/calabash/ios/device/gestures_mixin.rb +55 -53
  38. data/lib/calabash/ios/device/keyboard_mixin.rb +0 -21
  39. data/lib/calabash/ios/device/rotation_mixin.rb +65 -3
  40. data/lib/calabash/ios/device/text_mixin.rb +21 -0
  41. data/lib/calabash/ios/device.rb +1 -0
  42. data/lib/calabash/ios/gestures.rb +90 -24
  43. data/lib/calabash/ios/interactions.rb +6 -1
  44. data/lib/calabash/ios/lib/.irbrc +2 -9
  45. data/lib/calabash/ios/orientation.rb +8 -8
  46. data/lib/calabash/ios/runtime.rb +14 -14
  47. data/lib/calabash/ios/scroll.rb +17 -25
  48. data/lib/calabash/ios/slider.rb +18 -11
  49. data/lib/calabash/ios/text.rb +74 -20
  50. data/lib/calabash/ios/uia.rb +1 -1
  51. data/lib/calabash/ios.rb +16 -77
  52. data/lib/calabash/legacy.rb +6 -9
  53. data/lib/calabash/lib/skeleton/{Gemfile.skeleton → Gemfile} +0 -0
  54. data/lib/calabash/lib/skeleton/config/{cucumber.yml.skeleton → cucumber.yml} +0 -0
  55. data/lib/calabash/lib/skeleton/features/{sample.feature.skeleton → sample.feature} +0 -0
  56. data/lib/calabash/lib/skeleton/features/step_definitions/{sample_steps.rb.skeleton → calabash_steps.rb} +8 -8
  57. data/lib/calabash/lib/skeleton/features/support/{dry_run.rb.skeleton → dry_run.rb} +5 -2
  58. data/lib/calabash/lib/skeleton/features/support/{env.rb.skeleton → env.rb} +8 -2
  59. data/lib/calabash/lib/skeleton/features/support/hooks.rb +83 -0
  60. data/lib/calabash/life_cycle.rb +8 -16
  61. data/lib/calabash/location.rb +15 -14
  62. data/lib/calabash/orientation.rb +8 -8
  63. data/lib/calabash/page.rb +4 -1
  64. data/lib/calabash/screenshot.rb +3 -3
  65. data/lib/calabash/text.rb +19 -31
  66. data/lib/calabash/utility.rb +8 -41
  67. data/lib/calabash/version.rb +1 -1
  68. data/lib/calabash/wait.rb +192 -177
  69. data/lib/calabash.rb +10 -53
  70. metadata +32 -43
  71. data/lib/calabash/android/device/helper_application.rb +0 -95
  72. data/lib/calabash/android/lib/HelperApplication.apk +0 -0
  73. data/lib/calabash/android/lib/HelperApplicationTestServer.apk +0 -0
  74. data/lib/calabash/android/web.rb +0 -12
  75. data/lib/calabash/http/forwarding_client.rb +0 -23
  76. data/lib/calabash/internal.rb +0 -48
  77. data/lib/calabash/ios/automator/automator.rb +0 -217
  78. data/lib/calabash/ios/automator/coordinates.rb +0 -37
  79. data/lib/calabash/ios/automator/device_agent.rb +0 -379
  80. data/lib/calabash/ios/automator.rb +0 -9
  81. data/lib/calabash/ios/legacy.rb +0 -6
  82. data/lib/calabash/ios/web.rb +0 -10
  83. data/lib/calabash/lib/skeleton/features/support/hooks.rb.skeleton +0 -34
  84. data/lib/calabash/retry.rb +0 -33
  85. data/lib/calabash/stubs.rb +0 -21
  86. data/lib/calabash/web.rb +0 -44
@@ -3,21 +3,21 @@ module Calabash
3
3
  # Methods for entering text and interacting with iOS keyboards.
4
4
  module Text
5
5
  # @!visibility private
6
- define_method(:_enter_text) do |text|
6
+ def _enter_text(text)
7
7
  wait_for_keyboard
8
8
  existing_text = text_from_keyboard_first_responder
9
9
  options = { existing_text: existing_text }
10
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.enter_text(text, options)}
10
+ Device.default.uia_type_string(text, options)
11
11
  end
12
12
 
13
13
  # @!visibility private
14
- define_method(:_enter_text_in) do |view, text|
14
+ def _enter_text_in(view, text)
15
15
  tap(view)
16
16
  enter_text(text)
17
17
  end
18
18
 
19
19
  # @!visibility private
20
- define_method(:_clear_text) do
20
+ def _clear_text
21
21
  unless view_exists?("* isFirstResponder:1")
22
22
  raise 'Cannot clear text. No view has focus'
23
23
  end
@@ -26,7 +26,7 @@ module Calabash
26
26
  end
27
27
 
28
28
  # @!visibility private
29
- define_method(:_clear_text_in) do |view|
29
+ def _clear_text_in(view)
30
30
  unless keyboard_visible?
31
31
  tap(view)
32
32
  wait_for_keyboard
@@ -35,7 +35,6 @@ module Calabash
35
35
  unless wait_for_view(view)['text'].empty?
36
36
  tap(view)
37
37
  tap("UICalloutBarButton marked:'Select All'")
38
- sleep 0.5
39
38
  tap_keyboard_delete_key
40
39
  end
41
40
 
@@ -50,7 +49,7 @@ module Calabash
50
49
  #
51
50
  # @return [Boolean] Returns true if a keyboard is visible and docked.
52
51
  def docked_keyboard_visible?
53
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.docked_keyboard_visible?}
52
+ Device.default.docked_keyboard_visible?
54
53
  end
55
54
 
56
55
  # Returns true if an undocked keyboard is visible.
@@ -60,7 +59,7 @@ module Calabash
60
59
  # @return [Boolean] Returns false if the device is not an iPad; all
61
60
  # keyboards on the iPhone and iPod are docked.
62
61
  def undocked_keyboard_visible?
63
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.undocked_keyboard_visible?}
62
+ Device.default.undocked_keyboard_visible?
64
63
  end
65
64
 
66
65
  # Returns true if a split keyboard is visible.
@@ -71,7 +70,7 @@ module Calabash
71
70
  # @return [Boolean] Returns false if the device is not an iPad; all
72
71
  # keyboards on the Phone and iPod are docked and not split.
73
72
  def split_keyboard_visible?
74
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.split_keyboard_visible?}
73
+ Device.default.split_keyboard_visible?
75
74
  end
76
75
 
77
76
  # Touches the keyboard action key.
@@ -91,29 +90,86 @@ module Calabash
91
90
  # @todo Refactor uia_route to a public API call
92
91
  # @todo Move this documentation to the public method
93
92
  # @!visibility private
94
- define_method(:_tap_keyboard_action_key) do |action_key|
93
+ def _tap_keyboard_action_key(action_key)
95
94
  unless action_key.nil?
96
95
  raise ArgumentError,
97
96
  "An iOS keyboard does not have multiple action keys"
98
97
  end
99
98
 
100
- wait_for_keyboard
101
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.tap_keyboard_action_key}
99
+ char_sequence = ESCAPED_KEYBOARD_CHARACTERS[:action]
100
+ Device.default.uia_route("uia.keyboard().typeString('#{char_sequence}')")
102
101
  end
103
102
 
104
103
  # @!visibility private
105
- define_method(:_keyboard_visible?) do
104
+ def _keyboard_visible?
106
105
  docked_keyboard_visible? || undocked_keyboard_visible? || split_keyboard_visible?
107
106
  end
108
107
 
109
108
  # Touches the keyboard delete key.
109
+ #
110
+ # The 'delete' key difficult to find and touch because its behavior
111
+ # changes depending on the iOS version and keyboard type. Consider the
112
+ # following:
113
+ #
114
+ # On iOS 6, the 'delete' char code is _not_ \b.
115
+ # On iOS 7: The Delete char code is \b on non-numeric keyboards.
116
+ # On numeric keyboards, the delete key is a button on the
117
+ # the keyboard.
118
+ #
119
+ # By default, Calabash uses a raw UIAutomaton JavaScript call to tap the
120
+ # element named 'Delete'. This works well in English localizations for
121
+ # most keyboards. If you find that it does not work, use the options
122
+ # pass either an translation of 'Delete' for your localization or use the
123
+ # default the escaped keyboard character.
124
+ #
110
125
  # @example
111
- # cal_ios.tap_keyboard_delete_key
126
+ # # Uses UIAutomation to tap the 'Delete' key or button.
127
+ # tap_keyboard_delete_key
128
+ #
129
+ # # Types the \b key.
130
+ # tap_keyboard_delete_key({:use_escaped_char => true})
112
131
  #
113
- def tap_keyboard_delete_key
114
- Calabash::Internal.with_default_device(required_os: :ios) do |device|
115
- device.tap_keyboard_delete_key
132
+ # # Types the \d key.
133
+ # tap_keyboard_delete_key({:use_escaped_char => '\d'})
134
+ #
135
+ # # Uses UIAutomation to tap the 'Slet' key or button.
136
+ # tap_keyboard_delete_key({:delete_key_label => 'Slet'})
137
+ #
138
+ # # Don't specify both options! If :use_escape_sequence is truthy,
139
+ # # Calabash will ignore the :delete_key_label and try to use an
140
+ # # escaped character sequence.
141
+ # tap_keyboard_delete_key({:use_escaped_char => true,
142
+ # :delete_key_label => 'Slet'})
143
+ #
144
+ # @param [Hash] options Alternative ways to tap the delete key.
145
+ # @option options [Boolean, String] :use_escaped_char (false) If true,
146
+ # delete by typing the \b character. If this value is truthy, but not
147
+ # 'true', they it is expected to be an alternative escaped character.
148
+ # @option options [String] :delete_key_label ('Delete') An alternative
149
+ # localization of 'Delete'.
150
+ # @todo Need translations of 'Delete' key.
151
+ def tap_keyboard_delete_key(options = {})
152
+ default_options =
153
+ {
154
+ use_escaped_char: false,
155
+ delete_key_label: 'Delete'
156
+ }
157
+ merged_options = default_options.merge(options)
158
+
159
+ use_escape_sequence = merged_options[:use_escaped_char]
160
+ if use_escape_sequence
161
+ if use_escape_sequence.to_s == 'true'
162
+ # Use the default \b
163
+ char_sequence = ESCAPED_KEYBOARD_CHARACTERS[:delete]
164
+ else
165
+ char_sequence = use_escape_sequence
166
+ end
167
+ return Device.default.uia_route("uia.keyboard().typeString('#{char_sequence}')")
116
168
  end
169
+
170
+ delete_key_label = merged_options[:delete_key_label]
171
+ uia = "uia.keyboard().elements().firstWithName('#{delete_key_label}').tap()"
172
+ Device.default.uia_route(uia)
117
173
  end
118
174
 
119
175
  # Returns the the text in the first responder.
@@ -127,9 +183,7 @@ module Calabash
127
183
  #
128
184
  # @raise [RuntimeError] If there is no visible keyboard.
129
185
  def text_from_keyboard_first_responder
130
- Calabash::Internal.with_default_device(required_os: :ios) do |device|
131
- device.text_from_keyboard_first_responder
132
- end
186
+ Device.default.text_from_keyboard_first_responder
133
187
  end
134
188
 
135
189
  private
@@ -17,7 +17,7 @@ module Calabash
17
17
  # uia("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Delete']")
18
18
  # uia("UIATarget.localTarget().frontMostApp().mainWindow().elements()")
19
19
  def uia(script)
20
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.evaluate_uia(script)}
20
+ Device.default.evaluate_uia(script)
21
21
  end
22
22
 
23
23
  # Evaluates `script` after prefixing with "UIATarget.localTarget()"
data/lib/calabash/ios.rb CHANGED
@@ -1,7 +1,21 @@
1
1
  module Calabash
2
- # @!visibility private
3
- module IOSInternal
2
+ # Contains the iOS implementations of the Calabash APIs.
3
+ module IOS
4
4
  require 'calabash'
5
+ include Calabash
6
+
7
+ # @!visibility private
8
+ def self.extended(base)
9
+ Calabash.send(:extended, base)
10
+ end
11
+
12
+ # @!visibility private
13
+ def self.included(base)
14
+ Calabash.send(:included, base)
15
+ end
16
+
17
+ require 'calabash/ios/defaults'
18
+ extend Calabash::IOS::Defaults
5
19
 
6
20
  require 'calabash/ios/environment'
7
21
  require 'calabash/ios/application'
@@ -18,8 +32,6 @@ module Calabash
18
32
  require 'calabash/ios/gestures'
19
33
  require 'calabash/ios/slider'
20
34
  require 'calabash/ios/date_picker'
21
- require 'calabash/ios/automator'
22
- require 'calabash/ios/web'
23
35
 
24
36
  include Calabash::IOS::Conditions
25
37
  include Calabash::IOS::Orientation
@@ -31,79 +43,6 @@ module Calabash
31
43
  include Calabash::IOS::Gestures
32
44
  include Calabash::IOS::Slider
33
45
  include Calabash::IOS::DatePicker
34
- include Calabash::IOS::Web
35
- end
36
-
37
- # Contains the iOS implementations of the Calabash APIs.
38
- module IOS
39
- require 'calabash'
40
- # Hide from documentation
41
- send(:include, Calabash)
42
-
43
- # @!visibility private
44
- def self.extended(base)
45
- Calabash.send(:extended, base)
46
- end
47
46
 
48
- # @!visibility private
49
- def self.included(base)
50
- Calabash.send(:included, base)
51
- end
52
-
53
- include ::Calabash::IOSInternal
54
-
55
- require 'calabash/ios/defaults'
56
- extend Calabash::IOS::Defaults
57
-
58
- require 'calabash/ios/legacy'
59
47
  end
60
48
  end
61
-
62
- # @!visibility private
63
- class CalabashIOSMethodsInternal
64
- include ::Calabash::IOS
65
- end
66
-
67
- # @!visibility private
68
- class CalabashIOSMethods < BasicObject
69
- include ::Calabash::IOSInternal
70
-
71
- instance_methods.each do |method_name|
72
- define_method(method_name) do |*args, &block|
73
- ::CalabashIOSMethodsInternal.new.send(method_name, *args, &block)
74
- end
75
- end
76
- end
77
-
78
- # Returns a object that exposes all of the public Calabash iOS API.
79
- # This method should *always* be used to access the Calabash API. By default,
80
- # all methods are executed using the default device and the default
81
- # application.
82
- #
83
- # For iOS specific methods use {cal_android}. For cross-platform methods use
84
- # {cal}.
85
- #
86
- # All iOS API methods are available with documentation in {Calabash::IOS}
87
- #
88
- # @see Calabash::IOS
89
- #
90
- # @return [Object] Instance responding to all Calabash iOS methods
91
- # in the API.
92
- def cal_ios
93
- CalabashIOSMethods.new
94
- end
95
-
96
- # We also want to patch `cal` to invoke the iOS implementations
97
- class CalabashMethodsInternal
98
- include ::Calabash::IOS
99
-
100
- instance_methods.each do |method_name|
101
- define_method(method_name) do |*args, &block|
102
- ::CalabashIOSMethodsInternal.new.send(method_name, *args, &block)
103
- end
104
- end
105
- end
106
-
107
- if defined?(::Calabash::AndroidInternal)
108
- raise Calabash::RequiredBothPlatformsError, "Cannot require both calabash/android and calabash/ios"
109
- end
@@ -1,10 +1,7 @@
1
- if Calabash::Environment.variable('TEST_APP_PATH')
2
- Calabash::Logger.warn("Deprecated use of old ENV variable 'TEST_APP_PATH'")
3
- Calabash::Environment::TEST_SERVER_PATH =
4
- Calabash::Environment.variable('TEST_APP_PATH')
5
- end
6
-
7
- if Calabash::Environment.variable('APP_PATH')
8
- Calabash::Logger.warn("Deprecated use of old ENV variable 'APP_PATH'")
9
- Calabash::Environment::APP_PATH = Calabash::Environment.variable('APP_PATH')
1
+ module Calabash
2
+ class Application
3
+ def md5_checksum
4
+ 'samplechecksum'
5
+ end
6
+ end
10
7
  end
@@ -1,10 +1,10 @@
1
1
  Given(/^I have done a specific thing$/) do
2
2
  # Sample step definition
3
3
  # Example: (Given I am logged in)
4
- # cal.enter_text({marked: 'username'}, USERNAME)
5
- # cal.enter_text({marked: 'password'}, PASSWORD)
6
- # cal.tap({marked: 'login'}")
7
- # cal.wait_for_view("* text:'Welcome #{USERNAME}'")
4
+ # enter_text("* marked:'username'", USERNAME)
5
+ # enter_text("* marked:'password'", PASSWORD)
6
+ # touch("* marked:'login'")
7
+ # wait_for_view("* text:'Welcome #{USERNAME}'")
8
8
 
9
9
  # Remember: any Ruby is allowed in your step definitions
10
10
  did_something = true
@@ -17,13 +17,13 @@ end
17
17
  When(/^I do something$/) do
18
18
  # Sample step definition
19
19
  # Example: When I create a new entry
20
- # cal.tap({marked:'new_entry'})
21
- # cal.enter_text({marked: 'entry_title'}, 'My Entry')
22
- # cal.tap({marked: 'submit'})
20
+ # touch("* marked:'new_entry'")
21
+ # enter_text("* marked:'entry_title'", 'My Entry')
22
+ # touch("* marked:'submit'")
23
23
  end
24
24
 
25
25
  Then(/^something should happen$/) do
26
26
  # Sample step definition
27
27
  # Example: Then I should see the entry on my home page
28
- # cal.wait_for_view({text: 'My Entry'})
28
+ # wait_for_view("* text:'My Entry'")
29
29
  end
@@ -1,5 +1,8 @@
1
1
  # Cucumber does not load env.rb when running a dry-run. As the pages inherit
2
2
  # from Calabash::Page and assert that the scopes IOS and Android are defined,
3
- # we should require calabash stubs, which are empty scopes.
3
+ # we should require calabash.
4
4
 
5
- require 'calabash/stubs'
5
+ if ARGV.include?('--dry-run')
6
+ require 'calabash/android'
7
+ require 'calabash/ios'
8
+ end
@@ -1,4 +1,6 @@
1
1
  require 'calabash'
2
+ require 'calabash/android/application'
3
+ require 'calabash/ios/application'
2
4
 
3
5
  platform = ENV['PLATFORM']
4
6
 
@@ -10,7 +12,7 @@ unless platform
10
12
  elsif application.ios_application?
11
13
  platform = 'ios'
12
14
  else
13
- raise "Application '#{application}' is neither an Android app nor an iOS app"
15
+ raise "Application '#{application}' is neither an Android app or an iOS app"
14
16
  end
15
17
  end
16
18
 
@@ -18,10 +20,14 @@ case platform
18
20
  when 'android'
19
21
  require 'calabash/android'
20
22
 
23
+ World(Calabash::Android)
24
+
21
25
  Calabash::Android.setup_defaults!
22
26
  when 'ios'
23
27
  require 'calabash/ios'
24
28
 
29
+ World(Calabash::IOS)
30
+
25
31
  Calabash::IOS.setup_defaults!
26
32
  else
27
33
  message = if platform.nil? || platform.empty?
@@ -34,7 +40,7 @@ case platform
34
40
  [
35
41
  'ERROR! Unable to start the cucumber test:',
36
42
  message,
37
- "Run cucumber with the ENV variable 'CAL_APP' set to the path of the application under test, or specify 'PLATFORM'"
43
+ "Run cucumber with the ENV variable 'CAL_APP', or run cucumber using $ calabash run"
38
44
  ]
39
45
 
40
46
  Calabash::Logger.error(failure_messages.join("\n"))
@@ -0,0 +1,83 @@
1
+ require 'calabash'
2
+
3
+ Before do |scenario|
4
+ if scenario.respond_to?(:scenario_outline)
5
+ scenario = scenario.scenario_outline
6
+ end
7
+
8
+ AppLifeCycle.on_new_scenario(scenario)
9
+
10
+ start_app
11
+ end
12
+
13
+ After do
14
+ stop_app
15
+ end
16
+
17
+ module AppLifeCycle
18
+ # Since this is a module, the methods in the Cucumber World are not
19
+ # available inside the scope of this module. We can safely include Calabash
20
+ # because we will not affect the scope outside this module. The methods are
21
+ # loaded as class (static) methods.
22
+ class << self
23
+ include Calabash
24
+ end
25
+
26
+ DEFAULT_RESET_BETWEEN = #!DEFAULT_RESET_BETWEEN#! # Filled in by calabash generate
27
+ DEFAULT_RESET_METHOD = #!DEFAULT_RESET_METHOD#! # Filled in by calabash generate
28
+
29
+ RESET_BETWEEN = if Calabash::Environment.variable('RESET_BETWEEN')
30
+ Calabash::Environment.variable('RESET_BETWEEN').downcase.to_sym
31
+ else
32
+ DEFAULT_RESET_BETWEEN
33
+ end
34
+
35
+ RESET_METHOD = if Calabash::Environment.variable('RESET_METHOD')
36
+ Calabash::Environment.variable('RESET_METHOD').downcase.to_sym
37
+ else
38
+ DEFAULT_RESET_METHOD
39
+ end
40
+
41
+ def self.on_new_scenario(scenario)
42
+ # Ensure the app is installed at the beginning of the test,
43
+ # if we never reset
44
+ if @last_feature.nil? && RESET_BETWEEN == :never
45
+ ensure_app_installed
46
+ end
47
+
48
+ if should_reset?(scenario)
49
+ reset
50
+ end
51
+
52
+ @last_feature = scenario.feature
53
+ end
54
+
55
+ private
56
+
57
+ def self.should_reset?(scenario)
58
+ case RESET_BETWEEN
59
+ when :scenarios
60
+ true
61
+ when :features
62
+ scenario.feature != @last_feature
63
+ when :never
64
+ false
65
+ else
66
+ raise "Invalid reset between option '#{RESET_BETWEEN}'"
67
+ end
68
+ end
69
+
70
+ def self.reset
71
+ case RESET_METHOD
72
+ when :reinstall
73
+ install_app
74
+ when :clear
75
+ ensure_app_installed
76
+ clear_app_data
77
+ when '', nil
78
+ raise 'No reset method given'
79
+ else
80
+ raise "Invalid reset method '#{RESET_METHOD}'"
81
+ end
82
+ end
83
+ end
@@ -38,13 +38,13 @@ module Calabash
38
38
  raise 'No application given, and Calabash.default_application is not set'
39
39
  end
40
40
 
41
- Calabash::Internal.with_default_device {|device| device.start_app(path_or_application, options.dup)}
41
+ Device.default.start_app(path_or_application, options.dup)
42
42
  end
43
43
 
44
44
  # Stop the app running on
45
45
  # {Calabash::Defaults#default_server Calabash.default_server}
46
46
  def stop_app
47
- Calabash::Internal.with_default_device {|device| device.stop_app}
47
+ Device.default.stop_app
48
48
  end
49
49
 
50
50
  # Installs the given application. If the application is already installed,
@@ -67,7 +67,7 @@ module Calabash
67
67
  raise 'No application given, and Calabash.default_application is not set'
68
68
  end
69
69
 
70
- Calabash::Internal.with_default_device {|device| device.install_app(path_or_application)}
70
+ Device.default.install_app(path_or_application)
71
71
  end
72
72
 
73
73
  # Installs the given application *if it is not already installed*. If no
@@ -90,7 +90,7 @@ module Calabash
90
90
  raise 'No application given, and Calabash.default_application is not set'
91
91
  end
92
92
 
93
- Calabash::Internal.with_default_device {|device| device.ensure_app_installed(path_or_application)}
93
+ Device.default.ensure_app_installed(path_or_application)
94
94
  end
95
95
 
96
96
  # Uninstalls the given application. Does nothing if the application is
@@ -108,7 +108,7 @@ module Calabash
108
108
  raise 'No application given, and Calabash.default_application is not set'
109
109
  end
110
110
 
111
- Calabash::Internal.with_default_device {|device| device.uninstall_app(path_or_application)}
111
+ Device.default.uninstall_app(path_or_application)
112
112
  end
113
113
 
114
114
  # Clears the contents of the given application. This is roughly equivalent to
@@ -126,7 +126,7 @@ module Calabash
126
126
  raise 'No application given, and Calabash.default_application is not set'
127
127
  end
128
128
 
129
- Calabash::Internal.with_default_device {|device| device.clear_app_data(path_or_application)}
129
+ Device.default.clear_app_data(path_or_application)
130
130
  end
131
131
 
132
132
  # Sends the current app to the background and resumes it after
@@ -150,17 +150,9 @@ module Calabash
150
150
  true
151
151
  end
152
152
 
153
- # Attempts to reset the changes Calabash has made to the device.
154
- #
155
- # This method does nothing at the moment, but will be required to reset the
156
- # device changes in the future.
157
- def reset_device_changes
158
- true
159
- end
160
-
161
153
  # @!visibility private
162
- define_method(:_send_current_app_to_background) do |for_seconds|
163
- abstract_method!(:_send_current_app_to_background)
154
+ def _send_current_app_to_background(for_seconds)
155
+ abstract_method!
164
156
  end
165
157
  end
166
158
  end
@@ -5,39 +5,40 @@ module Calabash
5
5
  # An API for setting the location of your app.
6
6
  module Location
7
7
  # Simulates gps location of the device/simulator.
8
+ # @note Seems UIAutomation is broken here on physical devices on iOS 7.1
8
9
  #
9
10
  # @example
10
- # cal.set_location(latitude: 48.8567, longitude: 2.3508)
11
+ # set_location({latitude: 48.8567, longitude: 2.3508})
11
12
  #
12
13
  # @example
13
- # cal.set_location(coordinates_for_place('The little mermaid, Copenhagen'))
14
+ # set_location(coordinates_for_place('The little mermaid, Copenhagen'))
14
15
  #
15
- # @param [Number] latitude The latitude of the location to simulate.
16
- # @param [Number] longitude The longitude of the location to simulate.
17
- # @raise [ArgumentError] If not given a latitude or longitude key.
18
- def set_location(latitude: nil, longitude: nil)
19
- unless latitude
20
- raise ArgumentError, "Expected latitude to be a number, not '#{latitude.class}'"
16
+ # @param [Hash] location The location to simulate.
17
+ # @raise [ArgumentError] If location is not a hash and does not contain a
18
+ # latitude and longitude key.
19
+ def set_location(location)
20
+ unless location.is_a?(Hash)
21
+ raise ArgumentError, "Expected location to be a Hash, not '#{location.class}'"
21
22
  end
22
23
 
23
- unless longitude
24
- raise ArgumentError, "Expected longitude to be a number, not '#{longitude.class}'"
24
+ unless location[:latitude] || location[:longitude]
25
+ raise ArgumentError, 'You must supply :latitude and :longitude'
25
26
  end
26
27
 
27
- Calabash::Internal.with_default_device {|device| device.set_location(latitude: latitude, longitude: longitude)}
28
+ Device.default.set_location(location)
28
29
  end
29
30
 
30
31
  # Get the latitude and longitude for a certain place, resolved via Google
31
32
  # maps api. This hash can be used in `set_location`.
32
33
  #
33
34
  # @example
34
- # cal.coordinates_for_place('The little mermaid, Copenhagen')
35
+ # coordinates_for_place('The little mermaid, Copenhagen')
35
36
  # # => {:latitude => 55.6760968, :longitude => 12.5683371}
36
37
  #
37
38
  # @return [Hash] Latitude and longitude for the given place
38
39
  # @raise [RuntimeError] If the place cannot be found
39
- def coordinates_for_place(place_name)
40
- result = Geocoder.search(place_name)
40
+ def coordinates_for_place(place)
41
+ result = Geocoder.search(place)
41
42
 
42
43
  if result.empty?
43
44
  raise "No result found for '#{place}'"
@@ -62,23 +62,23 @@ module Calabash
62
62
  end
63
63
 
64
64
  # @!visibility private
65
- define_method(:_portrait?) do
66
- abstract_method!(:_portrait?)
65
+ def _portrait?
66
+ abstract_method!
67
67
  end
68
68
 
69
69
  # @!visibility private
70
- define_method(:_landscape?) do
71
- abstract_method!(:_landscape?)
70
+ def _landscape?
71
+ abstract_method!
72
72
  end
73
73
 
74
74
  # @!visibility private
75
- define_method(:_set_orientation_portrait) do
76
- abstract_method!(:_set_orientation_portrait)
75
+ def _set_orientation_portrait
76
+ abstract_method!
77
77
  end
78
78
 
79
79
  # @!visibility private
80
- define_method(:_set_orientation_landscape) do
81
- abstract_method!(:_set_orientation_landscape)
80
+ def _set_orientation_landscape
81
+ abstract_method!
82
82
  end
83
83
  end
84
84
  end
data/lib/calabash/page.rb CHANGED
@@ -8,6 +8,9 @@ module Calabash
8
8
  # * https://github.com/calabash/calabash/tree/develop/samples/wordpress
9
9
  # * https://github.com/calabash/calabash/tree/develop/samples/shared-page-logic
10
10
  class Page
11
+ # For auto-completion
12
+ include Calabash
13
+
11
14
  # @!visibility private
12
15
  def self.inherited(subclass)
13
16
  # Define the page into global scope
@@ -68,7 +71,7 @@ module Calabash
68
71
 
69
72
  # Waits for the page trait to appear.
70
73
  def await(options={})
71
- cal.wait_for_view(trait, options)
74
+ wait_for_view(trait, options)
72
75
  end
73
76
 
74
77
  # @!visibility private