calabash 1.9.9.pre2 → 1.9.9.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -0
  3. data/lib/calabash.rb +4 -2
  4. data/lib/calabash/android/build/java_keystore.rb +1 -0
  5. data/lib/calabash/android/console_helpers.rb +1 -0
  6. data/lib/calabash/android/defaults.rb +23 -13
  7. data/lib/calabash/android/device.rb +84 -19
  8. data/lib/calabash/android/environment.rb +2 -0
  9. data/lib/calabash/android/gestures.rb +4 -3
  10. data/lib/calabash/android/interactions.rb +1 -0
  11. data/lib/calabash/android/lib/.irbrc +61 -48
  12. data/lib/calabash/android/lib/TestServer.apk +0 -0
  13. data/lib/calabash/android/life_cycle.rb +3 -2
  14. data/lib/calabash/android/orientation.rb +1 -0
  15. data/lib/calabash/android/physical_buttons.rb +3 -1
  16. data/lib/calabash/android/screenshot.rb +0 -1
  17. data/lib/calabash/android/text.rb +1 -0
  18. data/lib/calabash/application.rb +20 -1
  19. data/lib/calabash/cli/generate.rb +10 -2
  20. data/lib/calabash/console_helpers.rb +101 -13
  21. data/lib/calabash/defaults.rb +36 -3
  22. data/lib/calabash/device.rb +28 -3
  23. data/lib/calabash/gestures.rb +12 -12
  24. data/lib/calabash/http/request.rb +1 -0
  25. data/lib/calabash/http/retriable_client.rb +1 -0
  26. data/lib/calabash/interactions.rb +2 -1
  27. data/lib/calabash/ios.rb +2 -0
  28. data/lib/calabash/ios/conditions.rb +1 -0
  29. data/lib/calabash/ios/console_helpers.rb +1 -0
  30. data/lib/calabash/ios/defaults.rb +32 -17
  31. data/lib/calabash/ios/device/device_implementation.rb +5 -1
  32. data/lib/calabash/ios/device/gestures_mixin.rb +27 -7
  33. data/lib/calabash/ios/device/rotation_mixin.rb +2 -2
  34. data/lib/calabash/ios/device/routes/error.rb +1 -0
  35. data/lib/calabash/ios/device/routes/playback_route_mixin.rb +1 -1
  36. data/lib/calabash/ios/device/routes/uia_route_mixin.rb +1 -1
  37. data/lib/calabash/ios/device/uia_mixin.rb +1 -1
  38. data/lib/calabash/ios/gestures.rb +107 -0
  39. data/lib/calabash/ios/interactions.rb +1 -0
  40. data/lib/calabash/ios/lib/.irbrc +61 -47
  41. data/lib/calabash/ios/orientation.rb +1 -0
  42. data/lib/calabash/ios/runtime.rb +1 -0
  43. data/lib/calabash/ios/scroll.rb +7 -7
  44. data/lib/calabash/ios/text.rb +3 -0
  45. data/lib/calabash/ios/uia.rb +1 -0
  46. data/lib/calabash/lib/skeleton/.gitignore +19 -0
  47. data/lib/calabash/lib/skeleton/Gemfile +5 -0
  48. data/lib/calabash/life_cycle.rb +3 -2
  49. data/lib/calabash/location.rb +5 -6
  50. data/lib/calabash/logger.rb +1 -0
  51. data/lib/calabash/orientation.rb +1 -0
  52. data/lib/calabash/page.rb +1 -0
  53. data/lib/calabash/screenshot.rb +1 -0
  54. data/lib/calabash/server.rb +1 -0
  55. data/lib/calabash/text.rb +3 -2
  56. data/lib/calabash/utility.rb +2 -1
  57. data/lib/calabash/version.rb +1 -1
  58. data/lib/calabash/wait.rb +1 -0
  59. metadata +114 -114
  60. data/lib/calabash/android/cucumber.rb +0 -3
  61. data/lib/calabash/android/scroll.rb +0 -5
  62. data/lib/calabash/patch/run_loop.rb +0 -90
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 145d0607c951c97fed6b885c1c492cbd86a79da4
4
- data.tar.gz: 561bec553b18f3f8b98346548dc7e21812470740
3
+ metadata.gz: c93bdf73649617b8de5fe8e2e34fcf03a2f31f2e
4
+ data.tar.gz: 187f1e60ca6bf8005efa47ee03a9f6896c169599
5
5
  SHA512:
