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
@@ -33,9 +33,6 @@ module Calabash
33
33
  'Content-Type' => 'application/json;charset=utf-8'
34
34
  }
35
35
 
36
- # @!visibility private
37
- attr_accessor :port_forward
38
-
39
36
  # Creates a new retriable client.
40
37
  #
41
38
  # This initializer takes multiple options. If the option is not
@@ -110,7 +107,7 @@ module Calabash
110
107
  retries = options.fetch(:retries, @retries)
111
108
  timeout = options.fetch(:timeout, @timeout)
112
109
  interval = options.fetch(:interval, @interval)
113
- header = HEADER.merge(options.fetch(:header, {}))
110
+ header = options.fetch(:header, HEADER)
114
111
 
115
112
  @logger.log "Getting: #{@server.endpoint + request.route} #{options}"
116
113
 
@@ -134,20 +131,8 @@ module Calabash
134
131
  client.receive_timeout = [time_diff, client.receive_timeout].min
135
132
 
136
133
  begin
137
- if request_method == :get
138
- return client.send(request_method, @server.endpoint + request.route,
139
- request.params, header)
140
- else
141
- if request.params.is_a?(Hash)
142
- if request.params.key?(:json)
143
- return client.send(request_method, @server.endpoint + request.route,
144
- {body: request.params[:json]}.merge(header: header))
145
- end
146
- end
147
-
148
- return client.send(request_method, @server.endpoint + request.route,
149
- {body: request.params}.merge(header: header))
150
- end
134
+ return client.send(request_method, @server.endpoint + request.route,
135
+ request.params, header)
151
136
  rescue *RETRY_ON => e
152
137
  @logger.log "Http error: #{e}"
153
138
 
data/lib/calabash/http.rb CHANGED
@@ -2,7 +2,6 @@ module Calabash
2
2
  # @!visibility private
3
3
  module HTTP
4
4
  require 'calabash/http/retriable_client'
5
- require 'calabash/http/forwarding_client'
6
5
  require 'calabash/http/request'
7
6
  require 'calabash/http/error'
8
7
  end
@@ -62,7 +62,7 @@ module Calabash
62
62
  #
63
63
  # @return [Calabash::QueryResult] A result of the query
64
64
  def query(query, *args)
65
- Calabash::Internal.with_default_device {|device| device.map_route(Query.new(query), :query, *args)}
65
+ Calabash::Device.default.map_route(Query.new(query), :query, *args)
66
66
  end
67
67
 
68
68
  # Flashes any views matching `query`. Only one view is flashed at a time,
@@ -71,7 +71,39 @@ module Calabash
71
71
  # @param [String, Hash, Calabash::Query] query The query to match the
72
72
  # view(s)
73
73
  def flash(query)
74
- Calabash::Internal.with_default_device {|device| device.map_route(Query.new(query), :flash)}
74
+ Calabash::Device.default.map_route(Query.new(query), :flash)
75
+ end
76
+
77
+ # Evaluate javascript in a Web View. On iOS, an implicit return is
78
+ # inserted, on Android an explicit return is needed.
79
+ #
80
+ # @example
81
+ # # iOS
82
+ # evaluate_javascript_in("UIWebView", "2+2")
83
+ # # Android
84
+ # evaluate_javascript_in("WebView", "return 2+2")
85
+ #
86
+ # @example
87
+ # # iOS
88
+ # evaluate_javascript_in("WKWebView",
89
+ # "document.body.style.backgroundColor = 'red';")
90
+ #
91
+ # # Android
92
+ # evaluate_javascript_in("XWalkContent",
93
+ # "document.body.style.backgroundColor = 'red';")
94
+ #
95
+ # @note No error will be raised if the javascript given is invalid, or
96
+ # throws an exception.
97
+ #
98
+ # @param [String, Hash, Calabash::Query] query Query that matches the view
99
+ # @param [String] javascript The javascript to evaluate
100
+ #
101
+ # @raise ViewNotFoundError If no views are found matching `query`
102
+ def evaluate_javascript_in(query, javascript)
103
+ wait_for_view(query,
104
+ timeout: Calabash::Gestures::DEFAULT_GESTURE_WAIT_TIMEOUT)
105
+
106
+ _evaluate_javascript_in(query, javascript)
75
107
  end
76
108
 
77
109
  # Invoke a method in your application.
@@ -126,7 +158,12 @@ module Calabash
126
158
  # @return [Object] the result of performing the selector/method with the
