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
@@ -1,5 +1,6 @@
1
1
  module Calabash
2
2
  module Android
3
+ # @!visibility private
3
4
  module LifeCycle
4
5
  # Resume an application. If the application is already focused, nothing
5
6
  # will happen.
@@ -23,7 +24,7 @@ module Calabash
23
24
  end
24
25
 
25
26
 
26
- # !@visibility private
27
+ # @!visibility private
27
28
  def _send_current_app_to_background(for_seconds)
28
29
  package = focused_package
29
30
  activity = focused_activity
@@ -34,4 +35,4 @@ module Calabash
34
35
  end
35
36
  end
36
37
  end
37
- end
38
+ end
@@ -1,5 +1,6 @@
1
1
  module Calabash
2
2
  module Android
3
+ # @!visibility private
3
4
  module Orientation
4
5
  # @!visibility private
5
6
  def _set_orientation_landscape
@@ -1,7 +1,9 @@
1
- # @todo: Add not about this class being easily abused
2
1
  module Calabash
3
2
  module Android
3
+ # @!visibility private
4
4
  module PhysicalButtons
5
+
6
+ # @todo: Add note about this class being easily abused
5
7
  def press_button(key)
6
8
  Device.default.perform_action('press_key', key)
7
9
  true
@@ -1,4 +1,3 @@
1
- # @!visibility private
2
1
  module Calabash
3
2
  module Android
4
3
  # @!visibility private
@@ -1,5 +1,6 @@
1
1
  module Calabash
2
2
  module Android
3
+ # @!visibility private
3
4
  module Text
4
5
  def dismiss_keyboard
5
6
  Device.default.perform_action('hide_soft_keyboard')
@@ -1,22 +1,30 @@
1
1
  require 'digest'
2
2
 
3
3
  module Calabash
4
- # A representation of the application that is under test.
4
+ # A representation of an application that is under test.
5
5
  class Application
6
+ # @!visibility private
6
7
  include Calabash::Utility
7
8
 
9
+ # @!visibility private
8
10
  @@default = nil
9
11
 
12
+ # @!visibility private
10
13
  def self.default
11
14
  @@default
12
15
  end
13
16
 
17
+ # @!visibility private
14
18
  def self.default=(value)
15
19
  @@default = value
16
20
  end
17
21
 
18
22
  attr_reader :path
19
23
 
24
+ # Create an application from a path
25
+ #
26
+ # @return [Calabash::Android::Application, Calabash::IOS::Application] An
27
+ # application for `path`.
20
28
  def self.from_path(path)
21
29
  extension = File.extname(path)
22
30
 
@@ -43,28 +51,39 @@ module Calabash
43
51
  ensure_application_path
44
52
  end
45
53
 
54
+ # @!visibility private
46
55
  def to_s
47
56
  "#<Application #{path}>"
48
57
  end
49
58
 
59
+ # @!visibility private
50
60
  def inspect
51
61
  to_s
52
62
  end
53
63
 
64
+ # @!visibility private
54
65
  def extract_identifier
55
66
  abstract_method!
56
67
  end
57
68
 
69
+ # The identifier of the app. On iOS this is known as the bundle id, on
70
+ # Android this is known as the package. If the application has not been
71
+ # given an identifier in #initialize, this method will try to extract the
72
+ # identifier of the app.
73
+ #
74
+ # @return [String] The identifier if the app
58
75
  def identifier
59
76
  @identifier ||= extract_identifier
60
77
  end
61
78
 
79
+ # @!visibility private
62
80
  def md5_checksum
63
81
  Digest::MD5.file(path).hexdigest
64
82
  end
65
83
 
66
84
  private
67
85
 
86
+ # @!visibility private
68
87
  def ensure_application_path
69
88
  unless File.exist?(path)
70
89
  raise "The app '#{path}' does not exist."
@@ -47,10 +47,18 @@ module Calabash
47
47
  File.open(File.join('features', 'support', 'hooks.rb'), 'w') {|file| file.write(hooks) }
48
48
  File.open(File.join('features', 'support', 'env.rb'), 'w') {|file| file.write(env) }
49
49
 