6
- metadata.gz: e51ffc4e81c0e7ad3b0fa6e1855b1d584003313d64fd0b91bab00ed429d2371a01712baa488b48ccdcfacc6fcbaa876dcd7bfe5bf8d001f09fc48268e869da53
7
- data.tar.gz: 4563da016a43db69eac0ef6c5316121abe87c872488d82c1aab508c49567ec75ad43704faff5e3552a0e1fe52e0d7580f4b4691f08e1edfb538b7d7e83745b98
6
+ metadata.gz: de02fd0467b70c2836fcca4859b803537365bf69ef6ae9c7f70f7f153ee877ecbaa1ec69a5941de2ba816874e9b9ad131af9b79642aef88c17a505d73df15af0
7
+ data.tar.gz: cd2a3b11e0ce8dcbc31236346f483440cfd61cdb00b12124ccf9c8922ee0373f5f940d2ea3e902308fca6f47c4bb8405816d5b9c238a2ac3c5ab6ad67e38c438
data/README.md CHANGED
@@ -18,6 +18,25 @@ $ ./changing_old_files.sh
18
18
 
19
19
  Before Calabash is ready to be released, the old gems will exist outside version control. To make a change run the script `copy_repos.sh`. This will copy the Android and iOS repositories and extract them as files in the directory `old`. Then execute `changing_old_files.sh`. This script will move old files into their new directories. To make changes to "old files" e.g. move them, add your steps to `changing_old_files.sh` and execute it. To make code changes to old files, change them locally first to ensure they work. Then copy the change to the branch `united` on either iOS or Android. Commit the changes and push them upstream. `copy_repos.sh` will always download the newest files.
20
20
 
21
+ ## Rake
22
+
23
+ **TODO** Release instructions for Android and iOS.
24
+
25
+ ```
26
+ $ rake -T
27
+ rake android:build # Build the Android test server
28
+ rake build # Build calabash-1.9.9.pre2.gem into the pkg directory
29
+ rake ctags # Generate ctags in ./git/tags
30
+ rake cucumber:android # Run Android cucumber tests
31
+ rake cucumber:ios # Run iOS cucumber tests
32
+ rake install # Build and install calabash-1.9.9.pre2.gem into system gems
33
+ rake release # Create tag v1.9.9.pre2 and build and push calabash-1.9.9.pre2.gem to Rubygems
34
+ rake spec # Run RSpec code examples
35
+ rake unit # Run RSpec code examples
36
+ rake yard # Generate YARD Documentation
37
+ rake yard:publish # Generate and publish docs
38
+ ```
39
+
21
40
  ## Testing
22
41
 
23
42
  ### rspec
data/lib/calabash.rb CHANGED
@@ -4,7 +4,6 @@
4
4
  # It is developed and maintained by Xamarin and is released under the Eclipse
5
5
  # Public License.
6
6
  module Calabash
7
- require 'calabash/patch/run_loop'
8
7
  require 'calabash/version'
9
8
  require 'calabash/environment'
10
9
  require 'calabash/logger'
@@ -62,7 +61,7 @@ module Calabash
62
61
  # page(LoginPage).method
63
62
  # end
64
63
  #
65
- # @param [Class] The page to instantiate
64
+ # @param [Class] page_class The page to instantiate
66
65
  # @return [Calabash::Page] An instance of the page class
67
66
  def page(page_class)
68
67
  if android?
@@ -98,14 +97,17 @@ module Calabash
98
97
  end
99
98
  end
100
99
 
100
+ # Is the app under test running on Android?
101
101
  def android?
102
102
  Android.const_defined?(:Device) && Device.default.is_a?(Android::Device)
103
103
  end
104
104
 
105
+ # Is the app under test running on iOS?
105
106
  def ios?
