calabash 1.2.1 → 1.9.9.pre1

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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +39 -0
  3. data/LICENSE +204 -21
  4. data/README.md +36 -6
  5. data/VERSIONING.md +16 -0
  6. data/bin/calabash +95 -0
  7. data/lib/calabash.rb +185 -1
  8. data/lib/calabash/android.rb +64 -0
  9. data/lib/calabash/android/adb.rb +277 -0
  10. data/lib/calabash/android/application.rb +110 -0
  11. data/lib/calabash/android/build.rb +12 -0
  12. data/lib/calabash/android/build/application.rb +13 -0
  13. data/lib/calabash/android/build/build_error.rb +11 -0
  14. data/lib/calabash/android/build/builder.rb +119 -0
  15. data/lib/calabash/android/build/java_keystore.rb +177 -0
  16. data/lib/calabash/android/build/resigner.rb +56 -0
  17. data/lib/calabash/android/build/test_server.rb +27 -0
  18. data/lib/calabash/android/console_helpers.rb +44 -0
  19. data/lib/calabash/android/cucumber.rb +3 -0
  20. data/lib/calabash/android/device.rb +965 -0
  21. data/lib/calabash/android/environment.rb +470 -0
  22. data/lib/calabash/android/gestures.rb +369 -0
  23. data/lib/calabash/android/interactions.rb +45 -0
  24. data/lib/calabash/android/lib/.irbrc +55 -0
  25. data/lib/calabash/android/lib/AndroidManifest.xml +51 -0
  26. data/lib/calabash/android/lib/TestServer.apk +0 -0
  27. data/lib/calabash/android/lib/calmd5/arm64-v8a/calmd5 +0 -0
  28. data/lib/calabash/android/lib/calmd5/arm64-v8a/calmd5-pie +0 -0
  29. data/lib/calabash/android/lib/calmd5/armeabi-v7a/calmd5 +0 -0
  30. data/lib/calabash/android/lib/calmd5/armeabi-v7a/calmd5-pie +0 -0
  31. data/lib/calabash/android/lib/calmd5/armeabi/calmd5 +0 -0
  32. data/lib/calabash/android/lib/calmd5/armeabi/calmd5-pie +0 -0
  33. data/lib/calabash/android/lib/calmd5/mips/calmd5 +0 -0
  34. data/lib/calabash/android/lib/calmd5/mips/calmd5-pie +0 -0
  35. data/lib/calabash/android/lib/calmd5/mips64/calmd5 +0 -0
  36. data/lib/calabash/android/lib/calmd5/mips64/calmd5-pie +0 -0
  37. data/lib/calabash/android/lib/calmd5/x86/calmd5 +0 -0
  38. data/lib/calabash/android/lib/calmd5/x86/calmd5-pie +0 -0
  39. data/lib/calabash/android/lib/calmd5/x86_64/calmd5 +0 -0
  40. data/lib/calabash/android/lib/calmd5/x86_64/calmd5-pie +0 -0
  41. data/lib/calabash/android/lib/screenshot_taker.jar +0 -0
  42. data/lib/calabash/android/life_cycle.rb +37 -0
  43. data/lib/calabash/android/orientation.rb +30 -0
  44. data/lib/calabash/android/physical_buttons.rb +39 -0
  45. data/lib/calabash/android/screenshot.rb +9 -0
  46. data/lib/calabash/android/scroll.rb +5 -0
  47. data/lib/calabash/android/server.rb +10 -0
  48. data/lib/calabash/android/text.rb +54 -0
  49. data/lib/calabash/application.rb +74 -0
  50. data/lib/calabash/cli.rb +12 -0
  51. data/lib/calabash/cli/build.rb +33 -0
  52. data/lib/calabash/cli/console.rb +90 -0
  53. data/lib/calabash/cli/generate.rb +110 -0
  54. data/lib/calabash/cli/helpers.rb +130 -0
  55. data/lib/calabash/cli/resign.rb +33 -0
  56. data/lib/calabash/cli/run.rb +99 -0
  57. data/lib/calabash/cli/setup_keystore.rb +39 -0
  58. data/lib/calabash/color.rb +32 -0
  59. data/lib/calabash/console_helpers.rb +90 -0
  60. data/lib/calabash/defaults.rb +56 -0
  61. data/lib/calabash/device.rb +401 -0
  62. data/lib/calabash/environment.rb +75 -0
  63. data/lib/calabash/gestures.rb +384 -0
  64. data/lib/calabash/http.rb +8 -0
  65. data/lib/calabash/http/error.rb +15 -0
  66. data/lib/calabash/http/request.rb +42 -0
  67. data/lib/calabash/http/retriable_client.rb +156 -0
  68. data/lib/calabash/interactions.rb +105 -0
  69. data/lib/calabash/ios.rb +37 -0
  70. data/lib/calabash/ios/application.rb +119 -0
  71. data/lib/calabash/ios/conditions.rb +79 -0
  72. data/lib/calabash/ios/console_helpers.rb +72 -0
  73. data/lib/calabash/ios/device.rb +24 -0
  74. data/lib/calabash/ios/device/device_implementation.rb +779 -0
  75. data/lib/calabash/ios/device/gestures_mixin.rb +167 -0
  76. data/lib/calabash/ios/device/keyboard_mixin.rb +133 -0
  77. data/lib/calabash/ios/device/physical_device_mixin.rb +266 -0
  78. data/lib/calabash/ios/device/rotation_mixin.rb +124 -0
  79. data/lib/calabash/ios/device/routes/backdoor_route_mixin.rb +86 -0
  80. data/lib/calabash/ios/device/routes/condition_route_mixin.rb +62 -0
  81. data/lib/calabash/ios/device/routes/error.rb +8 -0
  82. data/lib/calabash/ios/device/routes/handle_route_mixin.rb +102 -0
  83. data/lib/calabash/ios/device/routes/map_route_mixin.rb +38 -0
  84. data/lib/calabash/ios/device/routes/playback_route_mixin.rb +70 -0
  85. data/lib/calabash/ios/device/routes/response_parser.rb +48 -0
  86. data/lib/calabash/ios/device/routes/uia_route_mixin.rb +238 -0
  87. data/lib/calabash/ios/device/runtime_attributes.rb +184 -0
  88. data/lib/calabash/ios/device/status_bar_mixin.rb +17 -0
  89. data/lib/calabash/ios/device/text_mixin.rb +19 -0
  90. data/lib/calabash/ios/device/uia_keyboard_mixin.rb +188 -0
  91. data/lib/calabash/ios/device/uia_mixin.rb +12 -0
  92. data/lib/calabash/ios/environment.rb +41 -0
  93. data/lib/calabash/ios/interactions.rb +10 -0
  94. data/lib/calabash/ios/lib/.irbrc +55 -0
  95. data/lib/calabash/ios/lib/recordings/rotate_left_home_down_ipad.base64 +2 -0
  96. data/lib/calabash/ios/lib/recordings/rotate_left_home_down_iphone.base64 +2 -0
  97. data/lib/calabash/ios/lib/recordings/rotate_left_home_left_ipad.base64 +2 -0
  98. data/lib/calabash/ios/lib/recordings/rotate_left_home_left_iphone.base64 +2 -0
  99. data/lib/calabash/ios/lib/recordings/rotate_left_home_right_ipad.base64 +2 -0
  100. data/lib/calabash/ios/lib/recordings/rotate_left_home_right_iphone.base64 +2 -0
  101. data/lib/calabash/ios/lib/recordings/rotate_left_home_up_ipad.base64 +2 -0
  102. data/lib/calabash/ios/lib/recordings/rotate_left_home_up_iphone.base64 +2 -0
  103. data/lib/calabash/ios/lib/recordings/rotate_right_home_down_ipad.base64 +2 -0
  104. data/lib/calabash/ios/lib/recordings/rotate_right_home_down_iphone.base64 +2 -0
  105. data/lib/calabash/ios/lib/recordings/rotate_right_home_left_ipad.base64 +2 -0
  106. data/lib/calabash/ios/lib/recordings/rotate_right_home_left_iphone.base64 +2 -0
  107. data/lib/calabash/ios/lib/recordings/rotate_right_home_right_ipad.base64 +2 -0
  108. data/lib/calabash/ios/lib/recordings/rotate_right_home_right_iphone.base64 +2 -0
  109. data/lib/calabash/ios/lib/recordings/rotate_right_home_up_ipad.base64 +2 -0
  110. data/lib/calabash/ios/lib/recordings/rotate_right_home_up_iphone.base64 +2 -0
  111. data/lib/calabash/ios/orientation.rb +117 -0
  112. data/lib/calabash/ios/scroll.rb +504 -0
  113. data/lib/calabash/ios/server.rb +73 -0
  114. data/lib/calabash/ios/text.rb +248 -0
  115. data/lib/calabash/ios/uia.rb +24 -0
  116. data/lib/calabash/lib/skeleton/config/cucumber.yml +6 -0
  117. data/lib/calabash/lib/skeleton/features/sample.feature +5 -0
  118. data/lib/calabash/lib/skeleton/features/step_definitions/calabash_steps.rb +29 -0
  119. data/lib/calabash/lib/skeleton/features/support/env.rb +54 -0
  120. data/lib/calabash/lib/skeleton/features/support/hooks.rb +83 -0
  121. data/lib/calabash/life_cycle.rb +111 -0
  122. data/lib/calabash/location.rb +51 -0
  123. data/lib/calabash/logger.rb +87 -0
  124. data/lib/calabash/orientation.rb +84 -0
  125. data/lib/calabash/page.rb +35 -0
  126. data/lib/calabash/patch.rb +14 -0
  127. data/lib/calabash/patch/array.rb +16 -0
  128. data/lib/calabash/patch/run_loop.rb +90 -0
  129. data/lib/calabash/query.rb +160 -0
  130. data/lib/calabash/query_result.rb +85 -0
  131. data/lib/calabash/screenshot.rb +89 -0
  132. data/lib/calabash/server.rb +16 -0
  133. data/lib/calabash/text.rb +76 -0
  134. data/lib/calabash/utility.rb +58 -0
  135. data/lib/calabash/version.rb +3 -1
  136. data/lib/calabash/wait.rb +474 -0
  137. metadata +462 -24
