testautoa 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/Rakefile +7 -7
  2. data/bin/calabash-android +8 -1
  3. data/bin/calabash-android-build.rb +1 -1
  4. data/bin/calabash-android-console.rb +4 -4
  5. data/bin/calabash-android-run.rb +2 -10
  6. data/bin/testautoa +461 -0
  7. data/calabash-android.gemspec +3 -1
  8. data/features-skeleton/support/app_life_cycle_hooks.rb +0 -1
  9. data/irbrc +3 -1
  10. data/lib/calabash-android/helpers.rb +45 -17
  11. data/lib/calabash-android/lib/TestServer.apk +0 -0
  12. data/lib/calabash-android/lib/unsign.jar +0 -0
  13. data/lib/calabash-android/operations.rb +150 -66
  14. data/lib/calabash-android/steps/list_steps.rb +1 -1
  15. data/lib/calabash-android/steps/time_picker_steps.rb +1 -1
  16. data/lib/calabash-android/touch_helpers.rb +9 -0
  17. data/lib/calabash-android/version.rb +1 -1
  18. data/lib/calabash-android/wait_helpers.rb +93 -0
  19. data/test-server/AndroidManifest.xml +2 -0
  20. data/test-server/build.xml +1 -0
  21. data/test-server/instrumentation-backend/.classpath +0 -1
  22. data/test-server/instrumentation-backend/AndroidManifest.xml +1 -1
  23. data/test-server/instrumentation-backend/antlr/UIQuery.g +48 -5
  24. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Command.java +4 -3
  25. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/FranklyResult.java +95 -0
  26. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +7 -1
  27. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +14 -29
  28. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/FinishOpenedActivities.java +19 -0
  29. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/GetOpenedActivities.java +31 -0
  30. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/GoBackToActivity.java +67 -0
  31. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/DragCoordinates.java +28 -0
  32. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/Swipe.java +11 -5
  33. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/location/FakeGPSLocation.java +13 -10
  34. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/LeftKey.java +24 -0
  35. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/RightKey.java +24 -0
  36. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/UpKey.java +24 -0
  37. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/version/Version.java +31 -0
  38. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/CalabashChromeClient.java +131 -36
  39. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpBodyHtml.java +38 -18
  40. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpHtml.java +38 -16
  41. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/EnterTextByCssSelector.java +94 -66
  42. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteAsyncJavascript.java +55 -33
  43. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java +53 -31
  44. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptOperation.java +44 -0
  45. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/PressByCssSelector.java +52 -27
  46. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/QueryHelper.java +39 -32
  47. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ScrollTo.java +56 -41
  48. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetPropertyByCssSelector.java +50 -25
  49. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java +19 -22
  50. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/CompletedFuture.java +40 -0
  51. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/InvocationOperation.java +222 -0
  52. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Operation.java +7 -0
  53. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/PropertyOperation.java +56 -0
  54. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java +151 -43
  55. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQuery.tokens +19 -12
  56. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQueryResultVoid.java +22 -0
  57. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +41 -11
  58. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryLexer.java +1010 -242
  59. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryParser.java +406 -98
  60. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/BeginsWithRelation.java +45 -0
  61. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/ComparisonOperator.java +54 -0
  62. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/ContainsRelation.java +41 -0
  63. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/EndsWithRelation.java +42 -0
  64. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/LikeRelation.java +79 -0
  65. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/PartialFutureList.java +100 -0
  66. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryAST.java +1 -1
  67. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTClassName.java +54 -25
  68. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTPredicate.java +147 -0
  69. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTPredicateRelation.java +5 -0
  70. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +153 -89
  71. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryDirection.java +12 -2
  72. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java +58 -141
  73. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +162 -7
  74. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryVisibility.java +32 -0
  75. metadata +130 -97
  76. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/Query.java +0 -24
  77. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/Touch.java +0 -44
  78. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQuery.tokens +0 -10
  79. data/test-server/instrumentation-backend/tests/sh/calaba/instrumentationbackend/query/tests/UIQueryTest.java +0 -134
data/Rakefile CHANGED
@@ -3,18 +3,19 @@ load 'lib/calabash-android/helpers.rb'
3
3
 
4
4
  def build