106
107
  IOS.const_defined?(:Device) && Device.default.is_a?(IOS::Device)
107
108
  end
108
109
 
110
+ # @!visibility private
109
111
  def self.new_embed_method!(method)
110
112
  EmbeddingContext.new_embed_method(method)
111
113
  end
@@ -3,6 +3,7 @@ require 'escape'
3
3
  module Calabash
4
4
  module Android
5
5
  module Build
6
+ # @!visibility private
6
7
  class JavaKeystore
7
8
  CALABASH_KEYSTORE_SETTINGS_FILENAME = 'calabash_keystore_settings.json'
8
9
 
@@ -1,4 +1,5 @@
1
1
  module Calabash
2
+ # @!visibility private
2
3
  module ConsoleHelpers
3
4
  def self.render(data, indentation)
4
5
  if visible?(data)
@@ -1,21 +1,31 @@
1
1
  module Calabash
2
2
  module Android
3
- def self.setup_defaults!
4
- setup_default_application!
5
- setup_default_device!
6
- end
3
+ module Defaults
4
+ # Sets up the default device and the default application based on the
5
+ # environment.
6
+ #
7
+ # @see Calabash::Android::Defaults#setup_default_application!
8
+ # @see Calabash::Android::Defaults#setup_default_device!
9
+ # @see Calabash::Environment
10
+ def setup_defaults!
11
+ setup_default_application!
12
+ setup_default_device!
13
+ end
7
14
 
8
- def self.setup_default_application!
9
- # Setup the default application
10
- Calabash.default_application = Application.default_from_environment
11
- end
15
+ # Sets up the default application based on the environment.
16
+ def setup_default_application!
17
+ # Setup the default application
18
+ Calabash.default_application = Application.default_from_environment
19
+ end
12
20
 
13
- def self.setup_default_device!
14
- # Setup the default device
15
- identifier = Device.default_serial
16
- server = Server.default
21
+ # Sets up the default device based on the environment.
22
+ def setup_default_device!
23
+ # Setup the default device
24
+ identifier = Device.default_serial
25
+ server = Server.default
17
26
 
18
- Calabash.default_device = Device.new(identifier, server)
27
+ Calabash.default_device = Device.new(identifier, server)
28
+ end
19
29
  end
20
30
  end
21
31
  end
@@ -3,6 +3,7 @@ require 'json'
3
3
  module Calabash
4
4
  module Android
5
5
  # A representation of a Calabash Android device.
6
+ # @!visibility private
6
7
  class Device < ::Calabash::Device
7
8
  attr_reader :adb
8
9
 
@@ -15,6 +16,12 @@ module Calabash
15
16
  end
16
17
  end
17
18
 
19
+ # @!visibility private
20
+ def change_server(new_server)
21
+ super(new_server)
22
+ port_forward(new_server.endpoint.port, new_server.test_server_port)
23
+ end
24
+
18
25
  def self.default_serial
19
26
  serials = list_serials
20
27
 
@@ -156,7 +163,7 @@ module Calabash
156
163
  raise "mapping \"#{query}\" with \"#{method_name}\" failed because: #{result['reason']}\n#{result['details']}"
157
164
  end
158
165
 
159
- result['results']
166
+ Calabash::QueryResult.create(result['results'], query)
160
167
  end
161
168
 
162
169
  def perform_action(action, *arguments)
@@ -350,18 +357,17 @@ module Calabash
350
357
  "/data/data/#{application.test_server.identifier}/files/calabash_finished.out"
351
358
  end
352
359
 
353
- def calabash_server_failure_exists?(application)
354
- cmd = "ls #{calabash_server_failure_file_path(application)}"
360
+ def adb_file_exists?(file)
361
+ cmd = "ls #{file}"
362
+ adb.shell(cmd, no_exit_code_check: true).chomp == file
363
+ end
355
364
 
356
- adb.shell(cmd, no_exit_code_check: true).chomp ==
357
- calabash_server_failure_file_path(application)
365
+ def calabash_server_failure_exists?(application)
366
+ adb_file_exists?(calabash_server_failure_file_path(application))
358
367
  end
