calabash 2.0.0.pre11 → 2.0.0.prelegacy

Sign up to get free protection for your applications and to get access to all the features.
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,8 +3,15 @@ module Calabash
3
3
 
4
4
  # @!visibility private
5
5
  module Gestures
6
+
6
7
  # @!visibility private
7
- define_method (:_swipe_coordinates_for_screen) do
8
+ # Concrete implementation of pan_screen_up gesture.
9
+ def _pan_screen_up(options={})
10
+
11
+ gesture_options = options.dup
12
+ gesture_options[:duration] ||= 0.5
13
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
14
+
8
15
  points_from_top = gesture_points_from_top
9
16
  points_from_bottom = gesture_points_from_bottom
10
17
 
@@ -17,49 +24,108 @@ module Calabash
17
24
  end_y = points_from_top
18
25
  x = width/2.0
19
26
 
20
- {bottom: coordinate(x, start_y), top: coordinate(x, end_y)}
21
- end
27
+ from_offset = coordinate(x, start_y)
28
+ to_offset = coordinate(x, end_y)
22
29
 
23
- # @!visibility private
24
- # Concrete implementation of pan_screen_up gesture.
25
- define_method (:_pan_screen_up) do |options={}|
26
- swipe = _swipe_coordinates_for_screen
27
- gesture_options = options.merge({offset: {from: swipe[:bottom], to: swipe[:top]}})
28
-
29
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.pan_between(nil, nil, gesture_options)}
30
+ Device.default.pan_screen(top_view, from_offset, to_offset, gesture_options)
30
31
  end
31
32
 
32
33
  # @!visibility private
33
34
  # Concrete implementation of pan_screen_down gesture.
34
- define_method (:_pan_screen_down) do |options={}|
35
- swipe = _swipe_coordinates_for_screen
36
- gesture_options = options.merge({offset: {from: swipe[:top], to: swipe[:bottom]}})
35
+ def _pan_screen_down(options={})
36
+
37
+ gesture_options = options.dup
38
+ gesture_options[:duration] ||= 0.5
39
+ gesture_options[:timeout] ||= Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT
40
+
41
+ points_from_top = gesture_points_from_top
42
+ points_from_bottom = gesture_points_from_bottom
43
+
44
+ top_view = query('*').first
45
+
46
+ height = top_view['frame']['height'].to_f
47
+ width = top_view['frame']['width'].to_f
48
+
49
+ start_y = points_from_top
50
+ end_y = height - points_from_bottom
51
+ x = width/2.0
52
+
53
+ from_offset = coordinate(x, start_y)
54
+ to_offset = coordinate(x, end_y)
37
55
 
38
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.pan_between(nil, nil, gesture_options)}
56
+ Device.default.pan_screen(top_view, from_offset, to_offset, gesture_options)
39
57
  end
40
58
 
41
59
  # @!visibility private
42
60
  # Concrete implementation of flick_screen_up gesture.
43
- define_method (:_flick_screen_up) do |options={}|
44
- swipe = _swipe_coordinates_for_screen
45
- gesture_options = options.merge({offset: {from: swipe[:bottom], to: swipe[:top]}})
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
46
71
 
47
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.flick_between(nil, nil, gesture_options)}
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)
48
83
  end
49
84
 
50
85
  # @!visibility private
51
86
  # Concrete implementation of flick_screen_down gesture.
52
- define_method (:_flick_screen_down) do |options={}|
53
- swipe = _swipe_coordinates_for_screen
54
- gesture_options = options.merge({offset: {from: swipe[:top], to: swipe[:bottom]}})
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)
55
107
 
56
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.flick_between(nil, nil, gesture_options)}
108
+ Device.default.flick_screen(top_view, from_offset, to_offset, gesture_options)
57
109
  end
58
110
 
59
111
  # @!visibility private
60
112
  # Concrete implementation of pinch_screen
61
- define_method (:_pinch_screen) do |direction, options={}|
62
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.pinch(direction, '*', options)}
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)
63
129
  end
64
130
 
65
131
  private
@@ -13,7 +13,7 @@ module Calabash
13
13
  # in the background
