calabash 1.9.9.pre3 → 2.0.0.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -0
  3. data/bin/calabash +45 -36
  4. data/lib/calabash/android/build/builder.rb +1 -1
  5. data/lib/calabash/android/build/resigner.rb +19 -1
  6. data/lib/calabash/android/device.rb +13 -2
  7. data/lib/calabash/android/interactions.rb +104 -3
  8. data/lib/calabash/android/lib/TestServer.apk +0 -0
  9. data/lib/calabash/android/life_cycle.rb +5 -4
  10. data/lib/calabash/android/physical_buttons.rb +4 -1
  11. data/lib/calabash/android/scroll.rb +5 -0
  12. data/lib/calabash/android/text.rb +10 -25
  13. data/lib/calabash/android.rb +3 -0
  14. data/lib/calabash/cli/generate.rb +2 -0
  15. data/lib/calabash/console_helpers.rb +4 -2
  16. data/lib/calabash/device.rb +1 -9
  17. data/lib/calabash/environment.rb +4 -0
  18. data/lib/calabash/gestures.rb +159 -66
  19. data/lib/calabash/http/retriable_client.rb +1 -1
  20. data/lib/calabash/interactions.rb +67 -5
  21. data/lib/calabash/ios/conditions.rb +0 -1
  22. data/lib/calabash/ios/device/device_implementation.rb +17 -5
  23. data/lib/calabash/ios/device/gestures_mixin.rb +202 -48
  24. data/lib/calabash/ios/device/rotation_mixin.rb +10 -8
  25. data/lib/calabash/ios/device/routes/handle_route_mixin.rb +5 -1
  26. data/lib/calabash/ios/device/runtime_attributes.rb +4 -5
  27. data/lib/calabash/ios/gestures.rb +82 -8
  28. data/lib/calabash/ios/orientation.rb +21 -21
  29. data/lib/calabash/ios/runtime.rb +146 -2
  30. data/lib/calabash/ios/slider.rb +70 -0
  31. data/lib/calabash/ios/text.rb +6 -2
  32. data/lib/calabash/ios/uia.rb +24 -2
  33. data/lib/calabash/ios.rb +2 -0
  34. data/lib/calabash/lib/skeleton/features/support/dry_run.rb +8 -0
  35. data/lib/calabash/life_cycle.rb +59 -30
  36. data/lib/calabash/location.rb +0 -1
  37. data/lib/calabash/orientation.rb +0 -1
  38. data/lib/calabash/page.rb +38 -5
  39. data/lib/calabash/patch/array.rb +7 -7
  40. data/lib/calabash/query.rb +17 -2
  41. data/lib/calabash/query_result.rb +10 -0
  42. data/lib/calabash/screenshot.rb +28 -8
  43. data/lib/calabash/text.rb +52 -8
  44. data/lib/calabash/utility.rb +3 -3
  45. data/lib/calabash/version.rb +1 -1
  46. data/lib/calabash/wait.rb +33 -11
  47. data/lib/calabash.rb +124 -13
  48. metadata +114 -111
@@ -1,5 +1,6 @@
1
1
  module Calabash
2
2
  module IOS
3
+
3
4
  # @!visibility private
4
5
  #
5
6
  # Gestures should wait for the views involved before performing the
@@ -13,26 +14,117 @@ module Calabash
13
14
  # @todo Needs unit tests.
14
15
  module GesturesMixin
15
16
 