127
159
  # arguments (serialized)
128
160
  def backdoor(name, *arguments)
129
- Calabash::Internal.with_default_device {|device| device.backdoor(name, *arguments)}
161
+ Device.default.backdoor(name, *arguments)
162
+ end
163
+
164
+ # @!visibility private
165
+ def _evaluate_javascript_in(query, javascript)
166
+ abstract_method!
130
167
  end
131
168
  end
132
169
  end
@@ -72,7 +72,7 @@ module Calabash
72
72
  # @return [nil] When the condition is satisfied.
73
73
  # @raise [Calabash::Wait::TimeoutError] When the timeout is exceeded.
74
74
  def wait_for_condition(condition, timeout, timeout_message, query='*')
75
- unless Calabash::Internal.with_default_device(required_os: :ios) {|device| device.condition_route(condition, timeout, query)}
75
+ unless Device.default.condition_route(condition, timeout, query)
76
76
  raise Calabash::Wait::TimeoutError, timeout_message
77
77
  end
78
78
  true
@@ -55,7 +55,7 @@ module Calabash
55
55
  Calabash::Device.default = device
56
56
 
57
57
  begin
58
- Calabash::Internal.with_default_device(required_os: :ios) {|device| device.ensure_test_server_ready({:timeout => 4})}
58
+ Calabash::Device.default.ensure_test_server_ready({:timeout => 4})
59
59
  rescue RuntimeError => e
60
60
  if e.to_s == 'Calabash server did not respond'
61
61
  raise RuntimeError, 'You can only attach to a running Calabash iOS App'
@@ -65,7 +65,7 @@ module Calabash
65
65
  end
66
66
 
67
67
  run_loop_device = device.send(:run_loop_device)
68
- result = Calabash::Internal.with_default_device(required_os: :ios) {|device| device.send(:attach_to_run_loop, run_loop_device, uia_strategy)}
68
+ result = Calabash::Device.default.send(:attach_to_run_loop, run_loop_device, uia_strategy)
69
69
  result[:application] = Calabash::Application.default
70
70
  result
71
71
  end
@@ -378,16 +378,14 @@ module Calabash
378
378
  objc_format = date_picker_objc_date_format
379
379
  target_date_string = date_time.strftime(ruby_format).squeeze(' ').strip
380
380
 
381
- Calabash::Internal.with_default_device(required_os: :ios) do |device|
382
- device.map_route(query,
383
- :changeDatePickerDate,
384
- target_date_string,
385
- objc_format,
386
- # notify targets
387
- true,
388
- # animate
389
- true)
390
- end
381
+ Device.default.map_route(query,
382
+ :changeDatePickerDate,
383
+ target_date_string,
384
+ objc_format,
385
+ # notify targets
386
+ true,
387
+ # animate
388
+ true)
391
389
  end
392
390
 
393
391
  private
@@ -17,11 +17,13 @@ module Calabash
17
17
  include Calabash::IOS::RotationMixin
18
18
  include Calabash::IOS::KeyboardMixin
19
19
  include Calabash::IOS::UIAKeyboardMixin
20
+ include Calabash::IOS::TextMixin
20
21
  include Calabash::IOS::UIAMixin
21
22
  include Calabash::IOS::IPadMixin
22
23
  include Calabash::IOS::GesturesMixin
23
24
 
24
25
  attr_reader :run_loop
26
+ attr_reader :uia_strategy
25
27
  attr_reader :start_options
26
28
 
27
29
  # Returns the default simulator identifier. The string that is return
@@ -48,7 +50,7 @@ module Calabash
48
50
  if run_loop_device.nil?
49
51
  raise "Could not find a simulator with a UDID or name matching '#{identifier}'"
50
52
  end
51
- run_loop_device.instruments_identifier(RunLoop::SimControl.new.xcode)
53
+ run_loop_device.instruments_identifier
52
54
  end
53
55
  end
54
56
 
@@ -82,14 +84,14 @@ module Calabash
82
84
  elsif connected_devices.count > 1
83
85
  raise 'There is more than one physical devices connected. Use CAL_DEVICE_ID to indicate which you want to connect to.'
84
86
  else
85
- connected_devices.first.instruments_identifier(RunLoop::SimControl.new.xcode)
87
+ connected_devices.first.instruments_identifier
86
88
  end
87
89
  else