14
14
  # @raise [ArgumentError] If number of seconds is less than 1 and more
15
15
  # than 60 seconds.
16
- define_method(:_send_current_app_to_background) do |seconds|
16
+ def _send_current_app_to_background(seconds)
17
17
  unless (1..60).member?(seconds)
18
18
  raise ArgumentError,
19
19
  "Number of seconds: '#{seconds}' must be between 1 and 60"
@@ -30,6 +30,11 @@ module Calabash
30
30
  )
31
31
  uia(javascript)
32
32
  end
33
+
34
+ # @!visibility private
35
+ def _evaluate_javascript_in(query, javascript)
36
+ query(query, calabashStringByEvaluatingJavaScript: javascript)
37
+ end
33
38
  end
34
39
  end
35
40
  end
@@ -37,17 +37,10 @@ rescue LoadError => e
37
37
  end
38
38
 
39
39
  begin
40
- require 'calabash/ios'
41
-
42
- IRB.conf[:PROMPT][:CALABASH] = {
43
- :PROMPT_I => "calabash #{Calabash::VERSION}> ",
44
- :PROMPT_S => "%03n> ",
45
- :PROMPT_C => "%03n> ",
46
- :RETURN => "%s\n"
47
- }
48
40
 
49
- IRB.conf[:PROMPT_MODE] = :CALABASH
41
+ require 'calabash/ios'
50
42
 
43
+ extend Calabash::IOS
51
44
  extend Calabash::ConsoleHelpers
52
45
 
53
46
  Calabash::IOS.setup_defaults!
@@ -13,7 +13,7 @@ module Calabash
13
13
  # @return [String] Returns the device orientation as one of
14
14
  # `{'down' | 'up' | 'left' | 'right'}`.
15
15
  def status_bar_orientation
16
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.status_bar_orientation}
16
+ Device.default.status_bar_orientation
17
17
  end
18
18
 
19
19
  # Rotate the device left - clockwise relative to the home button.
@@ -26,7 +26,7 @@ module Calabash
26
26
  # @return [String] The position of the home button relative to the status
27
27
  # bar after the rotation. Can be one of 'down', 'left', 'right', 'up'.
28
28
  def rotate_device_left
29
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.rotate(:left)}
29
+ Device.default.rotate(:left)
30
30
  status_bar_orientation
31
31
  end
32
32
 
@@ -40,7 +40,7 @@ module Calabash
40
40
  # @return [String] The position of the home button relative to the status
41
41
  # bar after the rotation. Can be one of 'down', 'left', 'right', 'up'.
42
42
  def rotate_device_right
43
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.rotate(:right)}
43
+ Device.default.rotate(:right)
44
44
  status_bar_orientation
45
45
  end
46
46
 
@@ -83,11 +83,11 @@ module Calabash
83
83
  canonical_position = :down if position.to_sym == :bottom
84
84
  canonical_position = :up if position.to_sym == :top
85
85
 
86
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.rotate_home_button_to(canonical_position)}
86
+ Calabash::Device.default.rotate_home_button_to(canonical_position)
87
87
  end
88
88
 
89
89
  # @!visibility private
90
- define_method(:_set_orientation_landscape) do
90
+ def _set_orientation_landscape
91
91
  orientation = status_bar_orientation
92
92
  return orientation if landscape?
93
93
 
@@ -95,7 +95,7 @@ module Calabash
95
95
  end
96
96
 
97
97
  # @!visibility private
98
- define_method(:_set_orientation_portrait) do
98
+ def _set_orientation_portrait
99
99
  orientation = status_bar_orientation
100
100
  return orientation if portrait?
101
101
 
@@ -103,13 +103,13 @@ module Calabash
103
103
  end
104
104
 
105
105
  # @!visibility private
106
- define_method(:_portrait?) do
106
+ def _portrait?
107
107
  orientation = status_bar_orientation
108
108
  orientation.eql?('up') || orientation.eql?('down')
109
109
  end
110
110
 
111
111
  # @!visibility private