17
+ # @!visibility private
18
+ class UIAutomationError < StandardError; end
19
+
20
+ # @!visibility private
21
+ #
22
+ # Since iOS 7, Apple's UIAutomation API:
23
+ #
24
+ # * dragInsideWithOptions
25
+ # * flickInsideWithOptions
26
+ #
27
+ # has been broken for iOS Simulators under the following conditions:
28
+ #
29
+ # * View is UIScrollView or UIScrollView subclass
30
+ # * View is inside a UIScrollView or UIScrollView subclass
31
+ #
32
+ # @todo Check for fix on iOS 9
33
+ def check_for_broken_uia_automation(query, view, gesture_waiter)
34
+ # Only broken for simulators.
35
+ return if Device.default.physical_device?
36
+
37
+ conditions = [
38
+ # All UIScrollViews have content_offset.
39
+ lambda do
40
+ content_offset = gesture_waiter.query(query, :contentOffset).first
41
+ content_offset != '*****'
42
+ end,
43
+
44
+ # If view looks like a table view cell.
45
+ lambda do
46
+ view['class'][/TableViewCell/, 0]
47
+ end,
48
+
49
+ # Or a collection view cell.
50
+ lambda do
51
+ view['class'][/CollectionViewCell/, 0]
52
+ end,
53
+
54
+ # If view in inside a UITableViewCell.
55
+ lambda do
56
+ if query.to_s == '*'
57
+ # '*' parent UITableViewCell is too broad.
58
+ false
59
+ else
60
+ new_query = "#{query} parent UITableViewCell"
61
+ !gesture_waiter.query(new_query).empty?
62
+ end
63
+ end,
64
+
65
+ # Or inside a UICollectionViewCell
66
+ lambda do
67
+ if query.to_s == '*'
68
+ # '*' parent UICollectionViewCell is too broad.
69
+ false
70
+ else
71
+ new_query = "#{query} parent UICollectionViewCell"
72
+ !gesture_waiter.query(new_query).empty?
73
+ end
74
+ end
75
+ ]
76
+
77
+ if conditions.any? { |condition| condition.call }
78
+ message = [
79
+ '',
80
+ "Apple's public UIAutomation API `dragInsideWithOptions` is broken for iOS Simulators >= 7",
81
+ '',
82
+ 'If you are trying to swipe-to-delete on a simulator, it will only work on a device.',
83
+ '',
84
+ 'If you are trying to manipulate a table, collection or scroll view, try using the Scroll API.',
85
+ ' * scroll # Scroll in a direction.',
86
+ ' * scroll_to_row # Scroll to a row with row / section indexes.',
87
+ ' * scroll_to_row_with_mark # Scroll to table row with a mark.',
88
+ ' * scroll_to_item # Scroll to collection item with item / section indexes.',
89
+ ' * scroll_to_item_with_mark # Scroll to collection item with a mark.',
90
+ '',
91
+ 'All gestures work on physical devices.'
92
+ ].map { |msg| Color.red(msg) }.join("\n")
93
+ raise UIAutomationError, message
94
+ end
95
+ end
96
+
97
+ # @!visibility private
16
98
  def _tap(query, options={})
17
99
  view_to_touch = _gesture_waiter.wait_for_view(query, options)
18
100
 
19
- offset = uia_center_of_view(view_to_touch)
101
+ rect = view_to_touch['rect']
102
+ x = rect['x'] + (rect['width'] * (options[:at][:x] / 100.0)).to_i
103
+ y = rect['y'] + (rect['height'] * (options[:at][:y] / 100.0)).to_i
104
+
105
+ offset = coordinate(x, y)
20
106
 
21
107
  uia_serialize_and_call(:tapOffset, offset, options)
22
108
 
23
109
  Calabash::QueryResult.create([view_to_touch], query)
24
110
  end
25
111
 
112
+ # @!visibility private
26
113
  def _double_tap(query, options={})
27
114
  view_to_touch = _gesture_waiter.wait_for_view(query, options)
28
115
 
29
- offset = uia_center_of_view(view_to_touch)
116
+ rect = view_to_touch['rect']
117
+ x = rect['x'] + (rect['width'] * (options[:at][:x] / 100.0)).to_i
118
+ y = rect['y'] + (rect['height'] * (options[:at][:y] / 100.0)).to_i
119
+
120
+ offset = coordinate(x, y)
30
121
 
31
122
  uia_serialize_and_call(:doubleTapOffset, offset, options)
32
123
 
33
124
  Calabash::QueryResult.create([view_to_touch], query)
34
125
  end
35
126
 
127
+ # @!visibility private
36
128
  def _long_press(query, options={})
37
129
 
38
130
  begin