5
5
  test_server_template_dir = File.join(File.dirname(__FILE__), 'test-server')
6
-
6
+
7
7
  Dir.mktmpdir do |workspace_dir|
8
-
8
+
9
9
  @test_server_dir = File.join(workspace_dir, 'test-server')
10
10
  FileUtils.cp_r(test_server_template_dir, workspace_dir)
11
-
11
+
12
12
  ant_executable = (is_windows? ? "ant.bat" : "ant")
13
13
  args = [
14
14
  ant_executable,
15
- "clean",
15
+ "clean",
16
16
  "package",
17
17
  "-Dandroid.api.level=16",
18
+ "-Dversion=#{Calabash::Android::VERSION}",
18
19
  ]
19
20
  Dir.chdir(@test_server_dir) do
20
21
  STDOUT.sync = true
@@ -28,13 +29,11 @@ def build
28
29
  end
29
30
 
30
31
  FileUtils.mkdir_p "test_servers" unless File.exist? "test_servers"
31
-
32
+
32
33
  FileUtils.cp(File.join(@test_server_dir, "bin", "Test_unsigned.apk"), File.join(File.dirname(__FILE__), 'lib/calabash-android/lib/TestServer.apk'))
33
34
  end
34
35
  end
35
36
 
36
-
37
-
38
37
  task :build do
39
38
  unless File.exists? "test-server/calabash-js/src"
40
39
  puts "calabash-js not found!"
@@ -48,4 +47,5 @@ task :build do
48
47
 
49
48
  end
50
49
 
50
+
51
51
  Bundler::GemHelper.install_tasks
data/bin/calabash-android CHANGED
@@ -1,8 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'fileutils'
4
+ require 'rbconfig'
4
5
  require 'calabash-android/helpers'
5
6
 
7
+ # for ruby 1.9.1 and earlier
8
+ unless defined? RbConfig.ruby
9
+ def RbConfig.ruby
10
+ File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"])
11
+ end
12
+ end
6
13
 
7
14
  require File.join(File.dirname(__FILE__), "calabash-android-helpers")
8
15
  require File.join(File.dirname(__FILE__), "calabash-android-generate")
@@ -62,7 +69,7 @@ elsif cmd == 'console'
62
69
  puts "No such file #{ARGV.first}"
63
70
  exit 1
64
71
  end
65
- calabash_console ARGV.first
72
+ calabash_console(relative_to_full_path(ARGV.shift))
66
73
  exit 0
67
74
  elsif cmd == 'setup'
68
75
  calabash_setup
@@ -18,7 +18,7 @@ def calabash_build(app)
18
18
  FileUtils.cp(unsigned_test_apk, "TestServer.apk")
19
19
  FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'test-server/AndroidManifest.xml'), "AndroidManifest.xml")
20
20
 
21
- unless system %Q{ruby -pi.bak -e "gsub(/#targetPackage#/, '#{package_name(app)}')" AndroidManifest.xml}
21
+ unless system %Q{"#{RbConfig.ruby}" -pi.bak -e "gsub(/#targetPackage#/, '#{package_name(app)}')" AndroidManifest.xml}
22
22
  raise "Could not replace package name in manifest"
23
23
  end
24
24
 
@@ -5,9 +5,7 @@ def calabash_console(app_path = nil)
5
5
  ENV["TEST_SERVER_PORT"] = "34777"
6
6
  end
7
7
 
8
- unless ENV["IRBRC"]
9
- ENV["IRBRC"] = File.join(File.dirname(__FILE__), '..', 'irbrc')
10
- end
8
+ ENV["IRBRC"] = File.join(File.dirname(__FILE__), '..', 'irbrc')
11
9
 
12
10
  unless ENV["PACKAGE_NAME"]
13
11
  ENV["PACKAGE_NAME"] = package_name(app_path)
@@ -25,5 +23,7 @@ def calabash_console(app_path = nil)
25
23
  ENV["TEST_APP_PATH"] = test_server_path
26
24
  end
27
25
 
28
- system "irb"
26
+ build_test_server_if_needed(app_path)
27
+
28
+ system "#{RbConfig.ruby} -S irb"
29
29
  end
@@ -13,15 +13,7 @@ def calabash_run(app_path = nil)
13
13
  end
