calabash 1.9.9.pre3 → 2.0.0.prelegacy

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -33
  3. data/bin/calabash +45 -36
  4. data/lib/calabash.rb +137 -13
  5. data/lib/calabash/android.rb +6 -0
  6. data/lib/calabash/android/adb.rb +25 -1
  7. data/lib/calabash/android/application.rb +14 -3
  8. data/lib/calabash/android/build/builder.rb +16 -3
  9. data/lib/calabash/android/build/java_keystore.rb +10 -0
  10. data/lib/calabash/android/build/resigner.rb +23 -1
  11. data/lib/calabash/android/build/test_server.rb +2 -0
  12. data/lib/calabash/android/defaults.rb +1 -0
  13. data/lib/calabash/android/device.rb +55 -3
  14. data/lib/calabash/android/environment.rb +10 -0
  15. data/lib/calabash/android/interactions.rb +106 -3
  16. data/lib/calabash/android/legacy.rb +143 -0
  17. data/lib/calabash/android/lib/TestServer.apk +0 -0
  18. data/lib/calabash/android/life_cycle.rb +6 -4
  19. data/lib/calabash/android/physical_buttons.rb +12 -1
  20. data/lib/calabash/android/screenshot.rb +1 -0
  21. data/lib/calabash/android/scroll.rb +115 -0
  22. data/lib/calabash/android/server.rb +3 -1
  23. data/lib/calabash/android/text.rb +16 -25
  24. data/lib/calabash/application.rb +29 -0
  25. data/lib/calabash/cli/build.rb +15 -1
  26. data/lib/calabash/cli/console.rb +9 -5
  27. data/lib/calabash/cli/generate.rb +5 -0
  28. data/lib/calabash/cli/helpers.rb +7 -1
  29. data/lib/calabash/cli/resign.rb +1 -0
  30. data/lib/calabash/cli/run.rb +10 -6
  31. data/lib/calabash/cli/setup_keystore.rb +2 -0
  32. data/lib/calabash/color.rb +7 -0
  33. data/lib/calabash/console_helpers.rb +4 -2
  34. data/lib/calabash/defaults.rb +1 -0
  35. data/lib/calabash/device.rb +8 -9
  36. data/lib/calabash/environment.rb +5 -0
  37. data/lib/calabash/gestures.rb +159 -66
  38. data/lib/calabash/http/retriable_client.rb +3 -1
  39. data/lib/calabash/interactions.rb +68 -5
  40. data/lib/calabash/ios.rb +4 -0
  41. data/lib/calabash/ios/application.rb +8 -1
  42. data/lib/calabash/ios/conditions.rb +3 -1
  43. data/lib/calabash/ios/date_picker.rb +412 -0
  44. data/lib/calabash/ios/defaults.rb +1 -0
  45. data/lib/calabash/ios/device.rb +1 -0
  46. data/lib/calabash/ios/device/device_implementation.rb +33 -16
  47. data/lib/calabash/ios/device/gestures_mixin.rb +202 -48
  48. data/lib/calabash/ios/device/ipad_1x_2x_mixin.rb +253 -0
  49. data/lib/calabash/ios/device/keyboard_mixin.rb +2 -0
  50. data/lib/calabash/ios/device/rotation_mixin.rb +11 -8
  51. data/lib/calabash/ios/device/routes/condition_route_mixin.rb +1 -0
  52. data/lib/calabash/ios/device/routes/handle_route_mixin.rb +5 -1
  53. data/lib/calabash/ios/device/routes/map_route_mixin.rb +1 -0
  54. data/lib/calabash/ios/device/routes/response_parser.rb +1 -0
  55. data/lib/calabash/ios/device/routes/uia_route_mixin.rb +44 -6
  56. data/lib/calabash/ios/device/runtime_attributes.rb +4 -5
  57. data/lib/calabash/ios/device/text_mixin.rb +2 -0
  58. data/lib/calabash/ios/device/uia_keyboard_mixin.rb +9 -0
  59. data/lib/calabash/ios/device/uia_mixin.rb +1 -0
  60. data/lib/calabash/ios/gestures.rb +82 -8
  61. data/lib/calabash/ios/interactions.rb +30 -1
  62. data/lib/calabash/ios/orientation.rb +21 -21
  63. data/lib/calabash/ios/runtime.rb +154 -2
  64. data/lib/calabash/ios/slider.rb +70 -0
  65. data/lib/calabash/ios/text.rb +11 -47
  66. data/lib/calabash/ios/uia.rb +24 -2
  67. data/lib/calabash/legacy.rb +7 -0
  68. data/lib/calabash/lib/skeleton/config/cucumber.yml +1 -3
  69. data/lib/calabash/lib/skeleton/features/support/dry_run.rb +8 -0
  70. data/lib/calabash/lib/skeleton/features/support/env.rb +15 -1
  71. data/lib/calabash/life_cycle.rb +78 -32
  72. data/lib/calabash/location.rb +2 -1
  73. data/lib/calabash/orientation.rb +0 -1
  74. data/lib/calabash/page.rb +51 -5
  75. data/lib/calabash/patch.rb +1 -0
  76. data/lib/calabash/patch/array.rb +7 -7
  77. data/lib/calabash/query.rb +17 -2
  78. data/lib/calabash/query_result.rb +14 -0
  79. data/lib/calabash/screenshot.rb +28 -8
  80. data/lib/calabash/text.rb +105 -8
  81. data/lib/calabash/utility.rb +6 -6
  82. data/lib/calabash/version.rb +1 -1
  83. data/lib/calabash/wait.rb +37 -11
  84. metadata +14 -7