@@ -43,13 +135,18 @@ module Calabash
43
135
 
44
136
  view_to_touch = _gesture_waiter.wait_for_view(query, options)
45
137
 
46
- offset = uia_center_of_view(view_to_touch)
138
+ rect = view_to_touch['rect']
139
+ x = rect['x'] + (rect['width'] * (options[:at][:x] / 100.0)).to_i
140
+ y = rect['y'] + (rect['height'] * (options[:at][:y] / 100.0)).to_i
141
+
142
+ offset = coordinate(x, y)
47
143
 
48
144
  uia_serialize_and_call(:touchHoldOffset, options[:duration], offset)
49
145
 
50
146
  Calabash::QueryResult.create([view_to_touch], query)
51
147
  end
52
148
 
149
+ # @!visibility private
53
150
  def _pan_between(query_from, query_to, options={})
54
151
 
55
152
  begin
@@ -72,17 +169,14 @@ module Calabash
72
169
  }
73
170
  end
74
171
 
75
- # The default to and from for the pan_* methods are not good for iOS.
172
+ # @!visibility private
173
+ # @todo The default to and from for the pan_* methods are not good for iOS.
76
174
  #
77
175
  # * from: {x: 90, y: 50}
78
176
  # * to: {x: 10, y: 50}
79
177
  #
80
- # If the view has a UINavigationBar or UITabBar, the defaults will
178
+ # If the view has a UINavigationBar or UITabBar, the defaults *might*
81
179
  # cause vertical gestures to start and/or end on one of these bars.
82
- #
83
- # dragInsideWithOptions broke in iOS 7, so the condition should really be
84
- # `Device.default.simulator? && !Device.ios6?`, but I haven't checked on
85
- # iOS 9 yet, so I will leave the condition out.
86
180
  def _pan(query, from, to, options={})
87
181
 
88
182
  begin
@@ -94,66 +188,125 @@ module Calabash
94
188
  gesture_waiter = _gesture_waiter
95
189
  view_to_pan = gesture_waiter.wait_for_view(query, options)
96
190
 
97
- # * will never match a UIScrollView or subclass.
98
- if Device.default.simulator? && query.to_s != '*'
99
- should_raise = false
100
-
101
- content_offset = gesture_waiter.query(query, :contentOffset).first
102
- if content_offset != '*****'
103
- # Panning on anything with a content offset is broken.
104
- should_raise = true
105
- elsif view_to_pan['class'][/TableViewCell/, 0]
106
- should_raise = true
107
- else
108
- new_query = "#{query} parent UITableViewCell"
109
- should_raise = !gesture_waiter.query(new_query).empty?
110
- # TODO: Identify other conditions
111
- # TODO: Can we detect UITableViewCells?
112
- # The gist is that if the view is a UIScrollView or in a UIScrollView
113
- # dragInsideWithOptions does not work
114
- end
115
-
116
- if should_raise
117
- message = [
118
- '',
119
- "Apple's public UIAutomation API `dragInsideWithOptions` is broken for iOS Simulators >= 7",
120
- '',
121
- 'If you are trying to swipe-to-delete on a simulator, it will only work on a device.',
122
- '',
123
- 'If you are trying to manipulate a table, collection or scroll view, try using the Scroll API.',
124
- ' * scroll # Scroll in a direction.',
125
- ' * scroll_to_row # Scroll to a row with row / section indexes.',
126
- ' * scroll_to_row_with_mark # Scroll to table row with a mark.',
127
- ' * scroll_to_item # Scroll to collection item with item / section indexes.',
128
- ' * scroll_to_item_with_mark # Scroll to collection item with a mark.',
129
- '',
130
- 'All gestures work on physical devices.'
131
- ].map { |msg| Color.red(msg) }.join("\n")
132
- raise message
133
- end
191
+ begin
192
+ check_for_broken_uia_automation(query, view_to_pan, gesture_waiter)
193
+ rescue => e
194
+ raise "Could not pan with query: #{query}\n#{e.message}"
134
195
  end
135
196
 
136
197
  rect = view_to_pan['rect']
