testautoa 0.4.0.pre19 → 0.4.0

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 (76) hide show
  1. data/Rakefile +7 -7
  2. data/bin/calabash-android +1 -8
  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 +10 -2
  6. data/calabash-android.gemspec +0 -1
  7. data/irbrc +0 -2
  8. data/lib/calabash-android/helpers.rb +17 -45
  9. data/lib/calabash-android/lib/TestServer.apk +0 -0
  10. data/lib/calabash-android/operations.rb +43 -144
  11. data/lib/calabash-android/steps/list_steps.rb +1 -1
  12. data/lib/calabash-android/steps/time_picker_steps.rb +1 -1
  13. data/lib/calabash-android/version.rb +1 -1
  14. data/test-server/AndroidManifest.xml +0 -2
  15. data/test-server/build.xml +0 -1
  16. data/test-server/instrumentation-backend/.classpath +1 -0
  17. data/test-server/instrumentation-backend/AndroidManifest.xml +1 -1
  18. data/test-server/instrumentation-backend/antlr/UIQuery.g +5 -48
  19. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Command.java +3 -4
  20. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +1 -7
  21. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +29 -14
  22. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/Swipe.java +5 -11
  23. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/location/FakeGPSLocation.java +10 -13
  24. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/CalabashChromeClient.java +36 -131
  25. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpBodyHtml.java +18 -38
  26. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpHtml.java +16 -38
  27. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/EnterTextByCssSelector.java +66 -94
  28. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteAsyncJavascript.java +33 -55
  29. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java +31 -53
  30. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/PressByCssSelector.java +27 -52
  31. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/Query.java +24 -0
  32. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/QueryHelper.java +32 -39
  33. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ScrollTo.java +41 -56
  34. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetPropertyByCssSelector.java +25 -50
  35. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java +22 -19
  36. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/Touch.java +44 -0
  37. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java +43 -155
  38. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQuery.tokens +12 -19
  39. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +11 -41
  40. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQuery.tokens +10 -0
  41. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryLexer.java +242 -1010
  42. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryParser.java +98 -406
  43. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryAST.java +1 -1
  44. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTClassName.java +25 -52
  45. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +89 -153
  46. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryDirection.java +2 -12
  47. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java +141 -58
  48. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +7 -157
  49. data/test-server/instrumentation-backend/tests/sh/calaba/instrumentationbackend/query/tests/UIQueryTest.java +134 -0
  50. metadata +98 -128
  51. data/lib/calabash-android/lib/unsign.jar +0 -0
  52. data/lib/calabash-android/wait_helpers.rb +0 -93
  53. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/FranklyResult.java +0 -95
  54. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/FinishOpenedActivities.java +0 -19
  55. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/GetOpenedActivities.java +0 -31
  56. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/GoBackToActivity.java +0 -67
  57. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/DragCoordinates.java +0 -28
  58. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/LeftKey.java +0 -24
  59. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/RightKey.java +0 -24
  60. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/UpKey.java +0 -24
  61. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/version/Version.java +0 -31
  62. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptOperation.java +0 -44
  63. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/CompletedFuture.java +0 -40
  64. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/InvocationOperation.java +0 -222
  65. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Operation.java +0 -7
  66. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/PropertyOperation.java +0 -56
  67. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQueryResultVoid.java +0 -22
  68. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/BeginsWithRelation.java +0 -45
  69. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/ComparisonOperator.java +0 -54
  70. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/ContainsRelation.java +0 -41
  71. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/EndsWithRelation.java +0 -42
  72. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/LikeRelation.java +0 -79
  73. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/PartialFutureList.java +0 -100
  74. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTPredicate.java +0 -147
  75. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTPredicateRelation.java +0 -5
  76. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryVisibility.java +0 -32
data/Rakefile CHANGED
@@ -3,19 +3,18 @@ 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}",
19
18
  ]
20
19
  Dir.chdir(@test_server_dir) do
21
20
  STDOUT.sync = true
@@ -29,11 +28,13 @@ def build
29
28
  end
30
29
 
31
30
  FileUtils.mkdir_p "test_servers" unless File.exist? "test_servers"
