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
@@ -5,10 +5,6 @@ module Calabash
5
5
  # A representation of a Calabash Android device.
6
6
  # @!visibility private
7
7
  class Device < ::Calabash::Device
8
- require 'calabash/android/device/helper_application'
9
-
10
- include Calabash::Android::Device::HelperApplication
11
-
12
8
  attr_reader :adb
13
9
 
14
10
  def initialize(identifier, server)
@@ -70,28 +66,28 @@ module Calabash
70
66
 
71
67
  # @!visibility private
72
68
  def installed_packages
73
- installed_apps.map{|e| e[:package]}
69
+ adb.shell('pm list packages').lines.map do |line|
70
+ line.sub('package:', '').chomp
71
+ end
74
72
  end
75
73
 
76
74
  # @!visibility private
77
75
  def installed_apps
78
- @installed_apps_cache ||= lambda do
79
- adb.shell('pm list packages -f').lines.map do |line|
80
- # line will be package:<path>=<package>
81
- # e.g. "package:/system/app/GoogleEars.apk=com.google.android.ears"
82
- info = line.sub("package:", "")
76
+ adb.shell('pm list packages -f').lines.map do |line|
77
+ # line will be package:<path>=<package>
78
+ # e.g. "package:/system/app/GoogleEars.apk=com.google.android.ears"
79
+ info = line.sub("package:", "")
83
80
 
84
- app_path, app_id = info.split('=').map(&:chomp)
81
+ app_path, app_id = info.split('=').map(&:chomp)
85
82
 
86
- {package: app_id, path: app_path}
87
- end
88
- end.call
83
+ {package: app_id, path: app_path}
84
+ end
89
85
  end
90
86
 
91
87
  # @!visibility private
92
88
  def test_server_responding?
93
89
  begin
94
- http_client.post(HTTP::Request.new('ping'), retries: 1).body == 'pong'
90
+ http_client.get(HTTP::Request.new('ping'), retries: 1).body == 'pong'
95
91
  rescue HTTP::Error => _
96
92
  false
97
93
  end
@@ -100,7 +96,7 @@ module Calabash
100
96
  # @!visibility private
101
97
  def test_server_ready?
102
98
  begin
103
- http_client.post(HTTP::Request.new('ready')).body == 'true'
99
+ http_client.get(HTTP::Request.new('ready')).body == 'true'
104
100
  rescue HTTP::Error => _
105
101
  false
106
102
  end
@@ -170,9 +166,9 @@ module Calabash
170
166
  request = HTTP::Request.new('map', params_for_request(parameters))
171
167
 
172
168
  http_result = if method_name == :flash
173
- http_client.post(request, timeout: 30)
169
+ http_client.get(request, timeout: 30)
174
170
  else
175
- http_client.post(request)
171
+ http_client.get(request)
176
172
  end
177
173
 
178
174
  result = JSON.parse(http_result.body)
@@ -189,9 +185,9 @@ module Calabash
189
185
  @logger.log "Action: #{action} - Arguments: #{arguments.join(', ')}"
190
186
 
191
187
  parameters = {command: action, arguments: arguments}
192
- request = HTTP::Request.new('', params_for_request(parameters))
188
+ request = HTTP::Request.new('/', params_for_request(parameters))
193
189
 
194
- result = JSON.parse(http_client.post(request).body)
190
+ result = JSON.parse(http_client.get(request).body)
195
191
 
196
192
  unless result['success']
197
193
  message = result['message'] || result['bonusInformation']
@@ -215,17 +211,6 @@ module Calabash
215
211
  perform_action('keyboard_enter_text', text)
216
212
  end
217
213
 
218
- # @!visibility private
219
- def md5_checksum_for_app_package(package)
220
- app = installed_apps.find{|app| app[:package] == package}
221
-
222
- unless app
223
- raise "Application with package '#{app}' not installed"
224
- end
225
-
226
- md5_checksum(app[:path])
227
- end
228
-
229
214
  # @!visibility private
230
215
  def md5_checksum(file_path)
231
216
  result = adb.shell("#{md5_binary} '#{file_path}'")
@@ -244,7 +229,7 @@ module Calabash
244
229
  json = parameters.to_json
245
230
  request = HTTP::Request.new('/backdoor', json: json)
246
231
 
247
- body = http_client.post(request).body
232
+ body = http_client.get(request).body
248
233
  result = JSON.parse(body)
249
234
 
250
235
  if result['outcome'] != 'SUCCESS'