14
14
 
15
15
  if app_path
16
- unless File.exist?(test_server_path(app_path))
17
- if ARGV.include? "--no-build"
18
- puts "No test server found for this combination of app and calabash version. Exiting!"
19
- exit 1
20
- else
21
- puts "No test server found for this combination of app and calabash version. Recreating test server."
22
- calabash_build(app_path)
23
- end
24
- end
16
+ build_test_server_if_needed(app_path)
25
17
 
26
18
  test_server_path = test_server_path(app_path)
27
19
  if ENV["TEST_SERVER_PORT"]
@@ -40,7 +32,7 @@ def calabash_run(app_path = nil)
40
32
 
41
33
  STDOUT.sync = true
42
34
  arguments = ARGV - ["--no-build"]
43
- cmd = "cucumber #{arguments.join(" ")} #{env}"
35
+ cmd = "#{RbConfig.ruby} -S cucumber #{arguments.join(" ")} #{env}"
44
36
  log cmd
45
37
  exit_code = system(cmd)
46
38
 
data/bin/testautoa ADDED
@@ -0,0 +1,461 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+ require 'json'
5
+ require 'uri'
6
+ require 'tmpdir'
7
+
8
+ def raise_if_android_home_not_set
9
+ raise "Please set the ANDROID_HOME environment variable" unless ENV["ANDROID_HOME"]
10
+ end
11
+
12
+ def print_usage
13
+ puts <<EOF
14
+ Usage: testautoa <command-name> [parameters] [options]
15
+ <command-name> can be one of
16
+ setup
17
+ Set up test automation configurations
18
+ run
19
+ Start test automation
20
+ resign
21
+ Resign the app with debug key
22
+ build
23
+ Build the test server
24
+ gen
25
+ Generate the skeleton of features directory
26
+ createavd
27
+ Create an Android Virtual Device
28
+ runavd
29
+ Start an Android Virtual Device
30
+ devices
31
+ List connected Android Devices
32
+ getbuild list
33
+ List available builds in the build drop
34
+ getbuild <Version>
35
+ Download the build with <Version>.
36
+ getbuild trunk
37
+ Download the trunk build
38
+ getscript list
39
+ List available scripts
40
+ getscript <Script>
41
+ Download the specified script
42
+ version
43
+ prints the gem version
44
+
45
+ <options> can be
46
+ -v, --verbose
47
+ Turns on verbose logging
48
+ EOF
49
+ end
50
+
51
+ def is_windows?
52
+ (RUBY_PLATFORM =~ /mswin|mingw|cygwin/)
53
+ end
54
+
55
+ def go
56
+ version = ARGV.shift
57
+ feature = ARGV.shift
58
+
59
+ features_dir = File.join(FileUtils.pwd, "features")
60
+ source_dir = File.join(File.dirname(__FILE__), '..', 'features-skeleton')
61
+ testserver_dir = File.join(FileUtils.pwd, "test_servers")
62
+
63
+ # delete feature directory
64
+ FileUtils.rm_rf(features_dir)
65
+ FileUtils.rm_rf(testserver_dir)
66
+
67
+ FileUtils.cp_r(source_dir, features_dir)
68
+ FileUtils.rm_rf(File.join(FileUtils.pwd, "features", "my_first.feature"))
69
+
70
+ cmd = "testautoa getbuild #{version}"
71
+ exit 1 if system(cmd) != true
72
+ sleep(1)
73
+
74
+ cmd = "testautoa getscript #{feature}"
75
+ exit 1 if system(cmd) != true
76
+ sleep(1)
77
+
78
+ cmd = "testautoa resign"
79
+ exit 1 if system(cmd) != true
80
+ sleep(1)
81
+
82
+ cmd = "testautoa build"
83
+ exit 1 if system(cmd) != true
84
+ sleep(1)
85
+
86
+ cmd = "testautoa run"
87
+ result = system(cmd)
88
+ sleep(1)
89
+ end
90
+
91
+ def resign
92
+ app_package = @settings["app_package"]
93
+ STDOUT.sync = true
94
+ cmd = "calabash-android resign #{app_package}"
95
+ result = system(cmd)
96
+ sleep(1)
97
+ result
98
+ end
99
+
100
+ def build
101
+ app_package = @settings["app_package"]
102
+ STDOUT.sync = true
103
+ cmd = "calabash-android build #{app_package}"
104
+ result = system(cmd)
105
+ sleep(1)
106
+ result
107
+ end
108
+
109
+ def gen
110
+ STDOUT.sync = true
111
+ cmd = "calabash-android gen"
112
+ result = system(cmd)
113
+ sleep(1)
114
+ result
115
+ end
116
+
117
+ def run(option)
118
+ app_package = @settings["app_package"].to_s.strip
119
+ test_server_port = @settings["test_server_port"].to_s.strip
120
+ serial_number = @settings["device_serialno"].to_s.strip
121
+ STDOUT.sync = true
122
+ arguments = ARGV
123
+ cmd = "calabash-android #{option} #{app_package} #{arguments.join(" ")}"
124
+ env = {}
125
+ if test_server_port != ''
126
+ env["TEST_SERVER_PORT"] = test_server_port
127
+ end
128
+ if serial_number != ''
129
+ env["ADB_DEVICE_ARG"] = serial_number
130
+ end
131
+ result = system(env, cmd)
132
+ sleep(1)
133
+ result
134
+ end
135
+
136
+ def setup
137
+ read_settings
138
+ puts "Settings for Test Automation"
139
+
140
+ ask_for_setting(:svn_location, "Please enter svn location", @settings["svn_location"])
141
+ ask_for_setting(:svn_username, "Please enter svn username", @settings["svn_username"])
142
+ ask_for_setting(:svn_password, "Please enter svn password", @settings["svn_password"])
143
+
144
+ ask_for_setting(:build_drop_location, "Please enter build drop location", @settings["build_drop_location"])
145
+ ask_for_setting(:build_drop_username, "Please enter the username", @settings["build_drop_username"])
146
+ ask_for_setting(:build_drop_password, "Please enter the password", @settings["build_drop_password"])
147
+
148
+ ask_for_setting(:app_package, "Please enter the name of app package", @settings["app_package"])
149
+ ask_for_setting(:device_serialno, "Please enter the serial number of the device", @settings["device_serialno"])
150
+ ask_for_setting(:test_server_port, "Please enter the test server port", @settings["test_server_port"] ||= "34777")
151
+
152
+ ask_for_setting(:avd_name, "Please enter the name of Android emulator", @settings["avd_name"] ||= "testauto_avd")
153
+ puts "Available Targets:"
154
+ get_target_names.each{|i| puts "* #{i}" }
155
+ ask_for_setting(:avd_target, "Please enter the target of Android emulator", @settings["avd_target"] ||= "android-16")
156
+ puts "Available CPUs:"
157
+ get_abis(@settings["avd_target"]).each{|i| puts "* #{i}"}
158
+ ask_for_setting(:avd_cpu, "Please enter the CPU of Android emulator", @settings["avd_cpu"] ||= "armeabi-v7a")
159
+ ask_for_setting(:avd_sdcard_size, "Please enter the SD card size of Android emulator", @settings["avd_sdcard_size"] ||= "64M")
160
+ ask_for_setting(:avd_ram_size, "Please enter the RAM size of Android emulator", @settings["avd_ram_size"] ||= "1024")
161
+ @settings[:build_drop_branch_dir] = "Mobile/Android/branch"
162
+ @settings[:build_drop_trunk_dir] = "Mobile/Android/trunk"
163
+
164
+ open('.testautoa_settings', 'w') do |f|
165
+ f.puts @settings.to_json
166
+ end
167
+ puts "Saved your settings to .testautoa_settings. You can edit the settings manually or run this setup script again"
168
+ end
169
+
170
+ def ask_for_setting(key, msg, def_value)
171
+ puts (def_value == "" ? msg : "#{msg} (#{def_value})")
172
+ input = STDIN.gets.chomp
173
+ if input.empty?
174
+ @settings[key] = def_value
175
+ elsif input.strip.empty?
176
+ @settings[key] = ''
177
+ else
178
+ @settings[key] = input
179
+ end
180
+ end
181
+
182
+ def read_settings
183
+ if File.exist? ".testautoa_settings"
184
+ @settings = JSON.parse(IO.read(".testautoa_settings"))
185
+ else
186
+ @settings = {}
187
+ end
188
+ end
189
+
190
+ def smb_connect_win(location,username,password)
191
+ mount_node = location.tr('/', '\\')
192
+ username = username.tr('/', '\\')
193
+
194
+ cmd = "net use"
195
+ output=`#{cmd}` ; result=$?.success?
196
+
197
+ if output.include?(mount_node)
198
+ cmd = "net use #{mount_node} /delete"
199
+ output=`#{cmd}` ; result=$?.success?
200
+ end
201
+
202
+ cmd = "net use #{mount_node} #{password} /user:#{username}"
203
+ output=`#{cmd}` ; result=$?.success?
204
+ raise "the command '#{cmd}' failed" if result == false
205
+
206
+ mount_node
207
+ end
208
+
209
+ def smb_disconnect_win(mount_node)
210
+ cmd = "net use #{mount_node} /delete"
211
+ output=`#{cmd}` ; result=$?.success?
212
+ end
213
+
214
+ def smb_connect_mac(location,username,password)
215
+ # create mount node
216
+ mount_node = "/Volumes/build_drop_temp"
217
+ if File.exists?(mount_node)
218
+ cmd = "umount #{mount_node}"
219
+ output=`#{cmd}` ; result=$?.success?
220
+ FileUtils.rm_rf(mount_node) if result == false
221
+ end
222
+ cmd = "mkdir #{mount_node}"
223
+ output=`#{cmd}` ; result=$?.success?
224
+ raise "the command '#{cmd}' failed" if result == false
225
+
226
+ # mount smbfs
227
+ location = location.tr('\\','/')
228
+ username = username.tr('\\',';').tr('/',';')
229
+ raise "The build drop location is incorrect" if not location.start_with?("//")
230
+ cmd = "mount -t smbfs //'#{username}':#{password}@#{location[2..-1]} #{mount_node}"
231
+ output=`#{cmd}` ; result=$?.success?
232
+ raise "the command '#{cmd}' failed" if result == false
233
+ mount_node
234
+ end
235
+
236
+ def smb_disconnect_mac(mount_node)
237
+ # unmount fs
238
+ cmd = "umount -f #{mount_node}"
239
+ output=`#{cmd}` ; result=$?.success?
240
+ raise "the command '#{cmd}' failed" if result == false
241
+ end
242
+
243
+ def smb_connect(location,username,password)
244
+ if is_windows?
245
+ smb_connect_win(location,username,password)
246
+ else
247
+ smb_connect_mac(location,username,password)
248
+ end
249
+ end
250
+
251
+ def smb_disconnect(mount_node)
252
+ if is_windows?
253
+ smb_disconnect_win(mount_node)
254
+ else
255
+ smb_disconnect_mac(mount_node)
256
+ end
257
+ end
258
+
259
+ def get_build
260
+ mount_node = smb_connect(@settings["build_drop_location"],
261
+ @settings["build_drop_username"],
262
+ @settings["build_drop_password"])
263
+ if ARGV.first == 'list'
264
+ # list build versions
265
+ branch_path = File.join(mount_node, @settings["build_drop_branch_dir"])
266
+ Dir.entries(branch_path).sort_by{|c| File.stat(File.join(branch_path,c)).ctime}.each do |d|
267
+ m = d.match(/^Android(\S+)$/)
268
+ if m != nil
269
+ puts m[1]
270
+ end
271
+ end
272
+ else
273
+ if ARGV.first == 'trunk'
274
+ # copy the trunk build
275
+ release_path = File.join(mount_node, @settings["build_drop_trunk_dir"])
276
+ else
277
+ # copy the version build
278
+ release_path = File.join(mount_node, @settings["build_drop_branch_dir"], "Android#{ARGV.first}/Release")
279
+ end
280
+ build_dir = Dir.entries(release_path).sort_by{|c| File.stat(File.join(release_path,c)).ctime}.last
281
+ apk_file = "ConcurMobile.apk"
282
+ source = File.join(release_path, build_dir, apk_file)
283
+ raise "the file '#{source}' does not exist" if not File.exists?(source)
284
+ FileUtils.copy(source, File.join(FileUtils.pwd, apk_file))
285
+ puts "Copy the build from #{source}"
286
+ end
287
+
288
+ smb_disconnect(mount_node)
289
+ end
290
+
291
+ def get_script
292
+ username = @settings["svn_username"]
293
+ password = @settings["svn_password"]
294
+ uri = URI.join(@settings["svn_location"], "Mobile/", "BVT/", "CTE/")
295
+
296
+ if ARGV.first == 'list'
297
+ puts `svn list #{uri} --username #{username} --password #{password}`
298
+ else
299
+ feature = ARGV.first + (ARGV.first.end_with?('/')? '' : '/')
300
+ uri = URI.join(uri, feature)
301
+ puts `svn export --force #{uri} features --username #{username} --password #{password}`
302
+
303
+ #uri = URI.join(@settings["svn_location"], "_support/", "support/")
304
+ #puts `svn export --force #{uri} features/support --username #{username} --password #{password}`
305
+ uri = URI.join(@settings["svn_location"], "_support/", "step_definition/")
306
+ puts `svn export --force #{uri} features/step_definitions --username #{username} --password #{password}`
307
+ end
308
+ end
309
+
310
+ def adb_path
311
+ raise_if_android_home_not_set
312
+ File.join(ENV['ANDROID_HOME'], 'platform-tools', 'adb')
313
+ end
314
+
315
+ def android_path
316
+ raise_if_android_home_not_set
317
+ File.join(ENV['ANDROID_HOME'], 'tools', 'android')
318
+ end
319
+
320
+ def emulator_path
321
+ raise_if_android_home_not_set
322
+ File.join(ENV['ANDROID_HOME'], 'tools', 'emulator')
323
+ end
324
+
325
+ def list_devices
326
+ `#{adb_path} devices`.scan(/^(\S*)\s*device$/).each { |i| puts i[0] }
327
+ end
328
+
329
+ def get_target_names
330
+ targets = `#{android_path} list target`.scan(/^id: (\d*) or "([^\"]*)"$/)
331
+ targets.collect{|i| i[1]}
332
+ end
333
+
334
+ def get_abis(target)
335
+ `#{android_path} list target`.scan(/^id: (\d+) or "#{target}"(?:(?:.*[\r\n]*)\s{5}.*)*ABIs : (.*)$/)[0][1].split(/[\s,]+/)
336
+ end
337
+
338
+ def list_target
339
+ puts `#{android_path} list target`
340
+ end
341
+
342
+ def list_avd
343
+ puts `#{android_path} list avd`
344
+ end
345
+
346
+ def create_avd
347
+ android_targets = get_target_names.find_all{ |t| t =~ /android-(\d*)/ }
348
+ google_targets = get_target_names.find_all{ |t| t =~ /Google Inc.:Google APIs:(\d*)/ }
349
+
350
+ name = @settings["avd_name"]
351
+ target = @settings["avd_target"]
352
+ cpu = @settings["avd_cpu"]
353
+ sdcard_size = @settings["avd_sdcard_size"]
354
+ ram_size = @settings["avd_ram_size"]
355
+
356
+ # validate settings
357
+ raise "the target '#{target}' does not exist" if not get_target_names.include?(target)
358
+
359
+ #create avd
360
+ result = `echo no | \"#{android_path}\" create avd -f -n #{name} -t #{target} -c #{sdcard_size} -b #{cpu}`.include? "Created AVD '#{name}' based on Android"
361
+ raise "Creating AVD Failed" if result == false
362
+ config_ini = File.join(File.expand_path("~"), ".android", 'avd', "#{name}.avd", "config.ini")
363
+ config_bak = File.join(File.expand_path("~"), ".android", 'avd', "#{name}.avd", "config.bak")
364
+ File.open(config_ini, 'r') do |f_ini|
365
+ File.open(config_bak, 'w') do |f_bak|
366
+ while line = f_ini.gets
367
+ match = line.match(/^hw.ramSize=(\d+)$/)
368
+ f_bak.puts(match != nil ? "hw.ramSize=#{ram_size}" : line)
369
+ end
370
+ end
371
+ end
372
+ File.delete(config_ini)
373
+ File.rename(config_bak, config_ini)
374
+ end
375
+
376
+ def run_avd
377
+ avds = `#{android_path} list avd`.scan(/^\s*Name: (.*)$/).collect{|i| i[0]}
378
+ avd_name = @settings["avd_name"]
379
+ if avds.include?(avd_name)
380
+ pid = spawn("#{emulator_path} -avd #{avd_name}")
381
+ else
382
+ puts "The AVD '#{avd_name}' does not exist"
383
+ end
384
+ end
385
+
386
+ if (ARGV.length == 0)
387
+ print_usage
388
+ exit 0
389
+ end
390
+
391
+ cmd = ARGV.shift
392
+
393
+ if cmd == 'help'
394
+ print_usage
395
+ exit 0
396
+
397
+ elsif cmd == 'setup'
398
+ setup
399
+ exit 0
400
+
401
+ elsif cmd == 'getbuild'
402
+ read_settings
403
+ File.open("#{Dir.tmpdir}/testauto.lock", 'w') { |f|
404
+ f.flock(File::LOCK_EX)
405
+ get_build
406
+ }
407
+ exit 0
408
+
409
+ elsif cmd == 'getscript'
410
+ read_settings
411
+ get_script
412
+ exit 0
413
+
414
+ elsif cmd == 'devices'
415
+ list_devices
416
+ exit 0
417
+
418
+ elsif cmd == 'list'
419
+ option = ARGV.shift
420
+ if option == 'target'
421
+ list_target
422
+ elsif option == 'avd'
423
+ list_avd
424
+ end
425
+ exit 0
426
+
427
+ elsif cmd == 'createavd'
428
+ read_settings
429
+ create_avd
430
+ exit 0
431
+
432
+ elsif cmd == 'runavd'
433
+ read_settings
434
+ run_avd
435
+ exit 0
436
+
437
+ elsif cmd == 'run' or cmd == 'console'
438
+ read_settings
439
+ run(cmd)
440
+
441
+ elsif cmd == 'resign'
442
+ read_settings
443
+ resign
444
+
445
+ elsif cmd == 'build'
446
+ read_settings
447
+ build
448
+
449
+ elsif cmd == 'gen'
450
+ gen
451
+
452
+ elsif cmd == 'go'
453
+ go
454
+
455
+ elsif cmd == 'version'
456
+ puts Calabash::Android::VERSION
457
+ exit 0
458
+
459
+ else
460
+ print_usage
461
+ end
@@ -12,7 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Client for calabash-android for automated functional testing on Android}
13
13
  s.description = %q{calabash-android drives tests for native and hybrid Android apps. }