@@ -3,6 +3,7 @@ module Calabash
3
3
  # @!visibility private
4
4
  module TextMixin
5
5
 
6
+ # @!visibility private
6
7
  def enter_text(text)
7
8
  wait_for_keyboard(Calabash::Wait.default_options[:timeout])
8
9
  existing_text = text_from_keyboard_first_responder
@@ -10,6 +11,7 @@ module Calabash
10
11
  uia_type_string(text, options)
11
12
  end
12
13
 
14
+ # @!visibility private
13
15
  def _enter_text_in(query, text)
14
16
  _tap(query)
15
17
  enter_text(text)
@@ -43,6 +43,7 @@ module Calabash
43
43
 
44
44
  private
45
45
 
46
+ # @!visibility private
46
47
  def uia_type_string_handler(string, escaped_string, existing_text, result, logger)
47
48
  UIATypeStringHandler.new(string,
48
49
  escaped_string,
@@ -73,6 +74,7 @@ module Calabash
73
74
  @logger = logger
74
75
  end
75
76
 
77
+ # @!visibility private
76
78
  def self.escape_backslashes_in_string(string)
77
79
  return string if string.index(/\\/)
78
80
 
@@ -95,10 +97,12 @@ module Calabash
95
97
  result['value']
96
98
  end
97
99
 
100
+ # @!visibility private
98
101
  def log(message)
99
102
  logger.log(Color.blue(message), :info)
100
103
  end
101
104
 
105
+ # @!visibility private
102
106
  def log_preamble
103
107
  log('When typing:')
104
108
  log(" raw string: #{string}")
@@ -106,6 +110,7 @@ module Calabash
106
110
  log("existing text: #{existing_text}")
107
111
  end
108
112
 
113
+ # @!visibility private
109
114
  def log_epilogue
110
115
  log(" result: #{result}")
111
116
  log('')
@@ -113,6 +118,7 @@ module Calabash
113
118
  log('https://github.com/calabash/calabash-ios/issues/374')
114
119
  end
115
120
 
121
+ # @!visibility private
116
122
  def handle_result
117
123
  the_status = status
118
124
  if the_status == 'error'
@@ -130,6 +136,7 @@ module Calabash
130
136
  end
131
137
  end
132
138
 
139
+ # @!visibility private
133
140
  def handle_error
134
141
  log_preamble
135
142
  if result.has_key? 'value'
@@ -161,6 +168,7 @@ module Calabash
161
168
  end
162
169
  end
163
170
 
171
+ # @!visibility private
164
172
  def handle_success_with_incident
165
173
  log_preamble
166
174
  if value.nil?
@@ -176,6 +184,7 @@ module Calabash
176
184
  false
177
185
  end
178
186
 
187
+ # @!visibility private
179
188
  def handle_unknown_status
180
189
  log_preamble
181
190
  log("receive response with an unknown value for 'status' key: '#{status}'")
@@ -4,6 +4,7 @@ module Calabash
4
4
  # @!visibility private
5
5
  module UIAMixin
6
6
 
7
+ # @!visibility private
7
8
  def evaluate_uia(script)
8
9
  uia_route(script)
9
10
  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
 
@@ -1,7 +1,36 @@
1
1
  module Calabash
2
2
  module IOS
3
- # @!visibility private
3
+
4
+ # Interactions with your app that are specific to iOS
4
5
  module Interactions
6
+
7
+ # @!visibility private
8
+ # Sends app to background. Simulates pressing the home button.
9
+ #
10
+ # @note Cannot be more than 60 seconds.
11
+ #
12
+ # @param [Numeric] seconds The number of seconds to keep the app
13
+ # in the background
14
+ # @raise [ArgumentError] If number of seconds is less than 1 and more
15
+ # than 60 seconds.
16
+ def _send_current_app_to_background(seconds)
17
+ unless (1..60).member?(seconds)
18
+ raise ArgumentError,
19
+ "Number of seconds: '#{seconds}' must be between 1 and 60"
20
+ end
21
+
22
+ javascript = %Q(
23
+ var x = target.deactivateAppForDuration(#{seconds});
24
+ var MAX_RETRY=5, retry_count = 0;
25
+ while (!x && retry_count < MAX_RETRY) {
26
+ x = target.deactivateAppForDuration(#{seconds});
27
+ retry_count += 1
28
+ };
29
+ x
30
+ )
31
+ uia(javascript)
32
+ end
33
+
5
34
  # @!visibility private
6
35
  def _evaluate_javascript_in(query, javascript)
7
36
  query(query, calabashStringByEvaluatingJavaScript: javascript)
@@ -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
@@ -1,16 +1,168 @@
1
1
  module Calabash
2
2
  module IOS
3
- # @!visibility private
3
+
4
+ # Methods that describe the runtime attributes of the device under test.
5
+ #
6
+ # @note The key/value pairs in the Hash returned by #runtime_details are
7
+ # not stable and can change at any time. Don't write tests that rely on
8
+ # specific keys or values in this Hash. Instead, use the API methods
9
+ # defined in this class.
4
10
  module Runtime
5
11
 
6
- # @todo Complete and document the Runtime API
12
+ # Is the device under test a simulator?
7
13
  def simulator?
8
14
  Calabash::IOS::Device.default.simulator?
9
15
  end
10
16
 
17
+ # Is the device under test a physical device?
11
18
  def physical_device?
12
19
  Calabash::IOS::Device.default.physical_device?
13
20
  end
21
+
22
+ # Is the device under test an iPad?
23
+ def ipad?
24
+ Calabash::IOS::Device.default.device_family == 'iPad'
25
+ end
26
+
27
+ # Is the device under test an iPhone?
28
+ def iphone?
29
+ Calabash::IOS::Device.default.device_family == 'iPhone'
30
+ end
31
+
32
+ # Is the device under test an iPod?
33
+ def ipod?
34
+ Calabash::IOS::Device.default.device_family == 'iPod'
35
+ end
36
+
37
+ # Is the device under test an iPhone or iPod?
38
+ def device_family_iphone?
39
+ iphone? or ipod?
40
+ end
41
+
42
+ # Is the app that is being tested an iPhone app emulated on an iPad?
43
+ #
44
+ # An iPhone only app running on an iPad will be displayed in an emulated
45
+ # mode. Starting in iOS 7, such apps will always be launched in 2x mode.
46
+ def iphone_app_emulated_on_ipad?
47
+ Calabash::IOS::Device.default.iphone_app_emulated_on_ipad?
48
+ end
49
+
50
+ # Is the device under test have a 4 inch screen?
51
+ def iphone_4in?
52
+ Calabash::IOS::Device.default.form_factor == 'iphone 4in'
53
+ end
54
+
55
+ # Is the device under test an iPhone 6.
56
+ def iphone_6?
57
+ Calabash::IOS::Device.default.form_factor == 'iphone 6'
58
+ end
59
+
60
+ # Is the device under test an iPhone 6+?
61
+ def iphone_6_plus?
62
+ Calabash::IOS::Device.default.form_factor == 'iphone 6 +'
63
+ end
64
+
65
+ # Is the device under test an iPhone 3.5in?
66
+ #
67
+ # @note If the app under test is an iPhone app emulated on an iPad then
68
+ # the form factor will _always_ be 'iphone 3.5.in'. If you need to
69
+ # branch on the actual device the app is running on, use the #ipad?
70
+ # method.
71
+ #
72
+ # @see #iphone_app_emulated_on_ipad?
73
+ # @see #ipad?
74
+ def iphone_35in?
75
+ Calabash::IOS::Device.default.form_factor == 'iphone 3.5in'
76
+ end
77
+
78
+ # The screen dimensions and details about scale and sample rates.
79
+ #
80
+ # @example
81
+ # > app_screen_details
82
+ # => {
83
+ # :height => 1,
84
+ # :height => 1334,
85
+ # :width => 750,
86
+ # :scale => 2
87
+ # }
88
+ #
89
+ # @return [Hash] See the example.
90
+ def app_screen_details
91
+ Calabash::IOS::Device.default.screen_dimensions
92
+ end
93
+
94
+ # The version of iOS running on the test device.
95
+ #
96
+ # @example
97
+ # > ios_version.major
98
+ # > ios_version.minor
99
+ # > ios_version.patch
100
+ #
101
+ # @return [RunLoop::Version] A version object.
102
+ def ios_version
103
+ Calabash::IOS::Device.default.ios_version
104
+ end
105
+
106
+ # Is the device under test running iOS 6?
107
+ def ios6?
108
+ ios_version.major == 6
109
+ end
110
+
111
+ # Is the device under test running iOS 7?
112
+ def ios7?
113
+ ios_version.major == 7
114
+ end
115
+
116
+ # Is the device under test running iOS 8?
117
+ def ios8?
118
+ ios_version.major == 8
119
+ end
120
+
121
+ # Is the device under test running iOS 9?
122
+ def ios9?
123
+ ios_version.major == 9
124
+ end
125
+
126
+ # The version of the Calabash iOS Server running in the app.
127
+ #
128
+ # @example
129
+ # > server_version.major
130
+ # > server_version.minor
131
+ # > server_version.patch
132
+ #
133
+ # @return [RunLoop::Version] A version object.
134
+ def server_version
135
+ Calabash::IOS::Device.default.server_version
136
+ end
137
+
138
+ # Details about the version of the app under test.
139
+ #
140
+ # Will always contain these two keys:
141
+ #
142
+ # * :bundle_version => CFBundleVersion
143
+ # * :short_version => CFBundleShortVersionString
144
+ #
145
+ # It may contain other key/value pairs.
146
+ #
147
+ # @return [Hash] Key/value pairs that describe the version of the app
148
+ # under test.
149
+ def app_version_details
150
+ hash = runtime_details
151
+ {
152
+ :bundle_version => hash['app_version'],
153
+ :short_version => hash['short_version_string']
154
+ }
155
+ end
156
+
157
+ # A hash of all the details about the runtime environment.
158
+ #
159
+ # @note The key/value pairs in this Hash are subject to change. Don't
160
+ # write tests that rely on a specific key appearing in the Hash. Use
161
+ # the methods in the {Calabash::IOS::Runtime} module instead.
162
+ # @return[Hash] Key/value pairs that describe the runtime environment.
163
+ def runtime_details
164
+ Calabash::IOS::Device.default.runtime_details
165
+ end
14
166
  end
15
167
  end
16
168
  end