137
198
 
138
199
  from_x = rect['width'] * (from[:x]/100.0)
139
200
  from_y = rect['height'] * (from[:y]/100.0)
140
- from_offset = percent(from_x, from_y)
201
+ from_offset = coordinate(from_x, from_y)
141
202
 
142
203
  to_x = rect['width'] * (to[:x]/100.0)
143
204
  to_y = rect['height'] * (to[:y]/100.0)
144
- to_offset = percent(to_x, to_y)
205
+ to_offset = coordinate(to_x, to_y)
145
206
 
146
207
  uia_serialize_and_call(:panOffset, from_offset, to_offset)
147
208
 
148
209
  Calabash::QueryResult.create([view_to_pan], query)
149
210
  end
150
211
 
212
+ # @!visibility private
151
213
  def pan_screen(view_to_pan, from_offset, to_offset, options)
214
+ begin
215
+ _expect_valid_duration(options)
216
+ rescue ArgumentError => e
217
+ raise ArgumentError, e
218
+ end
219
+
152
220
  uia_serialize_and_call(:panOffset, from_offset, to_offset, options)
153
221
 
154
222
  Calabash::QueryResult.create([view_to_pan], '*')
155
223
  end
156
224
 
225
+ # @!visibility private
226
+ # @todo The default to and from for the screen_* methods are not good for iOS.
227
+ #
228
+ # * from: {x: 90, y: 50}
229
+ # * to: {x: 10, y: 50}
230
+ #
231
+ # If the view has a UINavigationBar or UITabBar, the defaults *might*
232
+ # cause vertical gestures to start and/or end on one of these bars.
233
+ def _flick(query, from, to, options)
234
+ begin
235
+ _expect_valid_duration(options)
236
+ rescue ArgumentError => e
237
+ raise ArgumentError, e
238
+ end
239
+
240
+ gesture_waiter = _gesture_waiter
241
+ view_to_flick = gesture_waiter.wait_for_view(query, options)
242
+
243
+ begin
244
+ check_for_broken_uia_automation(query, view_to_flick, gesture_waiter)
245
+ rescue => e
246
+ raise "Could not flick with query: #{query}\n#{e.message}"
247
+ end
248
+
249
+ rect = view_to_flick['rect']
250
+
251
+ from_x = rect['width'] * (from[:x]/100.0)
252
+ from_y = rect['height'] * (from[:y]/100.0)
253
+ from_offset = percent(from_x, from_y)
254
+
255
+ to_x = rect['width'] * (to[:x]/100.0)
256
+ to_y = rect['height'] * (to[:y]/100.0)
257
+ to_offset = percent(to_x, to_y)
258
+
259
+ uia_serialize_and_call(:flickOffset, from_offset, to_offset, options)
260
+
261
+ Calabash::QueryResult.create([view_to_flick], query)
262
+ end
263
+
264
+ # @!visibility private
265
+ def flick_screen(view_to_pan, from_offset, to_offset, options)
266
+ begin
267
+ _expect_valid_duration(options)
268
+ rescue ArgumentError => e
269
+ raise ArgumentError, e
270
+ end
271
+
272
+ uia_serialize_and_call(:flickOffset, from_offset, to_offset, options)
273
+
274
+ Calabash::QueryResult.create([view_to_pan], '*')
275
+ end
276
+
277
+ # @!visibility private
278
+ # @todo The pinch gestures are incredibly coarse grained.
279
+ #
280
+ # https://github.com/krukow/calabash-script/commit/fa33550ac7ac4f37da649498becef441d2284cd8
281
+ def _pinch(direction, query, options={})
282
+ begin
283
+ _expect_valid_duration(options)
284
+ rescue ArgumentError => e
285
+ raise ArgumentError, e
286
+ end
287
+
288
+ gesture_waiter = _gesture_waiter
289
+
290
+ view_to_pinch = gesture_waiter.wait_for_view(query, options)
291
+ offset = uia_center_of_view(view_to_pinch)
292
+
293
+ gesture_direction = direction == :in ? :out : :in
294
+
295
+ uia_serialize_and_call(:pinchOffset, gesture_direction, offset, options)
296
+
297
+ after = gesture_waiter.query(query)
298
+ if after.empty?
299
+ after_result = nil
300
+ else
301
+ after_result = after.first
302
+ end
303
+
304
+ {
305
+ :before => Calabash::QueryResult.create([view_to_pinch], query),
306
+ :after => Calabash::QueryResult.create([after_result], query)
307
+ }
308
+ end
309
+
157
310
  private