50
- gemfile = File.read(file(File.join('Gemfile')))
50
+ gemfile = File.readlines(file(File.join('Gemfile')))
51
51
 
52
52
  unless File.exist?('Gemfile')
53
- File.open('Gemfile', 'w') {|file| file.write(gemfile) }
53
+ File.open('Gemfile', 'w') do |file|
54
+ gemfile.each do |skeleton_line|
55
+ if skeleton_line == "gem 'calabash'\n"
56
+ file.write("#{skeleton_line.strip}, '#{Calabash::VERSION}'\n")
57
+ else
58
+ file.write(skeleton_line)
59
+ end
60
+ end
61
+ end
54
62
  end
55
63
 
56
64
  gitignore = File.read(file(File.join('.gitignore')))
@@ -1,49 +1,129 @@
1
1
  require 'clipboard'
2
2
 
3
3
  module Calabash
4
+
5
+ # Methods you can use in the Calabash console to help you
6
+ # interact with your app.
7
+ # @!visibility private
4
8
  module ConsoleHelpers
5
- # Outputs all visible elements as a tree
9
+
10
+ # Outputs all visible elements as a tree.
6
11
  def tree
7
12
  ConsoleHelpers.dump(Device.default.dump)
8
13
  true
9
14
  end
10
15
 
11
- def self.save_old_readline_history
12
- file_name = IRB.conf[:HISTORY_FILE]
13
-
14
- if File.exist?(file_name)
15
- @@start_readline_history = File.readlines(file_name).map(&:chomp)
16
- end
17
- end
18
-
19
- def self.extended(base)
20
- save_old_readline_history
21
- end
22
-
16
+ # List the visible element classes.
23
17
  def classes
24
18
  query("*").map{|e| e['class']}.uniq
25
19
  end
26
20
 
21
+ # List the visible element ids.
27
22
  def ids
28
23
  query("*").map{|e| e['id']}.compact
29
24
  end
30
25
 
26
+ # Copy all the commands entered in the current console session into the OS
27
+ # Clipboard.
31
28
  def copy
32
29
  ConsoleHelpers.copy
33
30
  true
34
31
  end
35
32
 
33
+ # Clear the console.
36
34
  def clear
37
35
  ConsoleHelpers.clear
38
36
  true
39
37
  end
40
38
 
39
+ # Puts a message of the day.
40
+ def message_of_the_day
41
+ messages = [
42
+ "Let's get this done!",
43
+ 'Ready to rumble.',
44
+ 'Enjoy.',
45
+ 'Remember to breathe.',
46
+ 'Take a deep breath.',
47
+ "Isn't it time for a break?",
48
+ 'Can I get you a coffee?',
49
+ 'What is a calabash anyway?',
50
+ 'Smile! You are on camera!',
51
+ 'Let op! Wild Rooster!',
52
+ "Don't touch that button!",
53
+ "I'm gonna take this to 11.",
54
+ 'Console. Engaged.',
55
+ 'Your wish is my command.',
56
+ 'This console session was created just for you.',
57
+ 'Den som jager to harer, får ingen.',
58
+ 'Uti, non abuti.',
59
+ 'Non Satis Scire',
60
+ 'Nullius in verba',
61
+ 'Det ka æn jå væer ei jált'
62
+ ]
63
+
64
+ puts Color.green("Calabash #{Calabash::VERSION} says: '#{messages.shuffle.first}'")
65
+ end
66
+
67
+ # Turn on debug logging.
68
+ def verbose
69
+ if Calabash::Logger.log_levels.include?(:debug)
70
+ puts Color.blue('Debug logging is already turned on.')
71
+ else
72
+ Calabash::Logger.log_levels << :debug
73
+ puts Color.blue('Turned on debug logging.')
74
+ end
75
+
76
+ true
77
+ end
78
+
79
+ # Turn off debug logging.
80
+ def quiet
81
+ if Calabash::Logger.log_levels.include?(:debug)
82
+ puts Color.blue('Turned off debug logging.')
83
+ Calabash::Logger.log_levels.delete(:debug)
84
+ else
85
+ puts Color.blue('Debug logging is already turned off.')
86
+ end
87
+
88
+ true
89
+ end
90
+
91
+ # @!visibility private
92
+ def puts_console_details
93
+ puts ''
94
+ puts Color.blue('# => Useful Methods <= #')
95
+ puts Color.cyan('> ids => List all the visible ids.')
96
+ puts Color.cyan('> classes => List all the visible classes.')
97
+ puts Color.cyan("> tree => The app's visible view hierarchy.")
98
+ puts Color.cyan('> copy => Copy console commands to the Clipboard.')
99
+ puts Color.cyan('> clear => Clear the console.')
100
+ puts Color.cyan('> verbose => Turn debug logging on.')
101
+ puts Color.cyan('> quiet => Turn debug logging off.')
102
+ puts ''
103
+ end
104
+
105
+ # @!visibility private
106
+ def self.save_old_readline_history
107
+ file_name = IRB.conf[:HISTORY_FILE]
108
+
109
+ if File.exist?(file_name)
110
+ @@start_readline_history = File.readlines(file_name).map(&:chomp)
111
+ end
112
+ end
113
+
114
+ # @!visibility private
115
+ def self.extended(base)
116
+ save_old_readline_history
117
+ end
118
+
119
+ # @!visibility private
41
120
  def self.copy