@@ -381,7 +366,7 @@ module Calabash
381
366
  json = parameters.to_json
382
367
  request = HTTP::Request.new('/map', json: json)
383
368
 
384
- body = http_client.post(request).body
369
+ body = http_client.get(request).body
385
370
  result = JSON.parse(body)
386
371
 
387
372
  if result['outcome'] != 'SUCCESS'
@@ -424,75 +409,25 @@ module Calabash
424
409
  adb.shell(cmd, no_exit_code_check: true).chomp == file
425
410
  end
426
411
 
427
- def file_exists?(file)
428
- ensure_helper_application_started
429
-
430
- request = HTTP::Request.new('file-exists', params_for_request(fileName: file))
431
- response = helper_application_http_client.post(request)
432
-
433
- if response.status != 200
434
- result = JSON.parse(response.body)
435
- raise "Failed to find out if file exists #{result['reason']}"
436
- end
437
-
438
- case response.body
439
- when 'true'
440
- return true
441
- when 'false'
442
- return false
443
- else
444
- raise "Invalid resposne '#{response.body}'"
445
- end
446
- end
447
-
448
- def read_file(file)
449
- ensure_helper_application_started
450
-
451
- request = HTTP::Request.new('read-file', params_for_request(fileName: file))
452
- response = helper_application_http_client.post(request)
453
-
454
- if response.status != 200
455
- result = JSON.parse(response.body)
456
- raise "Failed to read file. Reason: #{result['reason']}"
457
- end
458
-
459
- response.body
460
- end
461
-
462
412
  def calabash_server_failure_exists?(application)
463
- file_exists?(calabash_server_failure_file_path(application))
413
+ adb_file_exists?(calabash_server_failure_file_path(application))
464
414
  end
465
415
 
466
416
  def calabash_server_finished_exists?(application)
467
- file_exists?(calabash_server_finished_file_path(application))
417
+ adb_file_exists?(calabash_server_finished_file_path(application))
468
418
  end
469
419
 
470
420
  def read_calabash_sever_failure(application)
471
- read_file(calabash_server_failure_file_path(application))
421
+ adb.shell("cat #{calabash_server_failure_file_path(application)}")
472
422
  end
473
423
 
474
424
  def read_calabash_sever_finished(application)
475
- read_file(calabash_server_finished_file_path(application))
425
+ adb.shell("cat #{calabash_server_finished_file_path(application)}")
476
426
  end
477
427
 
478
428
  def clear_calabash_server_report(application)
479
429
  if installed_packages.include?(application.test_server.identifier)
480
- parameters =
481
- {
482
- intent: {
483
- flags: 0x10000000,
484
- component: {
485
- packageName: application.test_server.identifier,
486
- className: 'sh.calaba.instrumentationbackend.StatusReporterActivity',
487
- },
488
- extras: {
489
- method: 'clear'
490
- }
491
- }
492
- }
493
-
494
- ensure_helper_application_started
495
- start_activity(parameters)
430
+ adb.shell("am start -e method clear -n #{application.test_server.identifier}/sh.calaba.instrumentationbackend.StatusReporterActivity")
496
431
  end
497
432
  end
498
433
 
@@ -504,13 +439,12 @@ module Calabash
504
439
  end
505
440
 
506
441
  env_options[:test_server_port] = server.test_server_port
442
+ env_options[:target_package] = application.identifier
507
443
 
508
444
  env_options[:class] = options.fetch(:class, 'sh.calaba.instrumentationbackend.InstrumentationBackend')
509
445
 
510
446
  if options[:activity]
511
447
  env_options[:main_activity] = options[:activity]
512
- else
513
- env_options[:main_activity] = 'null'
514
448
  end
515
449
 
516
450
  if application.test_server.nil?
@@ -525,13 +459,15 @@ module Calabash
525
459
  raise "The test-server '#{application.test_server.identifier}' is not installed"
526
460
  end
527
461
 
528
- installed_app_md5_checksum = md5_checksum_for_app_package(application.identifier)
462
+ installed_app = installed_apps.find{|app| app[:package] == application.identifier}
463
+ installed_app_md5_checksum = md5_checksum(installed_app[:path])
529
464
 
530
465
  if application.md5_checksum != installed_app_md5_checksum
531
466
  raise "The specified app is not the same as the installed app (#{application.md5_checksum} != #{installed_app_md5_checksum})."
532
467
  end
533
468
 