158
311
 
159
312
  # @!visibility private
@@ -189,6 +342,7 @@ module Calabash
189
342
  end.call(self)
190
343
  end
191
344
 
345
+ # @!visibility private
192
346
  def _expect_valid_duration(options)
193
347
  duration = options[:duration].to_f
194
348
  if duration < 0.5 || duration > 60
@@ -59,10 +59,10 @@ module Calabash
59
59
  end
60
60
 
61
61
  # @!visibility private
62
- # Caller must pass position one of these positions down, left, right, up
62
+ # Caller must pass position one of these positions :down, :left, :right, :up
63
63
  def rotate_home_button_to(position)
64
64
 
65
- valid_positions = ['down', 'left', 'right', 'up']
65
+ valid_positions = [:down, :left, :right, :up]
66
66
  unless valid_positions.include?(position)
67
67
  raise ArgumentError,
68
68
  "Expected '#{position}' to be on of #{valid_positions.join(', ')}"
@@ -76,7 +76,7 @@ module Calabash
76
76
  wait_for_server_to_start({:timeout => 1})
77
77
  end
78
78
 
79
- orientation = status_bar_orientation
79
+ orientation = status_bar_orientation.to_sym
80
80
 
81
81
  if orientation == position
82
82
  return orientation
@@ -94,16 +94,18 @@ module Calabash
94
94
  playback_route(recording_name, form_factor)
95
95
 
96
96
  # Wait for rotation animation.
97
- timeout = 1.0
98
- condition_route('NONE_ANIMATING', timeout, '*')
97
+ #
98
+ # Can't wait for animations because there might be animations other
99
+ # than rotation on the screen.
100
+ sleep(0.4)
99
101
 
100
- orientation = status_bar_orientation
102
+ orientation = status_bar_orientation.to_sym
101
103
  if orientation == position
102
- return orientation
104
+ return orientation.to_s
103
105
  end
104
106
  end
105
107
 
106
- orientation
108
+ orientation.to_s
107
109
  end
108
110
 
109
111
  private
@@ -9,7 +9,11 @@ module Calabash
9
9
 
10
10
  def route_post_request(request)
11
11
  begin