88
90
  run_loop_device = Device.fetch_matching_physical_device(identifier)
89
91
  if run_loop_device.nil?
90
92
  raise "Could not find a physical device with a UDID or name matching '#{identifier}'"
91
93
  end
92
- run_loop_device.instruments_identifier(RunLoop::SimControl.new.xcode)
94
+ run_loop_device.instruments_identifier
93
95
  end
94
96
  end
95
97
 
@@ -343,7 +345,8 @@ module Calabash
343
345
 
344
346
  {
345
347
  :device => self,
346
- :application => application
348
+ :application => application,
349
+ :uia_strategy => uia_strategy
347
350
  }
348
351
  end
349
352
 
@@ -391,7 +394,7 @@ module Calabash
391
394
  def start_app_with_device_and_options(application, run_loop_device, user_defined_options)
392
395
  start_options = merge_start_options!(application, run_loop_device, user_defined_options)
393
396
  @run_loop = RunLoop.run(start_options)
394
- @automator = Calabash::IOS::Automator::DeviceAgent.new(@run_loop)
397
+ @uia_strategy = @run_loop[:uia_strategy]
395
398
  end
396
399
 
397
400
  # @!visibility private
@@ -525,6 +528,12 @@ module Calabash
525
528
  end
526
529
  end
527
530
 
531
+ # @!visibility private
532
+ def enter_text(text)
533
+ # @todo implement this
534
+ raise 'ni'
535
+ end
536
+
528
537
  # @!visibility private
529
538
  def clear_app_data_on_simulator(application, run_loop_device, bridge)
530
539
  begin
@@ -621,8 +630,9 @@ module Calabash
621
630
  # @!visibility private
622
631
  # Expensive!
623
632
  def Device.fetch_matching_simulator(udid_or_name)
624
- RunLoop::SimControl.new.simulators.detect do |sim|
625
- sim.instruments_identifier(RunLoop::SimControl.new.xcode) == udid_or_name ||
633
+ sim_control = RunLoop::SimControl.new
634
+ sim_control.simulators.detect do |sim|
635
+ sim.instruments_identifier == udid_or_name ||
626
636
  sim.udid == udid_or_name
627
637
  end
628
638
  end
@@ -652,7 +662,7 @@ module Calabash
652
662
  Logger.error('which resolves to a physical device.')
653
663
  Logger.error("The server endpoint '#{server.endpoint}' is for an iOS Simulator.")
654
664
  Logger.error('Use CAL_ENDPOINT to specify the IP address of your device')
655
- Logger.error("Ex. $ CAL_ENDPOINT=http://10.0.1.2:37265 CAL_DEVICE_ID=#{identifier} #{Calabash::Utility.bundle_exec_prepend}calabash ...")
665
+ Logger.error("Ex. $ CAL_ENDPOINT=http://10.0.1.2:37265 CAL_DEVICE_ID=#{identifier} be calabash ...")
656
666
  raise "Invalid device endpoint '#{server.endpoint}'"
657
667
  end
658
668
  end
@@ -693,7 +703,7 @@ module Calabash
693
703
  {
694
704
  :app => application.path,
695
705
  :bundle_id => application.identifier,
696
- :device_target => run_loop_device.instruments_identifier(RunLoop::SimControl.new.xcode),
706
+ :device_target => run_loop_device.instruments_identifier,
697
707
  :uia_strategy => strategy
698
708
  }
699
709
  @start_options = default_options.merge(options_from_user)
@@ -765,11 +775,13 @@ module Calabash
765
775
 
766
776
  if strategy == :host
767
777
  @run_loop = RunLoop::HostCache.default.read
778
+ @uia_strategy = :host
768
779
  else
769
780
  pid = instruments_pid
770
781
  @run_loop = {}
771
782
  @run_loop[:uia_strategy] = strategy
772
783
  @run_loop[:pid] = pid
784
+ @uia_strategy = strategy
773
785
  end
774
786
 
775
787
  # populate the @runtime_attributes
@@ -96,33 +96,36 @@ module Calabash
96
96
 
97
97
  # @!visibility private
98
98
  def _tap(query, options={})
99
- view_to_touch = _gesture_waiter.wait_for_view(query, timeout: options[:timeout])
99
+ view_to_touch = _gesture_waiter.wait_for_view(query, options)
100
100
 
101
101
  rect = view_to_touch['rect']
102
102
  x = rect['x'] + (rect['width'] * (options[:at][:x] / 100.0)).to_i