534
- installed_test_server_md5_checksum = md5_checksum_for_app_package(application.test_server.identifier)
469
+ installed_test_server = installed_apps.find{|app| app[:package] == application.test_server.identifier}
470
+ installed_test_server_md5_checksum = md5_checksum(installed_test_server[:path])
535
471
 
536
472
  if application.test_server.md5_checksum != installed_test_server_md5_checksum
537
473
  raise "The specified test-server is not the same as the installed test-server (#{application.test_server.md5_checksum} != #{installed_test_server_md5_checksum})."
@@ -539,6 +475,9 @@ module Calabash
539
475
 
540
476
  ensure_screen_on
541
477
 
478
+ # Clear any old error reports
479
+ clear_calabash_server_report(application)
480
+
542
481
  # We have to forward the port ourselves, as an old test-server could be
543
482
  # running on the old port. If the retriable client was able to
544
483
  # determine if the port had been forwarded, we would not need this.
@@ -558,17 +497,14 @@ module Calabash
558
497
  end
559
498
  end
560
499
 
561
- # Clear any old error reports
562
- clear_calabash_server_report(application)
563
-
564
500
  extras = ''
565
501
 
566
502
  env_options.each_pair do |key, val|
567
- extras = "#{extras} -e #{key.to_s} #{val.to_s}"
503
+ extras = "#{extras} -e \"#{key.to_s}\" \"#{val.to_s}\""
568
504
  end
569
505
 
570
506
  begin