14
14
  s.files = `git ls-files`.split("\n") + Dir["test-server/calabash-js/src/*.js"] + ["lib/calabash-android/lib/TestServer.apk"]
15
- s.executables = "calabash-android"
15
+ s.executables = ["calabash-android","testautoa"]
16
+ s.default_executable = "calabash-android"
16
17
  s.require_paths = ["lib"]
17
18
 
18
19
  s.add_dependency( "cucumber" )
@@ -20,5 +21,6 @@ Gem::Specification.new do |s|
20
21
  s.add_dependency( "retriable" )
21
22
  s.add_dependency( "slowhandcuke" )
22
23
  s.add_dependency( "rubyzip" )
24
+ s.add_dependency( "awesome_print" )
23
25
 
24
26
  end
@@ -1,6 +1,5 @@
1
1
  require 'calabash-android/management/adb'
2
2
  require 'calabash-android/operations'
3
- include Calabash::Android::Operations
4
3
 
5
4
  Before do |scenario|
6
5
  start_test_server_in_background
data/irbrc CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'irb/completion'
3
3
  require 'irb/ext/save-history'
4
+ require 'awesome_print'
5
+ AwesomePrint.irb!
4
6
 
5
7
  ARGV.concat [ "--readline",
6
8
  "--prompt-mode",
@@ -13,7 +15,7 @@ IRB.conf[:SAVE_HISTORY] = 50
13
15
  IRB.conf[:HISTORY_FILE] = ".irb-history"
14
16
 
15
17
  require 'calabash-android/operations'
16
- include Calabash::Android::Operations
18
+ extend Calabash::Android::Operations
17
19
 
18
20
  def embed(*args)
19
21
  puts "Embed is a Cucumber method and is not available in this console."