359
368
 
360
369
  def calabash_server_finished_exists?(application)
361
- cmd = "ls #{calabash_server_finished_file_path(application)}"
362
-
363
- adb.shell(cmd, no_exit_code_check: true).chomp ==
364
- calabash_server_finished_file_path(application)
370
+ adb_file_exists?(calabash_server_finished_file_path(application))
365
371
  end
366
372
 
367
373
  def read_calabash_sever_failure(application)
@@ -406,6 +412,20 @@ module Calabash
406
412
  raise "The test-server '#{application.test_server.identifier}' is not installed"
407
413
  end
408
414
 
415
+ installed_app = installed_apps.find{|app| app[:package] == application.identifier}
416
+ installed_app_md5_checksum = md5_checksum(installed_app[:path])
417
+
418
+ if application.md5_checksum != installed_app_md5_checksum
419
+ raise "The specified app is not the same as the installed app (#{application.md5_checksum} != #{installed_app_md5_checksum})."
420
+ end
421
+
422
+ installed_test_server = installed_apps.find{|app| app[:package] == application.test_server.identifier}
423
+ installed_test_server_md5_checksum = md5_checksum(installed_test_server[:path])
424
+
425
+ if application.test_server.md5_checksum != installed_test_server_md5_checksum
426
+ raise "The specified test-server is not the same as the installed test-server (#{application.test_server.md5_checksum} != #{installed_test_server_md5_checksum})."
427
+ end
428
+
409
429
  ensure_screen_on
410
430
 
411
431
  # Clear any old error reports
@@ -536,6 +556,10 @@ module Calabash
536
556
  raise ArgumentError, "No test server set for '#{application}'"
537
557
  end
538
558
 
559
+ unless app_installed?(application.identifier)
560
+ raise "The application #{application.identifier}' is not installed"
561
+ end
562
+
539
563
  unless app_installed?(application.test_server.identifier)
540
564
  raise "The test-server '#{application.test_server.identifier}' is not installed"
541
565
  end
@@ -746,7 +770,7 @@ module Calabash
746
770
  gesture = Gestures::Gesture.double_tap(gesture_options)
747
771
 
748
772
  execute_gesture(Gestures::Gesture.with_parameters(gesture,
749
- query_string: query.to_s,
773
+ query: query,
750
774
  timeout: options[:timeout]))
751
775
  end
752
776
 
@@ -785,7 +809,7 @@ module Calabash
785
809
  gesture = Gestures::Gesture.generate_swipe(from, to, time: duration)
786
810
 
787
811
  execute_gesture(Gestures::Gesture.with_parameters(gesture,
788
- query_string: query.to_s,
812
+ query: query,
789
813
  timeout: options[:timeout]))
790
814
  end
791
815
 
@@ -796,7 +820,7 @@ module Calabash
796
820
  gesture.gestures.first.touches[1].query = query_to
797
821
 
798
822
  execute_gesture(Gestures::Gesture.with_parameters(gesture,
799
- query_string: query_to,
823
+ query: query_to,
800
824
  timeout: options[:timeout]))
801
825
  end
802
826
 
@@ -813,7 +837,7 @@ module Calabash
813
837
  gesture = Gestures::Gesture.generate_swipe(from, to, time: duration, flick: true)
814
838
 
815
839
  execute_gesture(Gestures::Gesture.with_parameters(gesture,
816
- query_string: query.to_s,
840
+ query: query,
817
841
  timeout: options[:timeout]))
818
842
  end
819
843
 
@@ -822,7 +846,7 @@ module Calabash
822
846
  gesture = Gestures::Gesture.pinch(direction)
823
847
 
824
848
  execute_gesture(Gestures::Gesture.with_parameters(gesture,
825
- query_string: query.to_s,
849
+ query: query,
826
850
  timeout: options[:timeout]))
827
851
  end
828
852
 
@@ -842,15 +866,56 @@ module Calabash
842
866
 
843
867
  # @!visibility private
844
868
  def adb_install_app(application)