103
103
  y = rect['y'] + (rect['height'] * (options[:at][:y] / 100.0)).to_i
104
104
 
105
- @automator.touch({coordinates: coordinate(x, y)})
105
+ offset = coordinate(x, y)
106
+
107
+ uia_serialize_and_call(:tapOffset, offset, options)
106
108
 
107
109
  Calabash::QueryResult.create([view_to_touch], query)
108
110
  end
109
111
 
110
112
  # @!visibility private
111
113
  def _double_tap(query, options={})
112
- view_to_touch = _gesture_waiter.wait_for_view(query, timeout: options[:timeout])
114
+ view_to_touch = _gesture_waiter.wait_for_view(query, options)
113
115
 
114
116
  rect = view_to_touch['rect']
115
117
  x = rect['x'] + (rect['width'] * (options[:at][:x] / 100.0)).to_i
116
118
  y = rect['y'] + (rect['height'] * (options[:at][:y] / 100.0)).to_i
117
119
 
118
- @automator.double_tap({coordinates: coordinate(x, y)})
120
+ offset = coordinate(x, y)
121
+
122
+ uia_serialize_and_call(:doubleTapOffset, offset, options)
119
123
 
120
124
  Calabash::QueryResult.create([view_to_touch], query)
121
125
  end
122
126
 
123
127
  # @!visibility private
124
128
  def _long_press(query, options={})
125
- options[:duration] += 0.2
126
129
 
127
130
  begin
128
131
  _expect_valid_duration(options)
@@ -130,66 +133,39 @@ module Calabash
130
133
  raise ArgumentError e
131
134
  end
132
135
 
133
- view_to_touch = _gesture_waiter.wait_for_view(query, timeout: options[:timeout])
136
+ view_to_touch = _gesture_waiter.wait_for_view(query, options)
134
137
 
135
138
  rect = view_to_touch['rect']
136
139
  x = rect['x'] + (rect['width'] * (options[:at][:x] / 100.0)).to_i
137
140
  y = rect['y'] + (rect['height'] * (options[:at][:y] / 100.0)).to_i
138
141
 
139
- @automator.touch_hold({coordinates: coordinate(x, y), duration: options[:duration]})
142
+ offset = coordinate(x, y)
143
+
144
+ uia_serialize_and_call(:touchHoldOffset, options[:duration], offset)
140
145
 
141
146
  Calabash::QueryResult.create([view_to_touch], query)
142
147
  end
143
148
 
144
149
  # @!visibility private
145
150
  def _pan_between(query_from, query_to, options={})
146
- from_query_result = nil
147
- to_query_result = nil
148
- from = coordinate(0, 0)
149
- to = coordinate(0, 0)
150
-
151
- unless query_from.nil?
152
- from_view = _gesture_waiter.wait_for_view(query_from, timeout: options[:timeout])
153
- from = coordinate(from_view['rect']['center_x'], from_view['rect']['center_y'])
154
- from_query_result = Calabash::QueryResult.create([from_view], query_from)
155
- end
156
151
 
157
- unless query_to.nil?
158
- to_view = _gesture_waiter.wait_for_view(query_to, timeout: options[:timeout])
159
- to = coordinate(to_view['rect']['center_x'], to_view['rect']['center_y'])
160
- Calabash::QueryResult.create([to_view], query_to)
152
+ begin
153
+ _expect_valid_duration(options)
154
+ rescue ArgumentError => e
155
+ raise ArgumentError e
161
156
  end
162
157
 
163
- offset = options[:offset]
164
-
165
- if offset
166
- from_offset = offset[:from]
167
-
168
- if from_offset
169
- x, y = from_offset[:x], from_offset[:y]
158
+ from_view = _gesture_waiter.wait_for_view(query_from, options)
159
+ to_view = _gesture_waiter.wait_for_view(query_to, options)
170
160
 
171
- from[:x] += x || 0
172
- from[:y] += y || 0
173
- end
174
-
175
- to_offset = offset[:to]
176
-
177
- if from_offset
178
- x, y = to_offset[:x], to_offset[:y]
179
-
180
- to[:x] += x || 0
181
- to[:y] += y || 0
182
- end
183
- end
161
+ from_offset = uia_center_of_view(from_view)
162
+ to_offset = uia_center_of_view(to_view)
184
163
 