112
- define_method(:_landscape?) do
112
+ def _landscape?
113
113
  orientation = status_bar_orientation
114
114
  orientation.eql?('right') || orientation.eql?('left')
115
115
  end
@@ -11,27 +11,27 @@ module Calabash
11
11
 
12
12
  # Is the device under test a simulator?
13
13
  def simulator?
14
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.simulator?}
14
+ Calabash::IOS::Device.default.simulator?
15
15
  end
16
16
 
17
17
  # Is the device under test a physical device?
18
18
  def physical_device?
19
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.physical_device?}
19
+ Calabash::IOS::Device.default.physical_device?
20
20
  end
21
21
 
22
22
  # Is the device under test an iPad?
23
23
  def ipad?
24
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.device_family == 'iPad'}
24
+ Calabash::IOS::Device.default.device_family == 'iPad'
25
25
  end
26
26
 
27
27
  # Is the device under test an iPhone?
28
28
  def iphone?
29
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.device_family == 'iPhone'}
29
+ Calabash::IOS::Device.default.device_family == 'iPhone'
30
30
  end
31
31
 
32
32
  # Is the device under test an iPod?
33
33
  def ipod?
34
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.device_family == 'iPod'}
34
+ Calabash::IOS::Device.default.device_family == 'iPod'
35
35
  end
36
36
 
37
37
  # Is the device under test an iPhone or iPod?
@@ -44,22 +44,22 @@ module Calabash
44
44
  # An iPhone only app running on an iPad will be displayed in an emulated
45
45
  # mode. Starting in iOS 7, such apps will always be launched in 2x mode.
46
46
  def iphone_app_emulated_on_ipad?
47
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.iphone_app_emulated_on_ipad?}
47
+ Calabash::IOS::Device.default.iphone_app_emulated_on_ipad?
48
48
  end
49
49
 
50
50
  # Is the device under test have a 4 inch screen?
51
51
  def iphone_4in?
52
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.form_factor == 'iphone 4in'}
52
+ Calabash::IOS::Device.default.form_factor == 'iphone 4in'
53
53
  end
54
54
 
55
55
  # Is the device under test an iPhone 6.
56
56
  def iphone_6?
57
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.form_factor == 'iphone 6'}
57
+ Calabash::IOS::Device.default.form_factor == 'iphone 6'
58
58
  end
59
59
 
60
60
  # Is the device under test an iPhone 6+?
61
61
  def iphone_6_plus?
62
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.form_factor == 'iphone 6 +'}
62
+ Calabash::IOS::Device.default.form_factor == 'iphone 6 +'
63
63
  end
64
64
 
65
65
  # Is the device under test an iPhone 3.5in?
@@ -72,7 +72,7 @@ module Calabash
72
72
  # @see #iphone_app_emulated_on_ipad?
73
73
  # @see #ipad?
74
74
  def iphone_35in?
75
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.form_factor == 'iphone 3.5in'}
75
+ Calabash::IOS::Device.default.form_factor == 'iphone 3.5in'
76
76
  end
77
77
 
78
78
  # The screen dimensions and details about scale and sample rates.
@@ -88,7 +88,7 @@ module Calabash
88
88
  #
89
89
  # @return [Hash] See the example.
90
90
  def app_screen_details
91
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.screen_dimensions}
91
+ Calabash::IOS::Device.default.screen_dimensions
92
92
  end
93
93
 
94
94
  # The version of iOS running on the test device.
@@ -100,7 +100,7 @@ module Calabash
100
100
  #
101
101
  # @return [RunLoop::Version] A version object.
102
102
  def ios_version
103
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.ios_version}
103
+ Calabash::IOS::Device.default.ios_version
104
104
  end
105
105
 
106
106
  # Is the device under test running iOS 6?
@@ -132,7 +132,7 @@ module Calabash
132
132
  #
133
133
  # @return [RunLoop::Version] A version object.
134
134
  def server_version
135
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.server_version}
135
+ Calabash::IOS::Device.default.server_version
136
136
  end
137
137
 
138
138
  # Details about the version of the app under test.