12
- http_client.post(request)
12
+ if request.params[/\"method_name\":\"flash\"/, 0]
13
+ http_client.post(request, timeout: 30)
14
+ else
15
+ http_client.post(request)
16
+ end
13
17
  rescue => e
14
18
  raise Calabash::IOS::RouteError, e
15
19
  end
@@ -8,6 +8,10 @@ module Calabash
8
8
 
9
9
  require 'run_loop'
10
10
 
11
+ # @!visibility private
12
+ # The hash passed to initialize.
13
+ attr_reader :runtime_info
14
+
11
15
  # @!visibility private
12
16
  # Creates a new instance of DeviceRuntimeInfo.
13
17
  # @param [Hash] runtime_info The result of calling the version route on
@@ -173,11 +177,6 @@ module Calabash
173
177
  runtime_info['system']
174
178
  end.call
175
179
  end
176
-
177
- # @!visibility private
178
- # The hash passed to initialize.
179
- attr_reader :runtime_info
180
-
181
180
  end
182
181
  end
183
182
  end
@@ -4,6 +4,7 @@ module Calabash
4
4
  # @!visibility private
5
5
  module Gestures
6
6
 
7
+ # @!visibility private
7
8
  # Concrete implementation of pan_screen_up gesture.
8
9
  def _pan_screen_up(options={})
9
10
 
@@ -11,8 +12,8 @@ module Calabash
11
12
  gesture_options[:duration] ||= 0.5
12
13
  gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
13
14
 
14
- points_from_top = pan_points_from_top
15
- points_from_bottom = pan_points_from_bottom
15
+ points_from_top = gesture_points_from_top
16
+ points_from_bottom = gesture_points_from_bottom
16
17
 
17
18
  top_view = query('*').first
18
19
 
@@ -29,6 +30,7 @@ module Calabash
29
30
  Device.default.pan_screen(top_view, from_offset, to_offset, gesture_options)
30
31
  end
31
32
 
33
+ # @!visibility private
32
34
  # Concrete implementation of pan_screen_down gesture.
33
35
  def _pan_screen_down(options={})
34
36
 
@@ -36,8 +38,8 @@ module Calabash
36
38
  gesture_options[:duration] ||= 0.5
37
39
  gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
38
40
 
39
- points_from_top = pan_points_from_top
40
- points_from_bottom = pan_points_from_bottom
41
+ points_from_top = gesture_points_from_top
42
+ points_from_bottom = gesture_points_from_bottom
41
43
 
42
44
  top_view = query('*').first
43
45
 
@@ -54,10 +56,82 @@ module Calabash
54
56
  Device.default.pan_screen(top_view, from_offset, to_offset, gesture_options)
55
57
  end
56
58
 
59
+ # @!visibility private
60
+ # Concrete implementation of flick_screen_up gesture.
61
+ def _flick_screen_up(options={})
62
+
63
+ gesture_options = options.dup
64
+ gesture_options[:duration] ||= 0.5
65
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
66
+
67
+ points_from_top = gesture_points_from_top
68
+ points_from_bottom = gesture_points_from_bottom
69
+
70
+ top_view = query('*').first
71
+
72
+ height = top_view['frame']['height'].to_f
73
+ width = top_view['frame']['width'].to_f
74
+
75
+ start_y = height - points_from_bottom
76
+ end_y = points_from_top
77
+ x = width/2.0
78
+
79
+ from_offset = coordinate(x, start_y)
80
+ to_offset = coordinate(x, end_y)
81
+
82
+ Device.default.flick_screen(top_view, from_offset, to_offset, gesture_options)
83
+ end
84
+
85
+ # @!visibility private
86
+ # Concrete implementation of flick_screen_down gesture.
87
+ def _flick_screen_down(options={})
88
+
89
+ gesture_options = options.dup
90
+ gesture_options[:duration] ||= 0.5
91
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
92
+
93
+ points_from_top = gesture_points_from_top
94
+ points_from_bottom = gesture_points_from_bottom
95
+
96
+ top_view = query('*').first
97
+
98
+ height = top_view['frame']['height'].to_f
99
+ width = top_view['frame']['width'].to_f
100
+
101
+ start_y = points_from_top
102
+ end_y = height - points_from_bottom
103
+ x = width/2.0
104
+
105
+ from_offset = coordinate(x, start_y)
106
+ to_offset = coordinate(x, end_y)
107
+
108
+ Device.default.flick_screen(top_view, from_offset, to_offset, gesture_options)
109
+ end
110
+
111
+ # @!visibility private
112
+ # Concrete implementation of pinch_screen
113
+ def _pinch_screen(direction, options={})
114
+ Device.default.pinch(direction, '*', options)
115
+ end
116
+
117
+ # @!visibility private
118
+ # Concrete implementation of pinch_to_zoom
119
+ def _pinch_to_zoom(direction, query, options={})
120
+ gesture_direction = direction == :in ? :out : :in
121
+ Device.default.pinch(gesture_direction, query, options)
122
+ end
123
+
124
+ # @!visibility private
125
+ # Concrete implementation of pinch_screen_to_zoom
126
+ def _pinch_screen_to_zoom(direction, options={})
127
+ gesture_direction = direction == :in ? :out : :in
128
+ Device.default.pinch(gesture_direction, '*', options)
129
+ end
130
+
57
131
  private
58
132
 
59
- # Number of points from the top to start a full-screen vertical pan.
60
- def pan_points_from_top
133
+ # Number of points from the top to start a full-screen vertical gesture.
134
+ def gesture_points_from_top
61
135
  # 20 pixels for status bar in portrait; status bar is usually missing
62
136
  # in landscape @todo route for status bar height
63
137
 
@@ -79,8 +153,8 @@ module Calabash
79
153
  points_from_top
80
154
  end
81
155
 
82
- # Number of points from the bottom to start a full-screen vertical pan.
83
- def pan_points_from_bottom
156
+ # Number of points from the bottom to start a full-screen vertical gesture.
157
+ def gesture_points_from_bottom
84
158
  # Dragging from the bottom will lift the transport controls.
85
159
  points_from_bottom = 10
86
160
 
@@ -4,7 +4,6 @@ module Calabash
4
4
  # On iOS, the presenting view controller must respond to rotation events.
5
5
  # If the presenting view controller does not respond to rotation events,
6
6
  # then no rotation will be performed.
7
- # @!visibility private
8
7
  module Orientation
9
8
 
10
9
  # Returns the home button position relative to the status bar.
@@ -17,30 +16,31 @@ module Calabash
17
16
  Device.default.status_bar_orientation
18
17
  end
19
18
 
20
- # Rotates the device in the direction indicated by `direction`.
21
- #
22
- # @example
23
- # > rotate('left')
24
- # > rotate('right')
19
+ # Rotate the device left - clockwise relative to the home button.
25
20
  #
26
21
  # @note
27
22
  # The presenting view controller must respond to rotation events.
28
23
  # If the presenting view controller does not respond to rotation events,
29
24
  # then no rotation will be performed.
30
25
  #
31
- # @param [String] direction The direction in which to rotate.
32
- # Valid arguments are :left and :right
33
- #
34
- # @raise [ArgumentError] If an invalid direction is given.
35
26
  # @return [String] The position of the home button relative to the status
36
27
  # bar after the rotation. Can be one of 'down', 'left', 'right', 'up'.
37
- def rotate(direction)
38
- unless direction == 'left' || direction == 'right'
39
- raise ArgumentError, "Expected '#{direction}' to be 'left' or 'right'"
40
- end
28
+ def rotate_device_left
29
+ Device.default.rotate(:left)
30
+ status_bar_orientation
31
+ end
41
32
 
42
- Device.default.rotate(direction.to_sym)
43
- wait_for_animations
33
+ # Rotate the device right - counterclockwise relative to the home button.
34
+ #
35
+ # @note
36
+ # The presenting view controller must respond to rotation events.
37
+ # If the presenting view controller does not respond to rotation events,
38
+ # then no rotation will be performed.
39
+ #
40
+ # @return [String] The position of the home button relative to the status
41
+ # bar after the rotation. Can be one of 'down', 'left', 'right', 'up'.
42
+ def rotate_device_right
43
+ Device.default.rotate(:right)
44
44
  status_bar_orientation
45
45
  end
46
46
 
@@ -73,15 +73,15 @@ module Calabash
73
73
  # @return [String] The position of the home button relative to the status
74
74
  # bar after the rotation. Can be one of 'down', 'left', 'right', 'up'.
75
75
  def rotate_home_button_to(position)
76
- valid_positions = ['down', 'bottom', 'top', 'up', 'left', 'right']
77
- unless valid_positions.include?(position)
76
+ valid_positions = [:down, :bottom, :top, :up, :left, :right]
77
+ unless valid_positions.include?(position.to_sym)
78
78
  raise ArgumentError,
79
79
  "Expected '#{position}' to be one of #{valid_positions.join(', ')}"
80
80
  end
81
81
 
82
- canonical_position = position
83
- canonical_position = 'down' if position == 'bottom'
84
- canonical_position = 'up' if position == 'top'
82
+ canonical_position = position.to_sym
83
+ canonical_position = :down if position.to_sym == :bottom
84
+ canonical_position = :up if position.to_sym == :top
85
85
 
86
86
  Calabash::Device.default.rotate_home_button_to(canonical_position)
87
87
  end