185
- @automator.pan({coordinates:
186
- {from: from,
187
- to: to},
188
- duration: options[:duration]})
164
+ uia_serialize_and_call(:panOffset, from_offset, to_offset, options)
189
165
 
190
166
  {
191
- :from => from_query_result,
192
- :to => to_query_result
167
+ :from => Calabash::QueryResult.create([from_view], query_from),
168
+ :to => Calabash::QueryResult.create([to_view], query_to)
193
169
  }
194
170
  end
195
171
 
@@ -202,24 +178,50 @@ module Calabash
202
178
  # If the view has a UINavigationBar or UITabBar, the defaults *might*
203
179
  # cause vertical gestures to start and/or end on one of these bars.
204
180
  def _pan(query, from, to, options={})
181
+
182
+ begin
183
+ _expect_valid_duration(options)
184
+ rescue ArgumentError => e
185
+ raise ArgumentError, e
186
+ end
187
+
205
188
  gesture_waiter = _gesture_waiter
206
- view_to_pan = gesture_waiter.wait_for_view(query, timeout: options[:timeout])
189
+ view_to_pan = gesture_waiter.wait_for_view(query, options)
190
+
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}"
195
+ end
207
196
 
208
197
  rect = view_to_pan['rect']
209
198
 
210
199
  from_x = rect['width'] * (from[:x]/100.0)
211
200
  from_y = rect['height'] * (from[:y]/100.0)
201
+ from_offset = coordinate(from_x, from_y)
212
202
 
213
203
  to_x = rect['width'] * (to[:x]/100.0)
214
204
  to_y = rect['height'] * (to[:y]/100.0)
205
+ to_offset = coordinate(to_x, to_y)
215
206
 
216
- @automator.pan({coordinates: {from: coordinate(from_x, from_y), to: coordinate(to_x, to_y)},
217
- duration: options[:duration]})
218
-
207
+ uia_serialize_and_call(:panOffset, from_offset, to_offset)
219
208
 
220
209
  Calabash::QueryResult.create([view_to_pan], query)
221
210
  end
222
211
 
212
+ # @!visibility private
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
+
220
+ uia_serialize_and_call(:panOffset, from_offset, to_offset, options)
221
+
222
+ Calabash::QueryResult.create([view_to_pan], '*')
223
+ end
224
+
223
225
  # @!visibility private
224
226
  # @todo The default to and from for the screen_* methods are not good for iOS.
225
227
  #
@@ -236,7 +238,7 @@ module Calabash
236
238
  end
237
239
 
238
240
  gesture_waiter = _gesture_waiter
239
- view_to_flick = gesture_waiter.wait_for_view(query, timeout: options[:timeout])
241
+ view_to_flick = gesture_waiter.wait_for_view(query, options)
240
242
 
241
243
  begin
242
244
  check_for_broken_uia_automation(query, view_to_flick, gesture_waiter)
@@ -285,7 +287,7 @@ module Calabash
285
287
 
286
288
  gesture_waiter = _gesture_waiter
287
289
 
288
- view_to_pinch = gesture_waiter.wait_for_view(query, timeout: options[:timeout])
290
+ view_to_pinch = gesture_waiter.wait_for_view(query, options)
289
291
  offset = uia_center_of_view(view_to_pinch)
290
292
 
291
293
  gesture_direction = direction == :in ? :out : :in
@@ -3,12 +3,6 @@ module Calabash
3
3
 
4
4
  # @!visibility private
5
5
  module KeyboardMixin
6
- # Enter `text` into the currently focused view.
7
- # @see Calabash::Text#enter_text
8
- # @!visibility private
9
- def enter_text(text, options={})
10
- @automator.enter_text_with_keyboard(text, options)
11
- end
12
6
 
13
7
  # Returns true if a docked keyboard is visible.
14
8
  #
@@ -67,21 +61,6 @@ module Calabash
67
61
  docked_keyboard_visible? || undocked_keyboard_visible? || split_keyboard_visible?
68
62
  end
69
63
 
70
- def tap_keyboard_delete_key(options={})
71
- @automator.tap_keyboard_delete_key
72
- end
73
-
74
- def tap_keyboard_action_key
75
- results = keyboard_waiter.query("* isFirstResponder:1", :returnKeyType)
76
-
77
- if results.empty?
78
- RunLoop.log_debug("Cannot find keyboard first responder to ask for its returnKeyType")
79
- raise 'Cannot tap_keyboard_action_key. No view has focus'
80
- end
81
-
82
- @automator.tap_keyboard_action_key(results.first)
83
- end
84
-
85
64
  # Returns the the text in the first responder.