32
-
31
+
33
32
  FileUtils.cp(File.join(@test_server_dir, "bin", "Test_unsigned.apk"), File.join(File.dirname(__FILE__), 'lib/calabash-android/lib/TestServer.apk'))
34
33
  end
35
34
  end
36
35
 
36
+
37
+
37
38
  task :build do
38
39
  unless File.exists? "test-server/calabash-js/src"
39
40
  puts "calabash-js not found!"
@@ -47,5 +48,4 @@ task :build do
47
48
 
48
49
  end
49
50
 
50
-
51
51
  Bundler::GemHelper.install_tasks
data/bin/calabash-android CHANGED
@@ -1,15 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'fileutils'
4
- require 'rbconfig'
5
4
  require 'calabash-android/helpers'
6
5
 
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
13
6
 
14
7
  require File.join(File.dirname(__FILE__), "calabash-android-helpers")
15
8
  require File.join(File.dirname(__FILE__), "calabash-android-generate")
@@ -69,7 +62,7 @@ elsif cmd == 'console'
69
62
  puts "No such file #{ARGV.first}"
70
63
  exit 1
71
64
  end
72
- calabash_console(relative_to_full_path(ARGV.shift))
65
+ calabash_console ARGV.first
73
66
  exit 0
74
67
  elsif cmd == 'setup'
75
68
  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{"#{RbConfig.ruby}" -pi.bak -e "gsub(/#targetPackage#/, '#{package_name(app)}')" AndroidManifest.xml}