@@ -161,7 +161,7 @@ module Calabash
161
161
  # the methods in the {Calabash::IOS::Runtime} module instead.
162
162
  # @return[Hash] Key/value pairs that describe the runtime environment.
163
163
  def runtime_details
164
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.runtime_details}
164
+ Calabash::IOS::Device.default.runtime_details
165
165
  end
166
166
  end
167
167
  end
@@ -71,7 +71,7 @@ module Calabash
71
71
  raise RuntimeError, e
72
72
  end
73
73
 
74
- results = Calabash::Internal.with_default_device(required_os: :ios) {|device| device.map_route(query, :scroll, direction)}
74
+ results = Device.default.map_route(query, :scroll, direction)
75
75
 
76
76
  if results.first.nil?
77
77
  fail("Expected '#{query}' to match a UIScrollView or a subclass")
@@ -153,10 +153,8 @@ module Calabash
153
153
  position = merged_options[:scroll_position].to_sym
154
154
  animate = merged_options[:animate]
155
155
 
156
- results = Calabash::Internal.with_default_device(required_os: :ios) do |device|
157
- device.map_route(query, :scrollToRow, row.to_i,
158
- section.to_i, position, animate)
159
- end
156
+ results = Device.default.map_route(query, :scrollToRow, row.to_i,
157
+ section.to_i, position, animate)
160
158
 
161
159
  if results.first.nil?