86
65
  #
87
66
  # The first responder will be the UITextField or UITextView instance
@@ -14,14 +14,55 @@ module Calabash
14
14
  wait_for_server_to_start({:timeout => 1})
15
15
  end
16
16
 
17
- orientation = status_bar_orientation.to_sym
17
+ family = device_family
18
+
19
+ current_orientation = status_bar_orientation.to_sym
20
+ recording_name = nil
21
+ case direction
22
+ when :left
23
+ if current_orientation == :down
24
+ recording_name = 'left_home_down'
25
+ elsif current_orientation == :right
26
+ recording_name = 'left_home_right'
27
+ elsif current_orientation == :left
28
+ recording_name = 'left_home_left'
29
+ elsif current_orientation == :up
30
+ recording_name = 'left_home_up'
31
+ end
32
+ when :right
33
+ if current_orientation == :down
34
+ recording_name = 'right_home_down'
35
+ elsif current_orientation == :left
36
+ recording_name = 'right_home_left'
37
+ elsif current_orientation == :right
38
+ recording_name = 'right_home_right'
39
+ elsif current_orientation == :up
40
+ recording_name = 'right_home_up'
41
+ end
42
+ else
43
+ # Caller should have guarded us against this case.
44
+ raise ArgumentError, "Expected '#{direction}' to be :left or :right"
45
+ end
46
+
47
+ if family == 'iPad'
48
+ form_factor = 'ipad'
49
+ else
50
+ form_factor = 'iphone'
51
+ end
52
+
53
+ if recording_name.nil?
54
+ raise "Could not rotate device in direction '#{direction}' " \
55
+ "with orientation '#{current_orientation}'"
56
+ end
18
57
 
19
- @automator.rotate(direction, orientation)
58
+ recording_name = "rotate_#{recording_name}"
59
+ playback_route(recording_name, form_factor)
20
60
  end
21
61
 
22
62
  # @!visibility private
23
63
  # Caller must pass position one of these positions :down, :left, :right, :up
24
64
  def rotate_home_button_to(position)
65
+
25
66
  valid_positions = [:down, :left, :right, :up]
26
67
  unless valid_positions.include?(position)
27
68
  raise ArgumentError,
@@ -42,7 +83,28 @@ module Calabash
42
83
  return orientation
43
84
  end
44
85
 
45
- @automator.rotate_home_button_to(position, status_bar_orientation)
86
+ family = device_family
87
+
88
+ if family == 'iPad'
89
+ form_factor = 'ipad'
90
+ else
91
+ form_factor = 'iphone'
92
+ end
93
+
94
+ ROTATION_CANDIDATES.each do |recording_name|
95
+ playback_route(recording_name, form_factor)
96
+
97
+ # Wait for rotation animation.
98
+ #
99
+ # Can't wait for animations because there might be animations other
100
+ # than rotation on the screen.
101
+ sleep(0.4)
102
+
103
+ orientation = status_bar_orientation.to_sym
104
+ if orientation == position
105
+ return orientation.to_s
106
+ end
107
+ end
46
108
 
47
109
  orientation.to_s
48
110
  end
@@ -0,0 +1,21 @@
1
+ module Calabash
2
+ module IOS
3
+ # @!visibility private
4
+ module TextMixin
5
+
6
+ # @!visibility private
7
+ def enter_text(text)
8
+ wait_for_keyboard(Calabash::Wait.default_options[:timeout])
9
+ existing_text = text_from_keyboard_first_responder
10
+ options = { existing_text: existing_text }
11
+ uia_type_string(text, options)
12
+ end
13
+
14
+ # @!visibility private
15
+ def _enter_text_in(query, text)
16
+ _tap(query)
17
+ enter_text(text)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -16,6 +16,7 @@ module Calabash
16
16
  require 'calabash/ios/device/rotation_mixin'
17
17
  require 'calabash/ios/device/keyboard_mixin'
18
18
  require 'calabash/ios/device/uia_keyboard_mixin'
19
+ require 'calabash/ios/device/text_mixin'
19
20
  require 'calabash/ios/device/uia_mixin'
20
21
  require 'calabash/ios/device/ipad_1x_2x_mixin'
21
22
  require 'calabash/ios/device/device_implementation'