21
+ unless system %Q{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,7 +5,9 @@ def calabash_console(app_path = nil)
5
5
  ENV["TEST_SERVER_PORT"] = "34777"
6
6
  end
7
7
 
8
- ENV["IRBRC"] = File.join(File.dirname(__FILE__), '..', 'irbrc')
8
+ unless ENV["IRBRC"]
9
+ ENV["IRBRC"] = File.join(File.dirname(__FILE__), '..', 'irbrc')
10
+ end
9
11
 
10
12
  unless ENV["PACKAGE_NAME"]
11
13
  ENV["PACKAGE_NAME"] = package_name(app_path)
@@ -23,7 +25,5 @@ def calabash_console(app_path = nil)
23
25
  ENV["TEST_APP_PATH"] = test_server_path
24
26
  end
25
27
 
26
- build_test_server_if_needed(app_path)
27
-
28
- system "#{RbConfig.ruby} -S irb"
28
+ system "irb"
29
29
  end
@@ -13,7 +13,15 @@ def calabash_run(app_path = nil)
13
13
  end
14
14
 
15
15
  if app_path
16
- build_test_server_if_needed(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
17
25
 
18
26
  test_server_path = test_server_path(app_path)
19
27
  if ENV["TEST_SERVER_PORT"]
@@ -32,7 +40,7 @@ def calabash_run(app_path = nil)
32
40
 
33
41
  STDOUT.sync = true
34
42
  arguments = ARGV - ["--no-build"]
35
- cmd = "#{RbConfig.ruby} -S cucumber #{arguments.join(" ")} #{env}"
43
+ cmd = "cucumber #{arguments.join(" ")} #{env}"
36
44
  log cmd
37
45
  exit_code = system(cmd)
38
46
 
@@ -20,6 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency( "retriable" )
21
21
  s.add_dependency( "slowhandcuke" )
22
22
  s.add_dependency( "rubyzip" )
23
- s.add_dependency( "awesome_print" )
24
23
 
25
24
  end
data/irbrc CHANGED
@@ -1,8 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'irb/completion'
3
3
  require 'irb/ext/save-history'
4
- require 'awesome_print'
5
- AwesomePrint.irb!
6
4
 
7
5
  ARGV.concat [ "--readline",
8
6
  "--prompt-mode",
@@ -38,27 +38,22 @@ def test_server_path(apk_file_path)
38
38
  "test_servers/#{checksum(apk_file_path)}_#{Calabash::Android::VERSION}.apk"
39
39
  end
40
40
 
41
-
42
- def build_test_server_if_needed(app_path)
43
- unless File.exist?(test_server_path(app_path))
44
- if ARGV.include? "--no-build"
45
- puts "No test server found for this combination of app and calabash version. Exiting!"
46
- exit 1
47
- else
48
- puts "No test server found for this combination of app and calabash version. Recreating test server."
49
- calabash_build(app_path)
50
- end
51
- end
52
- end
53
-
54
41
  def resign_apk(app_path)
55
42
  Dir.mktmpdir do |tmp_dir|
56
43
  log "Resign apk"
57
44
  unsigned_path = File.join(tmp_dir, 'unsigned.apk')
58
45
  FileUtils.cp(app_path, unsigned_path)
59
46
 
60
- `java -jar "#{File.dirname(__FILE__)}/lib/unsign.jar" "#{unsigned_path}"`
47
+ #Delete META-INF/*
48
+ to_remove = Zip::ZipFile.foreach(unsigned_path).find_all { |e| /^META-INF\// =~ e.name}.collect &:name
61
49
 
50
+ Zip::ZipFile.open(unsigned_path) do |zip_file|
51
+ to_remove.each do |x|
52
+ log "Removing #{x}"
53
+ zip_file.remove x
54
+ end
55
+ zip_file.commit
56
+ end
62
57
  sign_apk(unsigned_path, app_path)
63
58
  end
64
59
  end
@@ -72,7 +67,7 @@ def sign_apk(app_path, dest_path)
72
67
  jarsigner_path = "jarsigner"
73
68
  end
74
69
 
75
- cmd = "#{jarsigner_path} -sigalg MD5withRSA -digestalg SHA1 -signedjar #{dest_path} -storepass #{keystore["keystore_password"]} -keystore #{keystore["keystore_location"]} #{app_path} #{keystore["keystore_alias"]}"
70
+ cmd = "#{jarsigner_path} -sigalg MD5withRSA -digestalg SHA1 -signedjar #{dest_path} -storepass #{keystore["keystore_password"]} -keystore \"#{File.expand_path keystore["keystore_location"]}\" #{app_path} #{keystore["keystore_alias"]}"
76
71
  log cmd
77
72
  unless system(cmd)
78
73
  puts "jarsigner command: #{cmd}"
@@ -82,32 +77,19 @@ end
82
77
 
83
78
  def read_keystore_info
84
79
  if File.exist? ".calabash_settings"
85
- keystore = JSON.parse(IO.read(".calabash_settings"))
86
- keystore["keystore_location"] = '"' + File.expand_path(keystore["keystore_location"]) + '"' if keystore["keystore_location"]
87
- keystore
80
+ JSON.parse(IO.read(".calabash_settings"))
88
81
  else
89
82
  {
90
- "keystore_location" => %Q("#{File.expand_path(File.join(ENV["HOME"], "/.android/debug.keystore"))}\"),
83
+ "keystore_location" => "#{ENV["HOME"]}/.android/debug.keystore",
91
84
  "keystore_password" => "android",
92
85
  "keystore_alias" => "androiddebugkey",
93
86
  }
94
87
  end
95
88
  end
96
89
 
97
- def keytool_path
98
- if is_windows?
99
- "\"#{ENV["JAVA_HOME"]}/bin/keytool.exe\""
100
- else
101
- "keytool"
102
- end
103
- end
104
-
105
90
  def fingerprint_from_keystore
106
91
  keystore_info = read_keystore_info
107
- cmd = "#{keytool_path} -v -list -alias #{keystore_info["keystore_alias"]} -keystore \"#{keystore_info["keystore_location"]}\" -storepass #{keystore_info["keystore_password"]}"
108
-
109
- log cmd
110
- fingerprints = `#{cmd}`
92
+ fingerprints = `keytool -v -list -alias #{keystore_info["keystore_alias"]} -keystore #{keystore_info["keystore_location"]} -storepass #{keystore_info["keystore_password"]}`
111
93
  md5_fingerprint = extract_md5_fingerprint(fingerprints)
112
94
  log "MD5 fingerprint for keystore (#{keystore_info["keystore_location"]}): #{md5_fingerprint}"
113
95
  md5_fingerprint
@@ -125,9 +107,7 @@ def fingerprint_from_apk(app_path)
125
107
  raise "No RSA file found in META-INF. Cannot proceed." if rsa_files.empty?
126
108
  raise "More than one RSA file found in META-INF. Cannot proceed." if rsa_files.length > 1
127
109
 
128
- cmd = "#{keytool_path} -v -printcert -file #{rsa_files.first}"
129
- log cmd
130
- fingerprints = `#{cmd}`
110
+ fingerprints = `keytool -v -printcert -file #{rsa_files.first}`
131
111
  md5_fingerprint = extract_md5_fingerprint(fingerprints)
132
112
  log "MD5 fingerprint for signing cert (#{app_path}): #{md5_fingerprint}"
133
113
  md5_fingerprint
@@ -136,17 +116,9 @@ def fingerprint_from_apk(app_path)
136
116
  end
137
117
 
138
118
  def extract_md5_fingerprint(fingerprints)
139
- log fingerprints
140
-
141
- if is_windows?
142
- if fingerprints.encoding.name == "CP850"
143
- fingerprints = fingerprints.gsub("\xA0".force_encoding("CP850"),"")
144
- end
145
- end
146
-
147
- m = fingerprints.scan(/MD5\s*:\s*((?:[a-fA-F\d]{2}:){15}[a-fA-F\d]{2})/).flatten
148
- raise "No MD5 fingerprint found:\n #{fingerprints}" if m.empty?
149
- m.first
119
+ m = fingerprints.scan(/MD5:\s+((?:[[:xdigit:]][[:xdigit:]]:){15}[[:xdigit:]][[:xdigit:]])/)
120
+ raise "No MD5 fingerprint found:\n #{fingerprints}" unless m
121
+ m.last.first
150
122
  end
151
123
 
152
124
  def is_windows?
@@ -6,16 +6,13 @@ require 'json'
6
6
  require 'socket'
7
7
  require 'timeout'
8
8
  require 'calabash-android/helpers'
9
- require 'calabash-android/wait_helpers'
10
- require 'calabash-android/version'
11
9
  require 'retriable'
12
- require 'cucumber'
13
10
 
14
11
 
15
12
  module Calabash module Android
16
13
 
17
14
  module Operations
18
- include Calabash::Android::WaitHelpers
15
+
19
16
 
20
17
  def log(message)
21
18
  $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose")
@@ -26,13 +23,12 @@ module Operations
26
23
  end
27
24
 
28
25
  def macro(txt)
29
- if self.respond_to?(:step)
26
+ if self.respond_to?:step
30
27
  step(txt)
31
28
  else
32
29
  Then(txt)
33
30
  end
34
31
  end
35
-
36
32
  def default_device
37
33
  unless @default_device
38
34
  @default_device = Device.new(self, ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
@@ -40,22 +36,10 @@ module Operations
40
36
  @default_device
41
37
  end
42
38
 
43
- def set_default_device(device)
44
- @default_device = device
45
- end
46
-
47
39
  def performAction(action, *arguments)
48
40
  default_device.perform_action(action, *arguments)
49
41
  end
50
42
 
51
- def reinstall_apps
52
- default_device.reinstall_apps
53
- end
54
-
55
- def reinstall_test_server
56
- default_device.reinstall_test_server
57
- end
58
-
59
43
  def install_app(app_path)
60
44
  default_device.install_app(app_path)
61
45
  end
@@ -73,7 +57,7 @@ module Operations
73
57
  default_device.clear_app_data
74
58
  end
75
59
 
76
- def start_test_server_in_background(options={})
60
+ def start_test_server_in_background
77
61
  default_device.start_test_server_in_background()
78
62
  end
79
63
 
@@ -98,49 +82,32 @@ module Operations
98
82
  default_device.set_gps_coordinates(latitude, longitude)
99
83
  end
100
84
 
101
- def press_back_key
102
- default_device.press_back_key
103
- end
104
-
105
- #def wait_for(timeout, &block)
106
- # value = nil
107
- # begin
108
- # Timeout::timeout(timeout) do
109
- # until (value = block.call)
110
- # sleep 0.3
111
- # end
112
- # end
113
- # rescue Exception => e
114
- # raise e
115
- # end
116
- # value
117
- #end
85
+ def wait_for(timeout, &block)
86
+ begin
87
+ Timeout::timeout(timeout) do
88
+ until block.call
89
+ sleep 0.3
90
+ end
91
+ end
92
+ rescue Exception => e
93
+ raise e
94
+ end
95
+ end
118
96
 
119
97
  def query(uiquery, *args)
120
- converted_args = []
121
- args.each do |arg|
122
- if arg.is_a?(Hash) and arg.count == 1
123
- converted_args << {:method_name => arg.keys.first, :arguments => [ arg.values.first ]}
98
+ if uiquery.start_with? "webView"
99
+ uiquery.slice!(0, "webView".length)
100
+ if uiquery =~ /(css|xpath):\s*(.*)/
101
+ r = performAction("query", $1, $2)
102
+ JSON.parse(r["message"])
124
103
  else
125
- converted_args << arg
104
+ raise "Invalid query #{uiquery}"
126
105
  end
127
- end
128
- map(uiquery,:query,*converted_args)
129
- end
130
-
131
- def each_item(opts={:query => "android.widget.ListView", :post_scroll => 0.2}, &block)
132
- uiquery = opts[:query] || "android.widget.ListView"
133
- skip_if = opts[:skip_if] || lambda { |i| false }
134
- stop_when = opts[:stop_when] || lambda { |i| false }
135
- check_element_exists(uiquery)
136
- num_items = query(opts[:query], :adapter, :count).first
137
- num_items.times do |item|
138
- next if skip_if.call(item)
139
- break if stop_when.call(item)
140
-
141
- scroll_to_row(opts[:query], item)
142
- sleep(opts[:post_scroll]) if opts[:post_scroll] and opts[:post_scroll] > 0
143
- yield(item)
106
+ else
107
+ arguments = [*args]
108
+ operation = {"method_name"=>"query", "arguments" => arguments}
109
+ data = {"query" => uiquery, "operation" => operation}
110
+ JSON.parse(http("/map",data))
144
111
  end
145
112
  end
146
113
 
@@ -165,6 +132,10 @@ module Operations
165
132
 
166
133
  class Device
167
134
 
135
+ def make_default_device
136
+ @cucumber_world.default_device = self
137
+ end
138
+
168
139
  def initialize(cucumber_world, serial, server_port, app_path, test_server_path)
169
140
  @cucumber_world = cucumber_world
170
141
  @serial = serial
@@ -180,10 +151,6 @@ module Operations
180
151
  def reinstall_apps()
181
152
  uninstall_app(package_name(@app_path))
182
153
  install_app(@app_path)
183
- reinstall_test_server()
184
- end
185
-
186
- def reinstall_test_server()
187
154
  uninstall_app(package_name(@test_server_path))
188
155
  install_app(@test_server_path)
189
156
  end
@@ -197,7 +164,7 @@ module Operations
197
164
  succeeded = `#{adb_command} shell pm list packages`.include?("package:#{pn}")
198
165
 
199
166
  unless succeeded
200
- ::Cucumber.wants_to_quit = true
167
+ Cucumber.wants_to_quit = true
201
168
  raise "#{pn} did not get installed. Aborting!"
202
169
  end
203
170
  end
@@ -344,30 +311,14 @@ module Operations
344
311
  raise "Could not clear data" unless system(cmd)
345
312
  end
346
313
 
347
- def start_test_server_in_background(options={})
348
- raise "Will not start test server because of previous failures." if ::Cucumber.wants_to_quit
314
+ def start_test_server_in_background
315
+ raise "Will not start test server because of previous failures." if Cucumber.wants_to_quit
349
316
 
350
317
  if keyguard_enabled?
351
318
  wake_up
352
319
  end
353
320
 
354
- env_options = {:target_package => options[:target_package] || package_name(@app_path),
355
- :main_activity => options[:main_activity] || main_activity(@app_path),
356
- :debug => options[:debug] || false,
357
- :class => options[:class] || "sh.calaba.instrumentationbackend.InstrumentationBackend"}
358
-
359
- cmd_arr = [adb_command, "shell am instrument"]
360
-
361
- env_options.each_pair do |key, val|
362
- cmd_arr << "-e"
363
- cmd_arr << key.to_s
364
- cmd_arr << val.to_s
365
- end
366
-
367
- cmd_arr << "sh.calaba.android.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner"
368
-
369
- cmd = cmd_arr.join(" ")
370
-
321
+ cmd = "#{adb_command} shell am instrument -e target_package #{ENV["PACKAGE_NAME"]} -e main_activity #{ENV["MAIN_ACTIVITY"]} -e class sh.calaba.instrumentationbackend.InstrumentationBackend sh.calaba.android.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner"
371
322
  log "Starting test server using:"
372
323
  log cmd
373
324
  raise "Could not execute command to start test server" unless system("#{cmd} 2>&1")
@@ -389,37 +340,12 @@ module Operations
389
340
  log "Instrumentation backend is ready!"
390
341
  end
391
342
  end
392
- rescue Exception => e
393
343
 
344
+ rescue
394
345
  msg = "Unable to make connection to Calabash Test Server at http://127.0.0.1:#{@server_port}/\n"
395
346
  msg << "Please check the logcat output for more info about what happened\n"
396
347
  raise msg
397
348
  end
398
-
399
- log "Checking client-server version match..."
400
- response = perform_action('version')
401
- unless response['success']
402
- msg = ["Unable to obtain Test Server version. "]
403
- msg << "Please run 'reinstall_test_server' to make sure you have the correct version"
404
- msg_s = msg.join("\n")
405
- log(msg_s)
406
- raise msg_s
407
- end
408
- unless response['message'] == Calabash::Android::VERSION
409
-
410
- msg = ["Calabash Client and Test-server version mismatch."]
411
- msg << "Client version #{Calabash::Android::VERSION}"
412
- msg << "Test-server version #{response['message']}"
413
- msg << "Expected Test-server version #{Calabash::Android::VERSION}"
414
- msg << "\n\nSolution:\n\n"
415
- msg << "Run 'reinstall_test_server' to make sure you have the correct version"
416
- msg_s = msg.join("\n")
417
- log(msg_s)
418
- raise msg_s
419
- end
420
- log("Client and server versions match. Proceeding...")
421
-
422
-
423
349
  end
424
350
 
425
351
  def shutdown_test_server
@@ -443,15 +369,6 @@ module Operations
443
369
  def set_gps_coordinates(latitude, longitude)
444
370
  perform_action('set_gps_coordinates', latitude, longitude)
445
371
  end
446
-
447
- def input_keyevent(keycode)
448
- cmd = "#{adb_command} shell input keyevent #{keycode.to_s}"
449
- result = `#{cmd}`
450
- end
451
-
452
- def press_back_key
453
- input_keyevent(4)
454
- end
455
372
  end
456
373
 
457
374
 
@@ -462,24 +379,22 @@ module Operations
462
379
 
463
380
  def screenshot_and_raise(msg)
464
381
  screenshot_embed
382
+ sleep 5
465
383
  raise(msg)
466
384
  end
467
385
 
468
386
  def touch(uiquery,*args)
469
- raise "Cannot touch nil" unless uiquery
470
-
471
387
  if uiquery.instance_of? String
472
388
  elements = query(uiquery, *args)
473
- raise "No elements found. Query: #{uiquery}" if elements.empty?
389
+ raise "No elements found" if elements.empty?
474
390
  element = elements.first
475
391
  else
476
392
  element = uiquery
477
- element = element.first if element.instance_of?(Array)
478
393
  end
479
394
 
480
395
 
481
- center_x = element["rect"]["center_x"]
482
- center_y = element["rect"]["center_y"]
396
+ center_x = element["frame"]["x"] + element["frame"]["width"] / 2
397
+ center_y = element["frame"]["y"] + element["frame"]["height"] / 2
483
398
  performAction("touch_coordinate", center_x, center_y)
484
399
  end
485
400
 
@@ -521,8 +436,7 @@ module Operations
521
436
  end
522
437
 
523
438
  def scroll_to_row(uiquery,number)
524
- query(uiquery, {:smoothScrollToPosition => number})
525
- puts "TODO:detect end of scroll - use sleep for now"
439
+ ni
526
440
  end
527
441
 
528
442
  def pinch(in_out,options={})
@@ -537,16 +451,12 @@ module Operations
537
451
  ni
538
452
  end
539
453
 
540
- def element_does_not_exist(uiquery)
541
- query(uiquery).empty?
542
- end
543
-
544
454
  def element_exists(uiquery)
545
- not element_does_not_exist(uiquery)
455
+ !query(uiquery).empty?
546
456
  end
547
457
 
548
458
  def view_with_mark_exists(expected_mark)
549
- element_exists( "android.view.View marked:'#{expected_mark}'" )
459
+ element_exists( "view marked:'#{expected_mark}'" )
550
460
  end
551
461
 
552
462
  def check_element_exists( query )
@@ -595,19 +505,8 @@ module Operations
595
505
  ni
596
506
  end
597
507
 
598
- def map(query, method_name, *method_args)
599
- operation_map = {
600
- :method_name => method_name,
601
- :arguments => method_args
602
- }
603
- res = http("/map",
604
- {:query => query, :operation => operation_map})
605
- res = JSON.parse(res)
606
- if res['outcome'] != 'SUCCESS'
607
- screenshot_and_raise "map #{query}, #{method_name} failed because: #{res['reason']}\n#{res['details']}"
608
- end
609
-
610
- res['results']
508
+ def map( query, method_name, *method_args )
509
+ ni
611
510
  end
612
511
 
613
512
  def url_for( verb )
@@ -26,7 +26,7 @@ Then /^The "([^\"]*)" for row (\d+) should be "([^\"]*)"$/ do | view_id, row, va
26
26
 
27
27
  if( response['children'] )
28
28
  found_id = false
29
- response['children'].each do | view |
29
+ response['children'] each do | view |
30
30
  if( view['id'] == view_id )
31
31
  raise "Text is #{view['text']}, expected #{value}" unless( view['text'] == value )
32
32
  found_id = true
@@ -4,5 +4,5 @@ Given /^I set the time to "(\d\d:\d\d)" on TimePicker with index "([^\"]*)"$/ do
4
4
  end
5
5
 
6
6
  Given /^I set the "([^\"]*)" time to "(\d\d:\d\d)"$/ do |content_description, time|
7
- performAction('set_time_with_description', content_description, time)
7
+ performAction('set_time_with_description', time, content_description)
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.4.0.pre19"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -22,8 +22,6 @@
22
22
 
23
23
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
24
24
  <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
25
- <uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION"/>
26
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
27
25
  <uses-permission android:name="android.permission.INTERNET" />
28
26
 
29
27
  </manifest>
@@ -69,7 +69,6 @@
69
69
  <copy todir="${staging.dir}/assets">
70
70
  <fileset dir="${calabashjs.dir}"/>
71
71
  </copy>
72
- <replace file="${staging.dir}/src/sh/calaba/instrumentationbackend/actions/version/Version.java" token="####VERSION####" value="${version}" failOnNoReplacements="true" />
73
72
  </target>
74
73
 
75
74
 
@@ -3,6 +3,7 @@
3
3
  <classpathentry kind="src" path="src"/>
4
4
  <classpathentry kind="src" path="gen"/>
5
5
  <classpathentry kind="src" path="assets"/>
6
+ <classpathentry kind="src" path="tests"/>
6
7
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
7
8
  <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
8
9
  <classpathentry kind="lib" path="libs/robotium-solo-3.6.jar"/>
@@ -6,7 +6,7 @@
6
6
 
7
7
  <uses-sdk android:minSdkVersion="6" />
8
8
 
9
- <application android:label="CalabashTestServer" android:debuggable="true">
9
+ <application android:label="CalabashTestServer" >
10
10
  <uses-library android:name="android.test.runner" />
11
11
  <uses-library android:name="com.google.android.maps" android:required="false" />
12
12
  </application>