869
+ # Because of a bug in the latest version of ADB
870
+ # https://github.com/android/platform_system_core/blob/0f91887868e51de67bdf9aedc97fbcb044dc1969/adb/commandline.cpp#L1466
871
+ # ADB now uses rm -f ... to remove the temporary application on the
872
+ # device, but not all devices (below a certain OS) supports this flag.
873
+ # The user will be unable to install the app and instead receive:
874
+ # RuntimeError: Could not install app 'com.xamarin.xtcandroidsample.test': rm failed for -f, No such file or directory
875
+ # We have rewritten the way adb handles app installation. It's a 3-step
876
+ # procedure:
877
+ # - Push the app binary to /data/local/tmp
878
+ # - Install the app binary using pm
879
+ # - Remove the temporary apk.
845
880
  @logger.log "Installing #{application.path}"
846
- result = adb.command('install' , '-r', application.path, timeout: 60).lines.last
847
881
 
848
- if result.downcase.chomp != 'success'
849
- raise "Could not install app '#{application.identifier}': #{result.chomp}"
882
+ tmp_path = "/data/local/tmp/#{File.basename(application.path)}"
883
+
884
+ begin
885
+ adb.command('push', application.path, tmp_path, timeout: 60)
886
+ rescue ADB::ADBCallError => e
887
+ raise "Failed to push the application to the device storage: '#{e.message}'"
888
+ end
889
+
890
+ begin
891
+ result = nil
892
+
893
+ begin
894
+ result = adb.shell("pm install -r #{tmp_path}", timeout: 60)
895
+ rescue ADB::ADBCallError => e
896
+ raise "Failed to install the application on device: '#{e.message}'"
897
+ end
898
+
899
+ if result.lines.last.downcase.chomp != 'success'
900
+ raise "Could not install app '#{application.identifier}': #{result.chomp}"
901
+ end
902
+
903
+ unless installed_packages.include?(application.identifier)
904
+ raise "App '#{application.identifier}' was not installed"
905
+ end
906
+ rescue => e
907
+ begin
908
+ adb.shell("rm #{tmp_path}")
909
+ rescue ADB::ADBCallError => _
910
+ end
911
+
912
+ raise e
850
913
  end
851
914
 
852
- unless installed_packages.include?(application.identifier)
853
- raise "App '#{application.identifier}' was not installed"
915
+ begin
916
+ adb.shell("rm #{tmp_path}")
917
+ rescue ADB::ADBCallError => e
918
+ raise "Failed to remove the tmp apk from device: #{e.message}"
854
919
  end
855
920
  end
856
921
 
@@ -10,7 +10,9 @@ end
10
10
  module Calabash
11
11
  module Android
12
12
  class Environment < Calabash::Environment
13
+ # @!visibility private
13
14
  class InvalidEnvironmentError < RuntimeError; end
15
+ # @!visibility private
14
16
  class InvalidJavaSDKHome < RuntimeError; end
15
17
 
16
18
  private
@@ -2,6 +2,7 @@ require 'json'
2
2
 
3
3
  module Calabash
4
4
  module Android
5
+ # @!visibility private
5
6
  module Gestures
6
7
  class MultiTouchGesture
7
8
  attr_reader :gestures
@@ -344,12 +345,12 @@ module Calabash
344
345
  flick("* id:'content'", from, to, options)
345
346
  end
346
347
 
347
- # !@visibility private
348
+ # @!visibility private
348
349
  def _pinch_screen(direction, options={})
349
350
  Device.default.pinch(direction, "* id:'content'", options)
350
351
  end
351
352
 
352
- # !@visibility private
353
+ # @!visibility private
353
354
  def _pinch_to_zoom(direction, query, options={})
354
355
  if direction == :out
355
356
  Device.default.pinch(:in, query, options)
@@ -360,7 +361,7 @@ module Calabash
360
361
  end
361
362
  end
362
363
 
363
- # !@visibility private
364
+ # @!visibility private
364
365
  def _pinch_screen_to_zoom(direction, options={})
365
366
  _pinch_to_zoom(direction, "* id:'content'", options)
366
367
  end