@@ -0,0 +1,90 @@
1
+ require 'clipboard'
2
+
3
+ module Calabash
4
+ module ConsoleHelpers
5
+ # Outputs all visible elements as a tree
6
+ def tree
7
+ ConsoleHelpers.dump(Device.default.dump)
8
+ true
9
+ end
10
+
11
+ def self.save_old_readline_history
12
+ file_name = IRB.conf[:HISTORY_FILE]
13
+
14
+ if File.exist?(file_name)
15
+ @@start_readline_history = File.readlines(file_name).map(&:chomp)
16
+ end
17
+ end
18
+
19
+ def self.extended(base)
20
+ save_old_readline_history
21
+ end
22
+
23
+ def classes
24
+ query("*").map{|e| e['class']}.uniq
25
+ end
26
+
27
+ def ids
28
+ query("*").map{|e| e['id']}.compact
29
+ end
30
+
31
+ def copy
32
+ ConsoleHelpers.copy
33
+ true
34
+ end
35
+
36
+ def self.copy
37
+ commands = filter_commands(current_console_history)
38
+ string = commands.join($INPUT_RECORD_SEPARATOR)
39
+ Clipboard.copy(string)
40
+ end
41
+
42
+ def self.current_console_history
43
+ length = readline_history.length - @@start_readline_history.length
44
+
45
+ readline_history.last(length)
46
+ end
47
+
48
+ FILTER_REGEX = Regexp.union(/\s*copy(\(|\z)/, /\s*tree(\(|\z)/,
49
+ /\s*flash(\(|\z)/, /\s*classes(\(|\z)/,
50
+ /\s*ids(\(|\z)/, /\s*start_app(\(|\z)/,
51
+ /\s*install_app(\(|\z)/,
52
+ /\s*ensure_app_installed(\(|\z)/,
53
+ /\s*uninstall_app(\(|\z)/,
54
+ /\s*clear_app(\(|\z)/,
55
+ /\s*stop_app(\(|\z)/)
56
+
57
+ def self.filter_commands(commands)
58
+ commands.reject {|command| command =~ FILTER_REGEX}
59
+ end
60
+
61
+ def self.readline_history
62
+ Readline::HISTORY.to_a
63
+ end
64
+
65
+ def self.dump(json_data)
66
+ json_data['children'].each {|child| write_child(child)}
67
+ end
68
+
69
+ def self.write_child(data, indentation=0)
70
+ render(data, indentation)
71
+
72
+ data['children'].each do |child|
73
+ write_child(child, indentation+1)
74
+ end
75
+ end
76
+
77
+ def self.render(data, indentation)
78
+ raise AbstractMethodError
79
+ end
80
+
81
+ def self.output(string, indentation)
82
+ (indentation*2).times {print " "}
83
+ print "#{string}"
84
+ end
85
+
86
+ def self.visible?(data)
87
+ raise AbstractMethodError
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,56 @@
1
+ module Calabash
2
+ module Defaults
3
+ # Get the default device. The device represents a physical device,
4
+ # an emulator, or a simulator. Calabash will communicate with this
5
+ # device by default.
6
+ #
7
+ # @return [Calabash::Device] The default device
8
+ def default_device
9
+ Device.default
10
+ end
11
+
12
+ # Set the default device.
13
+ #
14
+ # @see #Calabash::Defaults#default_device
15
+ def default_device=(device)
16
+ Device.default = device
17
+ end
18
+
19
+ # Get the default application. The application represents an .ipa, .app, or
20
+ # .apk. For Android, the application can represent a test-server along side
21
+ # the application under test. Calabash will use this application by
22
+ # default, for example when calling install_app.
23
+ #
24
+ # @return [Calabash::Application] The default application
25
+ def default_application
26
+ Application.default
27
+ end
28
+
29
+ # Set the default application.
30
+ #
31
+ # @see #Calabash::Defaults.default_application
32
+ def default_application=(application)
33
+ Application.default = application
34
+ end
35
+
36
+ # Get the default server. The default server is the test-server
37
+ # of the `#default_device`.
38
+ #
39
+ # @raise [RuntimeError] If default device is not set
40
+ def default_server
41
+ if default_device.nil?
42
+ raise 'No default device set'
43
+ end
44
+
45
+ default_device.server
46
+ end
47
+
48
+ # Set the default server.
49
+ #
50
+ # @see #Calabash::Defaults.default_server
51
+ # @raise [RuntimeError] If default device is not set
52
+ def default_server=(server)
53
+ default_device.change_server(server)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,401 @@
1
+ module Calabash
2
+ class Device
3
+ include Utility
4
+
5
+ @@default = nil
6
+
7
+ def self.default
8
+ @@default
9
+ end
10
+
11
+ def self.default=(value)
12
+ @@default = value
13
+ end
14
+
15
+ attr_reader :identifier, :server, :http_client, :logger
16
+
17
+ # Create a new device.
18
+ # @param [String] identifier A token that uniquely identifies the device.
19
+ # On iOS, this is the device UDID, or a simulator name or UDID returned by
20
+ # `$ xcrun instruments -s devices`.
21
+ # On Android, this is the serial of the device, emulator or simulator
22
+ # returned by `$ adb devices`.
23
+ # @param [Server] server A server object.
24
+ #
25
+ # @return [Device] A device.
26
+ def initialize(identifier, server, options={})
27
+ @identifier = identifier
28
+ @server = server
29
+ @logger = options[:logger] || Calabash::Logger.new
30
+ @http_client = HTTP::RetriableClient.new(server, options.fetch(:http_options, {}))
31
+ end
32
+
33
+ def change_server(new_server)
34
+ @server = new_server
35
+ @http_client.change_server(new_server)
36
+ end
37
+
38
+ # Start the application and the test server
39
+ def start_app(path_or_application, options={})
40
+ application = parse_path_or_app_parameters(path_or_application)
41
+
42
+ _start_app(application, options)
43
+ end
44
+
45
+ # Shutdown the application and the test server
46
+ def stop_app
47
+ _stop_app
48
+ end
49
+
50
+ # @see Screenshot#screenshot
51
+ def screenshot(name=nil)
52
+ path = Screenshot.obtain_screenshot_path!(name)
53
+
54
+ _screenshot(path)
55
+ end
56
+
57
+ def install_app(path_or_application)
58
+ application = parse_path_or_app_parameters(path_or_application)
59
+
60
+ _install_app(application)
61
+ end
62
+
63
+ def ensure_app_installed(path_or_application)
64
+ application = parse_path_or_app_parameters(path_or_application)
65
+
66
+ _ensure_app_installed(application)
67
+ end
68
+
69
+ def uninstall_app(path_or_application)
70
+ application = parse_path_or_app_parameters(path_or_application)
71
+
72
+ _uninstall_app(application)
73
+ end
74
+
75
+ def clear_app_data(path_or_application)
76
+ application = parse_path_or_app_parameters(path_or_application)
77
+
78
+ _clear_app_data(application)
79
+ end
80
+
81
+ def set_location(location)
82
+ abstract_method!
83
+ end
84
+
85
+ def dump
86
+ request = HTTP::Request.new('/dump')
87
+
88
+ JSON.parse(http_client.get(request, timeout: 60).body)
89
+ end
90
+
91
+ # @!visibility private
92
+ class EnsureTestServerReadyTimeoutError < RuntimeError; end
93
+
94
+ # Ensures the test server is ready
95
+ #
96
+ # @raise [RuntimeError] Raises error when the server does not respond
97
+ def ensure_test_server_ready(options={})
98
+ begin
99
+ Timeout.timeout(options.fetch(:timeout, 30), EnsureTestServerReadyTimeoutError) do
100
+ loop do
101
+ break if test_server_responding?
102
+ end
103
+ end
104
+ rescue EnsureTestServerReadyTimeoutError => _
105
+ raise 'Calabash server did not respond'
106
+ end
107
+ end
108
+
109
+ # @!visibility private
110
+ def test_server_responding?
111
+ abstract_method!
112
+ end
113
+
114
+ # Performs a `tap` on the (first) view that matches `query`.
115
+ # @see Calabash::Gestures#tap
116
+ def tap(query, options={})
117
+ Query.ensure_valid_query(query)
118
+
119
+ gesture_options = options.dup
120
+ gesture_options[:at] ||= {}
121
+ gesture_options[:at][:x] ||= 50
122
+ gesture_options[:at][:y] ||= 50
123
+ gesture_options[:offset] ||= {}
124
+ gesture_options[:offset][:x] ||= 0
125
+ gesture_options[:offset][:y] ||= 0
126
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
127
+
128
+ _tap(query, gesture_options)
129
+ end
130
+
131
+ # Performs a `double_tap` on the (first) view that matches `query`.
132
+ # @see Calabash::Gestures#double_tap
133
+ def double_tap(query, options={})
134
+ Query.ensure_valid_query(query)
135
+
136
+ gesture_options = options.dup
137
+ gesture_options[:at] ||= {}
138
+ gesture_options[:at][:x] ||= 50
139
+ gesture_options[:at][:y] ||= 50
140
+ gesture_options[:offset] ||= {}
141
+ gesture_options[:offset][:x] ||= 0
142
+ gesture_options[:offset][:y] ||= 0
143
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
144
+
145
+ _double_tap(query, gesture_options)
146
+ end
147
+
148
+ # Performs a `long_press` on the (first) view that matches `query`.
149
+ # @see Calabash::Gestures#long_press
150
+ def long_press(query, options={})
151
+ Query.ensure_valid_query(query)
152
+
153
+ gesture_options = options.dup
154
+ gesture_options[:at] ||= {}
155
+ gesture_options[:at][:x] ||= 50
156
+ gesture_options[:at][:y] ||= 50
157
+ gesture_options[:offset] ||= {}
158
+ gesture_options[:offset][:x] ||= 0
159
+ gesture_options[:offset][:y] ||= 0
160
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
161
+ gesture_options[:duration] ||= 1
162
+
163
+ _long_press(query, gesture_options)
164
+ end
165
+
166
+ # Performs a `pan` on the (first) view that matches `query`.
167
+ # @see Calabash::Gestures#pan
168
+ def pan(query, from, to, options={})
169
+ Query.ensure_valid_query(query)
170
+
171
+ ensure_valid_swipe_params(from, to)
172
+
173
+ gesture_options = options.dup
174
+ gesture_options[:duration] ||= 0.5
175
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
176
+
177
+ _pan(query, from, to, gesture_options)
178
+ end
179
+
180
+ # Performs a `pan` between two elements.
181
+ # @see Calabash::Gestures#pan_between
182
+ def pan_between(query_from, query_to, options={})
183
+ Query.ensure_valid_query(query_from)
184
+ Query.ensure_valid_query(query_to)
185
+
186
+ gesture_options = options.dup
187
+ gesture_options[:duration] ||= 1
188
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
189
+
190
+ _pan_between(query_from, query_to, gesture_options)
191
+ end
192
+
193
+ # Performs a `flick` on the (first) view that matches `query`.
194
+ # @see Calabash::Gestures#flick
195
+ def flick(query, from, to, options={})
196
+ Query.ensure_valid_query(query)
197
+
198
+ ensure_valid_swipe_params(from, to)
199
+
200
+ gesture_options = options.dup
201
+ gesture_options[:duration] ||= 0.5
202
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
203
+
204
+ _flick(query, from, to, gesture_options)
205
+ end
206
+
207
+ # @see Calabash::Gestures#pinch
208
+ def pinch(direction, query, options={})
209
+ Query.ensure_valid_query(query)
210
+
211
+ unless direction == :out || direction == :in
212
+ raise ArgumentError, "Invalid direction '#{direction}'"
213
+ end
214
+
215
+ gesture_options = options.dup
216
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
217
+
218
+ _pinch(direction, query, gesture_options)
219
+ end
220
+
221
+ # Enter `text` into the currently focused view.
222
+ # @see Calabash::Text#enter_text
223
+ def enter_text(text)
224
+ abstract_method!
225
+ end
226
+
227
+ # @!visibility private
228
+ def map_route(query, method_name, *method_args)
229
+ abstract_method!
230
+ end
231
+
232
+ # @!visibility private
233
+ def backdoor(method, *arguments)
234
+ abstract_method!
235
+ end
236
+
237
+ private
238
+
239
+ # @!visibility private
240
+ def _start_app(application, options={})
241
+ abstract_method!
242
+ end
243
+
244
+ # @!visibility private
245
+ def _stop_app
246
+ abstract_method!
247
+ end
248
+
249
+ # @!visibility private
250
+ def _screenshot(path)
251
+ abstract_method!
252
+ end
253
+
254
+ # @!visibility private
255
+ def _install_app(application)
256
+ abstract_method!
257
+ end
258
+
259
+ # @!visibility private
260
+ def _ensure_app_installed(application)
261
+ abstract_method!
262
+ end
263
+
264
+ # @!visibility private
265
+ def _uninstall_app(application)
266
+ abstract_method!
267
+ end
268
+
269
+ # @!visibility private
270
+ def _clear_app_data(application)
271
+ abstract_method!
272
+ end
273
+
274
+ # @!visibility private
275
+ def parse_path_or_app_parameters(path_or_application)
276
+ if path_or_application.is_a?(String)
277
+ Calabash::Application.from_path(path_or_application)
278
+ elsif path_or_application.is_a?(Calabash::Application)
279
+ path_or_application
280
+ else
281
+ raise ArgumentError, "Expected a String or Calabash::Application, got #{path_or_application.class}"
282
+ end
283
+ end
284
+
285
+ # @!visibility private
286
+ def parse_identifier_or_app_parameters(identifier_or_application)
287
+ if identifier_or_application.is_a?(String)
288
+ identifier_or_application
289
+ elsif identifier_or_application.is_a?(Calabash::Application)
290
+ identifier_or_application.identifier
291
+ else
292
+ raise ArgumentError, "Expected a String or Calabash::Application, got #{identifier_or_application.class}"
293
+ end
294
+ end
295
+
296
+ # @!visibility private
297
+ def ensure_valid_swipe_params(from, to)
298
+ unless from.is_a?(Hash)
299
+ message = "Invalid 'from' (#{from}). Expected a hash"
300
+ raise ArgumentError, message
301
+ end
302
+
303
+ unless from.include?(:x)
304
+ message = 'No from[:x] given. Expected a number between 0 and 100'
305
+ raise ArgumentError, message
306
+ end
307
+
308
+ unless from.include?(:y)
309
+ message = 'No from[:y] given. Expected a number between 0 and 100'
310
+ raise ArgumentError, message
311
+ end
312
+
313
+ unless (0..100).include?(from[:x])
314
+ message = 'Invalid from[:x] given. Expected a number between 0 and 100'
315
+ raise ArgumentError, message
316
+ end
317
+
318
+ unless (0..100).include?(from[:y])
319
+ message = 'Invalid from[:y] given. Expected a number between 0 and 100'
320
+ raise ArgumentError, message
321
+ end
322
+
323
+ unless to.is_a?(Hash)
324
+ message = "Invalid 'to' (#{to}). Expected a hash"
325
+ raise ArgumentError, message
326
+ end
327
+
328
+ unless to.include?(:x)
329
+ message = 'No to[:x] given. Expected a number between 0 and 100'
330
+ raise ArgumentError, message
331
+ end
332
+
333
+ unless to.include?(:y)
334
+ message = 'No to[:y] given. Expected a number between 0 and 100'
335
+ raise ArgumentError, message
336
+ end
337
+
338
+ unless (0..100).include?(to[:x])
339
+ message = 'Invalid to[:x] given. Expected a number between 0 and 100'
340
+ raise ArgumentError, message
341
+ end
342
+
343
+ unless (0..100).include?(to[:y])
344
+ message = 'Invalid to[:y] given. Expected a number between 0 and 100'
345
+ raise ArgumentError, message
346
+ end
347
+ end
348
+
349
+ # @!visibility private
350
+ def _tap(query, options={})
351
+ abstract_method!
352
+ end
353
+
354
+ # @!visibility private
355
+ def _double_tap(query, options={})
356
+ abstract_method!
357
+ end
358
+
359
+ # @!visibility private
360
+ def _long_press(query, options={})
361
+ abstract_method!
362
+ end
363
+
364
+ # @!visibility private
365
+ def _pan(query, from, to, options={})
366
+ abstract_method!
367
+ end
368
+
369
+ # @!visibility private
370
+ def _pan_between(query_from, query_to, options={})
371
+ abstract_method!
372
+ end
373
+
374
+ # @!visibility private
375
+ def _flick(query, from, to, options={})
376
+ abstract_method!
377
+ end
378
+
379
+ # @!visibility private
380
+ def _pinch(direction, query, options={})
381
+ abstract_method!
382
+ end
383
+
384
+ # Do not keep a reference to this module
385
+ def world_for_device
386
+ @new_module = world_module.clone
387
+
388
+ device = self
389
+
390
+ @new_module.send(:define_singleton_method, :default_device) do
391
+ device
392
+ end
393
+
394
+ @new_module
395
+ end
396
+
397
+ def world_module
398
+ abstract_method!
399
+ end
400
+ end
401
+ end