42
121
  commands = filter_commands(current_console_history)
43
122
  string = commands.join($INPUT_RECORD_SEPARATOR)
44
123
  Clipboard.copy(string)
45
124
  end
46
125
 
126
+ # @!visibility private
47
127
  def self.clear
48
128
  if Gem.win_platform?
49
129
  system('cls')
@@ -54,6 +134,7 @@ module Calabash
54
134
  @@start_readline_history = readline_history
55
135
  end
56
136
 
137
+ # @!visibility private
57
138
  def self.current_console_history
58
139
  length = readline_history.length - @@start_readline_history.length
59
140
 
@@ -69,18 +150,22 @@ module Calabash
69
150
  /\s*clear_app(\(|\z)/,
70
151
  /\s*stop_app(\(|\z)/)
71
152
 
153
+ # @!visibility private
72
154
  def self.filter_commands(commands)
73
155
  commands.reject {|command| command =~ FILTER_REGEX}
74
156
  end
75
157
 
158
+ # @!visibility private
76
159
  def self.readline_history
77
160
  Readline::HISTORY.to_a
78
161
  end
79
162
 
163
+ # @!visibility private
80
164
  def self.dump(json_data)
81
165
  json_data['children'].each {|child| write_child(child)}
82
166
  end
83
167
 
168
+ # @!visibility private
84
169
  def self.write_child(data, indentation=0)
85
170
  render(data, indentation)
86
171
 
@@ -89,15 +174,18 @@ module Calabash
89
174
  end
90
175
  end
91
176
 
177
+ # @!visibility private
92
178
  def self.render(data, indentation)
93
179
  raise AbstractMethodError
94
180
  end
95
181
 
182
+ # @!visibility private
96
183
  def self.output(string, indentation)
97
184
  (indentation*2).times {print " "}
98
185
  print "#{string}"
99
186
  end
100
187
 
188
+ # @!visibility private
101
189
  def self.visible?(data)
102
190
  raise AbstractMethodError
103
191
  end
@@ -11,7 +11,7 @@ module Calabash
11
11
 
12
12
  # Set the default device.
13
13
  #
14
- # @see #Calabash::Defaults#default_device
14
+ # @see Calabash::Defaults#default_device
15
15
  def default_device=(device)
16
16
  Device.default = device
17
17
  end
@@ -28,7 +28,7 @@ module Calabash
28
28
 
29
29
  # Set the default application.
30
30
  #
31
- # @see #Calabash::Defaults.default_application
31
+ # @see Calabash::Defaults#default_application
32
32
  def default_application=(application)
33
33
  Application.default = application
34
34
  end
@@ -36,6 +36,39 @@ module Calabash
36
36
  # Get the default server. The default server is the test-server
37
37
  # of the `#default_device`.
38
38
  #
39
+ # @example
40
+ # # Setup the two apps we are going to test
41
+ # app1 = Calabash::Android::Application.new(app1_path, app1_test_server_path)
42
+ # app2 = Calabash::Android::Application.new(app2_path, app2_test_server_path)
43
+ #
44
+ # # Ensure they are installed
45
+ # ensure_app_installed(app1)
46
+ # ensure_app_installed(app2)
47
+ #
48
+ # # Set up the servers of the apps. Notice that the second app has to use a
49
+ # # different port for them to be able to run at the same time.
50
+ # app1_server = Calabash.default_server
51
+ # app2_server = Calabash::Server.new(app1_server.endpoint, app1_server.test_server_port + 1)
52
+ #
53
+ # # Start the first app
54
+ # start_app(app1)
55
+ # # Interact with the first app
56
+ # tap("something on app 1")
57
+ #
58
+ # # Start the second app
59
+ # Calabash.default_server = app2_server
60
+ # start_app(app2)
61
+ #
62
+ # # Interact with the second app
63
+ # tap("something on app 2")
64
+ #
65
+ # # Resume the first app
66
+ # Calabash.default_server = app1_server
67
+ # resume_app(app1)
68
+ #
69
+ # # Interact with the first app again
70
+ # tap("something on app 1")
71
+ #
39
72
  # @raise [RuntimeError] If default device is not set
40
73
  def default_server
41
74
  if default_device.nil?
@@ -47,7 +80,7 @@ module Calabash
47
80
 
48
81
  # Set the default server.
49
82
  #
50
- # @see #Calabash::Defaults.default_server
83
+ # @see Calabash::Defaults#default_server
51
84
  # @raise [RuntimeError] If default device is not set
52
85
  def default_server=(server)
53
86
  default_device.change_server(server)
@@ -2,17 +2,22 @@ module Calabash
2
2
  class Device
3
3
  include Utility
4
4
 
5
+ # @!visibility private
5
6
  @@default = nil
6
7
 
8
+ # @!visibility private
7
9
  def self.default
8
10
  @@default
9
11
  end
10
12
 
13
+ # @!visibility private
11
14
  def self.default=(value)
12
15
  @@default = value
13
16
  end
14
17
 
15
- attr_reader :identifier, :server, :http_client, :logger
18
+ attr_reader :identifier
19
+ # @!visibility private
20
+ attr_reader :server, :http_client, :logger
16
21
 
17
22
  # Create a new device.
18
23
  # @param [String] identifier A token that uniquely identifies the device.
@@ -20,9 +25,10 @@ module Calabash
20
25
  # `$ xcrun instruments -s devices`.
21
26
  # On Android, this is the serial of the device, emulator or simulator
22
27
  # returned by `$ adb devices`.
23
- # @param [Server] server A server object.
28
+ # @param [Calabash::Server] server A server object.
24
29
  #
25
- # @return [Device] A device.
30
+ # @return [Calabash::Device] A device.
31
+ # @!visibility public
26
32
  def initialize(identifier, server, options={})
27
33
  @identifier = identifier
28
34
  @server = server
@@ -30,12 +36,14 @@ module Calabash
30
36
  @http_client = HTTP::RetriableClient.new(server, options.fetch(:http_options, {}))
31
37
  end
32
38
 
39
+ # @!visibility private
33
40
  def change_server(new_server)
34
41
  @server = new_server
35
42
  @http_client.change_server(new_server)
36
43
  end
37
44
 
38
45
  # Start the application and the test server
46
+ # @!visibility private
39
47
  def start_app(path_or_application, options={})
40
48
  application = parse_path_or_app_parameters(path_or_application)
41
49
 
@@ -43,45 +51,53 @@ module Calabash
43
51
  end
44
52
 
45
53
  # Shutdown the application and the test server
54
+ # @!visibility private
46
55
  def stop_app
47
56
  _stop_app
48
57
  end
49
58
 
50
59
  # @see Screenshot#screenshot
60
+ # @!visibility private
51
61
  def screenshot(name=nil)
52
62
  path = Screenshot.obtain_screenshot_path!(name)
53
63
 
54
64
  _screenshot(path)
55
65
  end
56
66
 
67
+ # @!visibility private
57
68
  def install_app(path_or_application)
58
69
  application = parse_path_or_app_parameters(path_or_application)
59
70
 
60
71
  _install_app(application)
61
72
  end
62
73
 
74
+ # @!visibility private
63
75
  def ensure_app_installed(path_or_application)
64
76
  application = parse_path_or_app_parameters(path_or_application)
65
77
 
66
78
  _ensure_app_installed(application)
67
79
  end
68
80
 
81
+ # @!visibility private
69
82
  def uninstall_app(path_or_application)
70
83
  application = parse_path_or_app_parameters(path_or_application)
71
84
 
72
85
  _uninstall_app(application)
73
86
  end
74
87
 
88
+ # @!visibility private
75
89
  def clear_app_data(path_or_application)
76
90
  application = parse_path_or_app_parameters(path_or_application)
77
91
 
78
92
  _clear_app_data(application)
79
93
  end
80
94
 
95
+ # @!visibility private
81
96
  def set_location(location)
82
97
  abstract_method!
83
98
  end
84
99
 
100
+ # @!visibility private
85
101
  def dump
86
102
  request = HTTP::Request.new('/dump')
87
103
 
@@ -94,6 +110,7 @@ module Calabash
94
110
  # Ensures the test server is ready
95
111
  #
96
112
  # @raise [RuntimeError] Raises error when the server does not respond
113
+ # @!visibility private
97
114
  def ensure_test_server_ready(options={})
98
115
  begin
99
116
  Timeout.timeout(options.fetch(:timeout, 30), EnsureTestServerReadyTimeoutError) do
@@ -113,6 +130,7 @@ module Calabash
113
130
 
114
131
  # Performs a `tap` on the (first) view that matches `query`.
115
132
  # @see Calabash::Gestures#tap
133
+ # @!visibility private
116
134
  def tap(query, options={})
117
135
  Query.ensure_valid_query(query)
118
136
 
@@ -130,6 +148,7 @@ module Calabash
130
148
 
131
149
  # Performs a `double_tap` on the (first) view that matches `query`.
132
150
  # @see Calabash::Gestures#double_tap
151
+ # @!visibility private
133
152
  def double_tap(query, options={})
134
153
  Query.ensure_valid_query(query)
135
154
 
@@ -147,6 +166,7 @@ module Calabash
147
166
 
148
167
  # Performs a `long_press` on the (first) view that matches `query`.
149
168
  # @see Calabash::Gestures#long_press
169
+ # @!visibility private
150
170
  def long_press(query, options={})
151
171
  Query.ensure_valid_query(query)
152
172
 
@@ -165,6 +185,7 @@ module Calabash
165
185
 
166
186
  # Performs a `pan` on the (first) view that matches `query`.
167
187
  # @see Calabash::Gestures#pan
188
+ # @!visibility private
168
189
  def pan(query, from, to, options={})
169
190
  Query.ensure_valid_query(query)
170
191
 
@@ -179,6 +200,7 @@ module Calabash
179
200
 
180
201
  # Performs a `pan` between two elements.
181
202
  # @see Calabash::Gestures#pan_between
203
+ # @!visibility private
182
204
  def pan_between(query_from, query_to, options={})
183
205
  Query.ensure_valid_query(query_from)
184
206
  Query.ensure_valid_query(query_to)
@@ -192,6 +214,7 @@ module Calabash
192
214
 
193
215
  # Performs a `flick` on the (first) view that matches `query`.
194
216
  # @see Calabash::Gestures#flick
217
+ # @!visibility private
195
218
  def flick(query, from, to, options={})
196
219
  Query.ensure_valid_query(query)
197
220
 
@@ -205,6 +228,7 @@ module Calabash
205
228
  end
206
229
 
207
230
  # @see Calabash::Gestures#pinch
231
+ # @!visibility private
208
232
  def pinch(direction, query, options={})
209
233
  Query.ensure_valid_query(query)
210
234
 
@@ -220,6 +244,7 @@ module Calabash
220
244
 
221
245
  # Enter `text` into the currently focused view.
222
246
  # @see Calabash::Text#enter_text
247
+ # @!visibility private
223
248
  def enter_text(text)
224
249
  abstract_method!
225
250
  end