@@ -1,5 +1,6 @@
1
1
  module Calabash
2
2
  module Android
3
+ # @!visibility private
3
4
  module Interactions
4
5
  # Go back.
5
6
  def go_back
@@ -1,50 +1,63 @@
1
+ require 'irb/completion'
2
+ require 'irb/ext/save-history'
3
+
4
+ IRB.conf[:SAVE_HISTORY] = 100
5
+ IRB.conf[:HISTORY_FILE] = '.irb-history'
6
+
7
+ ARGV.concat [ '--readline',
8
+ '--prompt-mode',
9
+ 'simple']
10
+
11
+ begin
12
+ require 'pry'
13
+ Pry.config.history.file = '.pry-history'
14
+ require 'pry-nav'
15
+ rescue LoadError => _
16
+
17
+ end
18
+
19
+ begin
20
+ require 'awesome_print'
21
+ AwesomePrint.irb!
22
+ rescue LoadError => e
23
+ msg = ["Caught a LoadError: could not load 'awesome_print'",
24
+ "#{e}",
25
+ '',
26
+ 'Use bundler (recommended) or uninstall awesome_print.',
27
+ '',
28
+ '# Use bundler (recommended)',
29
+ '$ bundle update',
30
+ '$ bundle exec calabash console [path to apk]',
31
+ '',
32
+ '# Uninstall',
33
+ '$ gem update --system',
34
+ '$ gem uninstall -Vax --force --no-abort-on-dependent awesome_print']
35
+ puts msg
36
+ exit(1)
37
+ end
38
+
1
39
  begin
2
- require 'irb/completion'
3
- require 'irb/ext/save-history'
4
-
5
- begin
6
- require 'awesome_print'
7
- rescue LoadError => e
8
- msg = ["Caught a LoadError: could not load 'awesome_print'",
9
- "#{e}",
10
- '',
11
- 'Use bundler (recommended) or uninstall awesome_print.',
12
- '',
13
- '# Use bundler (recommended)',
14
- '$ bundle update',
15
- '$ bundle exec calabash console [path to apk]',
16
- '',
17
- '# Uninstall',
18
- '$ gem update --system',
19
- '$ gem uninstall -Vax --force --no-abort-on-dependent awesome_print']
20
- puts msg
21
- exit(1)
22
- end
23
-
24
- AwesomePrint.irb!
25
-
26
- ARGV.concat [ '--readline',
27
- '--prompt-mode',
28
- 'simple']
29
-
30
- # 50 entries in the list
31
- IRB.conf[:SAVE_HISTORY] = 50
32
-
33
- # Store results in home directory with specified file name
34
- IRB.conf[:HISTORY_FILE] = '.irb-history'
35
-
36
- require 'calabash/android'
37
-
38
- extend Calabash::Android
39
- extend Calabash::ConsoleHelpers
40
-
41
- Calabash::Android.setup_defaults!
42
-
43
- Calabash.new_embed_method!(lambda {|*_| Calabash::Logger.info 'Embed is not available in the console.'})
44
- Calabash::Screenshot.screenshot_directory_prefix = 'console_'
40
+ require 'calabash/android'
41
+
42
+ extend Calabash::Android
43
+ extend Calabash::ConsoleHelpers
44
+
45
+ Calabash::Android.setup_defaults!
46
+
47
+ embed_lambda = lambda do |*_|
48
+ Calabash::Logger.info 'Embed is not available in the console.'
49
+ true
50
+ end
51
+
52
+ Calabash.new_embed_method!(embed_lambda)
53
+
54
+ Calabash::Screenshot.screenshot_directory_prefix = 'console_'
55
+
56
+ puts_console_details
57
+ message_of_the_day
45
58
  rescue Exception => e
46
- puts 'Unable to start console:'
47
- puts "#{e.class}: #{e.message}"
48
- puts "#{e.backtrace.join("\n")}"
49
- exit(1)
50
- end
59
+ puts 'Unable to start console:'
60
+ puts "#{e.class}: #{e.message}"
61
+ puts "#{e.backtrace.join("\n")}"
62
+ exit(1)
63
+ end