571
- adb_instrument(application,
507
+ instrument(application,
572
508
  'sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner',
573
509
  extras)
574
510
  rescue ADB::ADBCallError => e
@@ -576,7 +512,7 @@ module Calabash
576
512
  end
577
513
 
578
514
  begin
579
- Calabash::Retry.retry(retries: 30, interval: 1, timeout: 30, on_errors: [RetryError]) do
515
+ Retriable.retriable(tries: 30, interval: 1, timeout: 30, on: RetryError) do
580
516
  unless test_server_responding?
581
517
  # Read any message the test-server might have
582
518
  if calabash_server_failure_exists?(application)
@@ -595,7 +531,7 @@ module Calabash
595
531
  end
596
532
 
597
533
  begin
598
- Calabash::Retry.retry(retries: 10, interval: 1, timeout: 10, on_errors: [RetryError]) do
534
+ Retriable.retriable(tries: 10, interval: 1, timeout: 10) do
599
535
  unless test_server_ready?
600
536
  raise RetryError
601
537
  end
@@ -606,31 +542,15 @@ module Calabash
606
542
  raise 'Test-server was never ready'
607
543
  end
608
544
 
609
- start_application(options[:intent])
610
-
611
545
  # Return true to avoid cluttering the console
612
546
  true
613
547
  end
614
548
 
615
- # @!visibility private
616
- def start_application(intent)
617
- request = HTTP::Request.new('start-application', params_for_request(intent: intent))
618
- body = http_client.post(request).body
619
-
620
- result = JSON.parse(body)
621
-
622
- if result['outcome'] != 'SUCCESS'
623
- raise "Failed to start application. Reason: #{result['reason']}"
624
- end
625
-
626
- result['result']
627
- end
628
-
629
549
  # @!visibility private
630
550
  def _stop_app
631
- Calabash::Retry.retry(retries: 5, interval: 1) do
551
+ Retriable.retriable(tries: 5, interval: 1) do
632
552
  begin
633
- http_client.post(HTTP::Request.new('kill'), retries: 1, interval: 0)
553
+ http_client.get(HTTP::Request.new('kill'), retries: 1, interval: 0)
634
554
  rescue HTTP::Error => _
635
555
  # It's fine that we can't contact the test-server, as it might already have been shut down
636
556
  if test_server_responding?
@@ -674,7 +594,7 @@ module Calabash
674
594
  end
675
595
 
676
596
  # @!visibility private
677
- def adb_instrument(application, test_server_activity, extras = '')
597
+ def instrument(application, test_server_activity, extras = '')
678
598
  unless application.is_a?(Android::Application)
679
599
  raise ArgumentError, "Invalid application type '#{application.class}'"
680
600
  end
@@ -702,45 +622,11 @@ module Calabash
702
622
  class EnsureInstrumentActionError < RuntimeError; end
703
623
 
704
624
  # @!visibility private
705
- def ensure_adb_instrument_action(application, test_server_activity, extras = '')
625
+ def ensure_instrument_action(application, test_server_activity, extras = '')
706
626
  clear_calabash_server_report(application)
707
627
 
708
628
  begin
709
- adb_instrument(application, test_server_activity, extras)
710
- rescue ADB::ADBCallError => e
711
- raise EnsureInstrumentActionError, e
712
- end
713
-
714
- begin
715
- Timeout.timeout(10) do
716
- loop do
717
- if calabash_server_failure_exists?(application)
718
- failure_message = read_calabash_sever_failure(application)
719
-
720
- raise EnsureInstrumentActionError, parse_failure_message(failure_message)
721
- end
722
-
723
- if calabash_server_finished_exists?(application)
724
- output = read_calabash_sever_finished(application)
725
-
726
- if output == 'SUCCESSFUL'
727
- break
728
- end
729
- end
730
- end
731
- end
732
- rescue Timeout::Error => _
733
- raise EnsureInstrumentActionError, 'Timed out waiting for status'
734
- end
735
- end
736
-
737
- # @!visibility private
738
- def ensure_instrument_action(application, parameters)
739
- ensure_helper_application_started
740
- clear_calabash_server_report(application)
741
-
742
- begin
743
- instrument(parameters)
629
+ instrument(application, test_server_activity, extras)
744
630
  rescue ADB::ADBCallError => e
745
631
  raise EnsureInstrumentActionError, e
746
632
  end
@@ -770,18 +656,8 @@ module Calabash
770
656
 
771
657
  # @!visibility private
772
658
  def ts_clear_app_data(application)
773
- parameters =
774
- {
775
- intent: {
776
- component: {
777
- className: 'sh.calaba.instrumentationbackend.ClearAppData2',
778
- packageName: application.test_server.identifier
779
- }
780
- }
781
- }
782
-
783
659
  begin
784
- ensure_instrument_action(application, parameters)
660
+ ensure_instrument_action(application, 'sh.calaba.instrumentationbackend.ClearAppData2')
785
661
  rescue EnsureInstrumentActionError => e
786
662
  raise "Failed to clear app data: #{e.message}"
787
663
  end
@@ -866,10 +742,11 @@ module Calabash
866
742
  if installed_packages.include?(application.identifier)
867
743
  @logger.log 'Application is already installed. Ensuring right checksum'
868
744
 
869
- installed_app_md5_checksum = md5_checksum_for_app_package(application.identifier)
745
+ installed_app = installed_apps.find{|app| app[:package] == application.identifier}
746
+ installed_app_md5_checksum = md5_checksum(installed_app[:path])
870
747
 
871
748
  if application.md5_checksum != installed_app_md5_checksum
872
- @logger.log("The md5 checksum has changed for '#{application.identifier}' (#{application.md5_checksum} != #{installed_app_md5_checksum}).", :info)
749
+ @logger.log("The md5 checksum has changed (#{application.md5_checksum} != #{installed_app_md5_checksum}).", :info)
873
750
  _install_app(application)
874
751
  end
875
752
  else
@@ -1027,7 +904,6 @@ module Calabash
1027
904
 
1028
905
  # @!visibility private
1029
906
  def adb_uninstall_app(package)
1030
- @installed_apps_cache = nil
1031
907
  @logger.log "Uninstalling #{package}"
1032
908
  result = adb.command('uninstall', package, timeout: 60).lines.last
1033
909
 
@@ -1042,7 +918,6 @@ module Calabash
1042
918
 
1043
919
  # @!visibility private
1044
920
  def adb_install_app(application)
1045
- @installed_apps_cache = nil
1046
921
  # Because of a bug in the latest version of ADB
1047
922
  # https://github.com/android/platform_system_core/blob/0f91887868e51de67bdf9aedc97fbcb044dc1969/adb/commandline.cpp#L1466
1048
923
  # ADB now uses rm -f ... to remove the temporary application on the
@@ -1113,9 +988,9 @@ module Calabash
1113
988
 
1114
989
  # @!visibility private
1115
990
  def execute_gesture(multi_touch_gesture)
1116
- request = HTTP::Request.new('gesture', params_for_request(multi_touch_gesture))
991
+ request = HTTP::Request.new('gesture', json: multi_touch_gesture.to_json)
1117
992
 
1118
- body = http_client.post(request, timeout: multi_touch_gesture.timeout + 10).body
993
+ body = http_client.get(request, timeout: multi_touch_gesture.timeout + 10).body
1119
994
  result = JSON.parse(body)
1120
995
 
1121
996
  if result['outcome'] != 'SUCCESS'
@@ -1139,36 +1014,6 @@ module Calabash
1139
1014
  end
1140
1015
  end
1141
1016
 
1142
- class InstrumentationError < RuntimeError; end
1143
-
1144
- def instrument(parameters, http_client = helper_application_http_client)
1145
- request = HTTP::Request.new('instrument', params_for_request(parameters))
1146
-
1147
- body = http_client.post(request).body
1148
- result = JSON.parse(body)
1149
-
1150
- if result['outcome'] != 'SUCCESS'
1151
- raise InstrumentationError, "Failed to instrument. Reason: #{result['reason']}"
1152
- end
1153
-
1154
- true
1155
- end
1156
-
1157
- class StartActivityError < RuntimeError; end
1158
-
1159
- def start_activity(parameters, http_client = helper_application_http_client)
1160
- request = HTTP::Request.new('start-activity', params_for_request(parameters))
1161
-
1162
- body = http_client.post(request).body
1163
- result = JSON.parse(body)
1164
-
1165
- if result['outcome'] != 'SUCCESS'
1166
- raise StartActivityError, "Failed to start activity. Reason: #{result['reason']}"
1167
- end
1168
-
1169
- true
1170
- end
1171
-
1172
1017
  # @!visibility private
1173
1018
  def params_for_request(parameters)
1174
1019
  {json: parameters.to_json}
@@ -1181,9 +1026,6 @@ module Calabash
1181
1026
  else
1182
1027
  if adb.shell('md5', no_exit_code_check: true).chomp == 'md5 file ...'
1183
1028
  @md5_binary = 'md5'
1184
- elsif (r = adb.shell('md5sum _cal_no_such_file', no_exit_code_check: true)) && r.chomp.start_with?('md5sum:') &&
1185
- !r.include?('permission denied')
1186
- @md5_binary = 'md5sum'
1187
1029
  else
1188
1030
  # The device does not have 'md5'
1189
1031
  calmd5 = Calabash::Android.binary_location('calmd5', info[:cpu_architecture], can_handle_pie_binaries?)
@@ -1,11 +1,6 @@
1
1
  require 'rexml/document'
2
2
  require 'timeout'
3
-
4
- # We sometimes want to require a Ruby gem without having our IDE auto-complete
5
- # using it. For example awesome_print adds a ton of methods to 'Object'
6
- alias :cal_require_without_documentation :require
7
- cal_require_without_documentation 'luffa'
8
-
3
+ require 'luffa'
9
4
  require 'timeout'
10
5
 
11
6
  if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
@@ -30,14 +25,6 @@ module Calabash
30
25
  # @todo Maybe rename this to CAL_SERVER_URL or CAL_SERVER?
31
26
  DEVICE_ENDPOINT = URI.parse((variable('CAL_ENDPOINT') || 'http://127.0.0.1:34777'))
32
27
 
33
- # A URI that points to the helper server on the device.
34
- #
35
- # The default value is 'http://localhost:34778'.
36
- #
37
- # You can control the value of this variable by setting the `CAL_HELPER_ENDPOINT`
38
- # variable.
39
- DEVICE_HELPER_ENDPOINT = URI.parse((variable('CAL_HELPER_ENDPOINT') || 'http://127.0.0.1:34778'))
40
-
41
28
  private
42
29
 
43
30
  def self.set_android_dependencies(android_dependencies)
@@ -314,7 +314,7 @@ module Calabash
314
314
  end
315
315
 
316
316
  # @!visibility private
317
- define_method(:_pan_screen_up) do |options={}|
317
+ def _pan_screen_up(options={})
318
318
  from = {x: 50, y: 90}
319
319
  to = {x: 50, y: 10}
320
320
 
@@ -322,7 +322,7 @@ module Calabash
322
322
  end
323
323
 
324
324
  # @!visibility private
325
- define_method(:_pan_screen_down) do |options={}|
325
+ def _pan_screen_down(options={})
326
326
  from = {x: 50, y: 10}
327
327
  to = {x: 50, y: 90}
328
328
 
@@ -330,7 +330,7 @@ module Calabash
330
330
  end
331
331
 
332
332
  # @!visibility private
333
- define_method(:_flick_screen_up) do |options={}|
333
+ def _flick_screen_up(options={})
334
334
  from = {x: 50, y: 90}
335
335
  to = {x: 50, y: 10}
336
336
 
@@ -338,7 +338,7 @@ module Calabash
338
338
  end
339
339
 
340
340
  # @!visibility private
341
- define_method(:_flick_screen_down) do |options={}|
341
+ def _flick_screen_down(options={})
342
342
  from = {x: 50, y: 10}
343
343
  to = {x: 50, y: 90}
344
344
 
@@ -346,8 +346,24 @@ module Calabash
346
346
  end
347
347
 
348
348
  # @!visibility private
349
- define_method(:_pinch_screen) do |options={}|
350
- Calabash::Internal.with_default_device(required_os: :android) {|device| device.pinch(direction, "* id:'content'", options)}
349
+ def _pinch_screen(direction, options={})
350
+ Device.default.pinch(direction, "* id:'content'", options)
351
+ end
352
+
353
+ # @!visibility private
354
+ def _pinch_to_zoom(direction, query, options={})
355
+ if direction == :out
356
+ Device.default.pinch(:in, query, options)
357
+ elsif direction == :in
358
+ Device.default.pinch(:out, query, options)
359
+ else
360
+ raise "Invalid direction '#{direction}'"
361
+ end
362
+ end
363
+
364
+ # @!visibility private
365
+ def _pinch_screen_to_zoom(direction, options={})
366
+ _pinch_to_zoom(direction, "* id:'content'", options)
351
367
  end
352
368
  end
353
369
  end
@@ -8,16 +8,13 @@ module Calabash
8
8
  module Interactions
9
9
  # Go back. If the keyboard is shown, it will be dismissed.
10
10
  def go_back
11
- Calabash::Internal.with_default_device(required_os: :android) do |device|
12
- device.perform_action('hide_soft_keyboard')
13
- end
14
-
15
- press_physical_back_button
11
+ Device.default.perform_action('hide_soft_keyboard')
12
+ press_back_button
16
13
  end
17
14
 
18
15
  # Go to the home screen.
19
16
  def go_home
20
- Calabash::Internal.with_default_device(required_os: :android) {|device| device.go_home}
17
+ Device.default.go_home
21
18
 
22
19
  true
23
20
  end
@@ -25,33 +22,33 @@ module Calabash
25
22
  # Get the name of the currently focused activity
26
23
  #
27
24
  # @example
28
- # puts cal_android.focused_activity
25
+ # puts focused_activity
29
26
  # # => com.example.MainActivity
30
27
  #
31
28
  # @return [String] The name of the currently focused activity.
32
29
  def focused_activity
33
- Calabash::Internal.with_default_device(required_os: :android) {|device| device.current_focus[:activity]}
30
+ Device.default.current_focus[:activity]
34
31
  end
35
32
 
36
33
  # Get the name of the currently focused package
37
34
  #
38
35
  # @example
39
- # puts cal_android.focused_package
36
+ # puts focused_package
40
37
  # # => com.example
41
38
  #
42
39
  # @return [String] The name of the currently focused package
43
40
  def focused_package
44
- Calabash::Internal.with_default_device(required_os: :android) {|device| device.current_focus[:package]}
41
+ Device.default.current_focus[:package]
45
42
  end
46
43
 
47
44
  # Sets the date of the first visible date picker widget.
48
45
  #
49
46
  # @example
50
- # cal_android.set_date('2012-04-24')
47
+ # set_date('2012-04-24')
51
48
  #
52
49
  # @example
53
50
  # date = Date.parse('3rd Feb 2012')
54
- # cal_android.set_date(date)
51
+ # set_date(date)
55
52
  #
56
53
  # @param [Date, String] date The date to set. If given a String,
57
54
  # `Date.parse` is called on the string.
@@ -91,11 +88,11 @@ module Calabash
91
88
  # Sets the time of the first visible time picker widget.
92
89
  #
93
90
  # @example
94
- # cal_android.set_time('14:42')
91
+ # set_time('14:42')
95
92
  #
96
93
  # @example
97
94
  # time = Time.parse('8:30 AM')
98
- # cal_android.set_time(time)
95
+ # set_time(time)
99
96
  #
100
97
  # @param [Time, String] time The time to set. If given a String,
101
98
  # `Time.parse` is called on the string.
@@ -141,6 +138,12 @@ module Calabash
141
138
 
142
139
  true
143
140
  end
141
+
142
+
143
+ # @!visibility private
144
+ def _evaluate_javascript_in(query, javascript)
145
+ Device.default.evaluate_javascript_in(query, javascript)
146
+ end
144
147
  end
145
148
  end
146
149
  end