162
160
  message = [
@@ -242,10 +240,8 @@ module Calabash
242
240
  position = merged_options[:scroll_position].to_sym
243
241
  animate = merged_options[:animate]
244
242
 
245
- results = Calabash::Internal.with_default_device(required_os: :ios) do |device|
246
- device.map_route(query, :scrollToRowWithMark, mark,
247
- position, animate)
248
- end
243
+ results = Device.default.map_route(query, :scrollToRowWithMark, mark,
244
+ position, animate)
249
245
 
250
246
  if results.first.nil?
251
247
  message = [
@@ -338,12 +334,9 @@ module Calabash
338
334
  position = merged_options[:scroll_position].to_sym
339
335
  animate = merged_options[:animate]
340
336
 
341
- results = Calabash::Internal.with_default_device(required_os: :ios) do |device|
342
- device.map_route(query, :collectionViewScroll,
343
- item.to_i, section.to_i,
344
- position, animate)
345
- end
346
-
337
+ results = Device.default.map_route(query, :collectionViewScroll,
338
+ item.to_i, section.to_i,
339
+ position, animate)
347
340
  if results.first.nil?
348
341
  message = [
349
342
  "Could not scroll collection to item '#{item}' and section '#{section}'.",
@@ -434,11 +427,9 @@ module Calabash
434
427
  position = merged_options[:scroll_position].to_sym
435
428
  animate = merged_options[:animate]
436
429
 
437
- results = Calabash::Internal.with_default_device(required_os: :ios) do |device|
438
- device.map_route(query,
439
- :collectionViewScrollToItemWithMark,
440
- mark, position, animate)
441
- end
430
+ results = Device.default.map_route(query,
431
+ :collectionViewScrollToItemWithMark,
432
+ mark, position, animate)
442
433
 
443
434
  if results.first.nil?
444
435
  message = [
@@ -464,7 +455,8 @@ module Calabash
464
455
  :left, :center_horizontal, :right]
465
456
 
466
457
  # @!visibility private
467
- define_method(:_wait_for_exactly_one_scroll_view) do |query|
458
+ def _wait_for_exactly_one_scroll_view(query)
459
+
468
460
  results = []
469
461
 
470
462
  found_none = "Expected '#{query}' to match exactly one view, but found no matches."
@@ -485,7 +477,7 @@ module Calabash
485
477
  end
486
478
 
487
479
  # @!visibility private
488
- define_method(:_expect_valid_scroll_positions) do |valid_positions, position|
480
+ def _expect_valid_scroll_positions(valid_positions, position)
489
481
  unless valid_positions.include?(position.to_sym)
490
482
  raise ArgumentError,
491
483
  "Expected '#{position}' to be one of #{valid_positions.join(', ')}"
@@ -493,7 +485,7 @@ module Calabash
493
485
  end
494
486
 
495
487
  # @!visibility private
496
- define_method(:_expect_valid_scroll_animate) do |animate|
488
+ def _expect_valid_scroll_animate(animate)
497
489
  unless [true, false].include?(animate)
498
490
  raise ArgumentError,
499
491
  "Expected '#{animate}' to be a Boolean true or false"
@@ -501,13 +493,13 @@ module Calabash
501
493
  end
502
494
 
503
495
  # @!visibility private
504
- define_method(:_expect_valid_scroll_options) do |valid_positions, options|
496
+ def _expect_valid_scroll_options(valid_positions, options)
505
497
  _expect_valid_scroll_positions(valid_positions, options[:scroll_position])
506
498
  _expect_valid_scroll_animate(options[:animate])
507
499
  end
508
500
 
509
501
  # @!visibility private
510
- define_method(:_expect_valid_scroll_mark) do |mark|
502
+ def _expect_valid_scroll_mark(mark)
511
503
  if mark.nil? || mark == ''
512
504
  raise ArgumentError,
513
505
  if mark.nil?
@@ -16,25 +16,34 @@ module Calabash
16
16
  # * Use the index language feature: "UISlider index:0"
17
17
  #
18
18
  # @example
19
- # cal_ios.slider_set_value("UISlider marked:'office slider'", 2)
20
- # cal_ios.slider_set_value("slider marked:'weather slider'", -1)
21
- # cal_ios.slider_set_value("UISlider", 11)
19
+ # slider_set_value("UISlider marked:'office slider'", 2)
20
+ # slider_set_value("slider marked:'weather slider'", -1)
21
+ # slider_set_value("UISlider", 11)
22
22
  #
23
23
  # @param [String, Hash, Calabash::Query] query A query to that indicates
24
24
  # in which slider to set the value.
25
25
  # @param [Numeric] value The value to set the slider to. value.to_s should
26
26
  # produce a String representation of a Number.
27
- # @param [Boolean] animate (default: true) Animate the change.
28
- # @param [Boolean] notify_targets (default: true) simulate a UIEvent by
27
+ #
28
+ # @param [options] options Options to control the behavior of the gesture.
29
+ # @option options [Boolean] :animate (true) Animate the change.
30
+ # @option options [Boolean] :notify_targets (true) Simulate a UIEvent by
29
31
  # calling every target/action pair defined on the UISlider matching
30
32
  # `query`.
31
33
  #
32
34
  # @raise [RuntimeError] When `query` does not match exactly one slider.
33
35
  # @raise [RuntimeError] When setting the value of the slider matched by
34
36
  # `query` is not successful.
35
- def slider_set_value(query, value, animate: true, notify_targets: true)
37
+ def slider_set_value(query, value, options={})
36
38
  Query.ensure_valid_query(query)
37
39
 
40
+ default_options = {
41
+ :animate => true,
42
+ :notify_targets => true
43
+ }
44
+
45
+ merged_options = default_options.merge(options)
46
+
38
47
  found_none = "Expected '#{query}' to match exactly one view, but found no matches."
39
48
  query_object = Query.new(query)
40
49
  wait_for(found_none) do
@@ -44,7 +53,7 @@ module Calabash
44
53
  "Expected '#{query}' to match exactly one view, but found '#{results.length}'",
45
54
  results.join("\n")
46
55
  ].join("\n")
47
- raise message
56
+ fail(message)
48
57
  else
49
58
  results.length == 1
50
59
  end
@@ -52,11 +61,9 @@ module Calabash
52
61
 
53
62
  value_str = value.to_s
54
63
 
55
- args = [animate, notify_targets]
64
+ args = [merged_options[:animate], merged_options[:notify_targets]]
56
65
 
57
- Calabash::Internal.with_default_device(required_os: :ios) do |device|
58
- device.map_route(query, :changeSlider, value_str, *args)
59
- end
66
+ Device.default.map_route(query, :changeSlider, value_str, *args)
60
67
  end
61
68
  end
62
69
  end