calabash-android 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +11 -0
- data/bin/calabash-android-console.rb +10 -2
- data/features-skeleton/support/app_life_cycle_hooks.rb +0 -4
- data/irbrc +15 -0
- data/lib/calabash-android/lib/TestServer.apk +0 -0
- data/lib/calabash-android/operations.rb +40 -15
- data/lib/calabash-android/version.rb +1 -1
- data/test-server/instrumentation-backend/project.properties +1 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +1 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +33 -21
- metadata +2 -2
data/CHANGES.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
0.3.6:
|
2
|
+
Will fail if the keyguard cannot be disabled when starting the app.
|
3
|
+
|
4
|
+
If the app is not running calabash will now die instead of running around
|
5
|
+
like a serverless chicking.
|
6
|
+
|
7
|
+
On-device screenshots are still unstable but will no longer crash the app
|
8
|
+
if they fail.
|
9
|
+
|
10
|
+
Much better Cucumber output if the app is no longer running.
|
11
|
+
|
1
12
|
0.3.5:
|
2
13
|
No longer takes screenshots when perform_action fails.
|
3
14
|
If you want to take screenshots when a scenario fails you can use a hook:
|
@@ -10,11 +10,19 @@ def calabash_console(app_path = nil)
|
|
10
10
|
end
|
11
11
|
|
12
12
|
unless ENV["PACKAGE_NAME"]
|
13
|
-
ENV["PACKAGE_NAME"] = package_name(app_path)
|
13
|
+
ENV["PACKAGE_NAME"] = package_name(app_path)
|
14
14
|
end
|
15
15
|
|
16
16
|
unless ENV["MAIN_ACTIVITY"]
|
17
|
-
ENV["MAIN_ACTIVITY"] = main_activity(app_path)
|
17
|
+
ENV["MAIN_ACTIVITY"] = main_activity(app_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
unless ENV["APP_PATH"]
|
21
|
+
ENV["APP_PATH"] = app_path
|
22
|
+
end
|
23
|
+
|
24
|
+
unless ENV["TEST_APP_PATH"]
|
25
|
+
ENV["TEST_APP_PATH"] = test_server_path
|
18
26
|
end
|
19
27
|
|
20
28
|
system "irb"
|
data/irbrc
CHANGED
@@ -18,3 +18,18 @@ include Calabash::Android::Operations
|
|
18
18
|
def embed(*args)
|
19
19
|
puts "Embed is a Cucumber method and is not available in this console."
|
20
20
|
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
#Virker det her?
|
25
|
+
module Calabash
|
26
|
+
module Android
|
27
|
+
module Operations
|
28
|
+
class Cucumber
|
29
|
+
def self.wants_to_quit
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
Binary file
|
@@ -151,13 +151,13 @@ module Operations
|
|
151
151
|
cmd = "#{adb_command} install \"#{app_path}\""
|
152
152
|
log "Installing: #{app_path}"
|
153
153
|
result = `#{cmd}`
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
raise "
|
154
|
+
log result
|
155
|
+
pn = package_name(app_path)
|
156
|
+
succeeded = `#{adb_command} shell pm list packages`.include?("package:#{pn}")
|
157
|
+
|
158
|
+
unless succeeded
|
159
|
+
Cucumber.wants_to_quit = true
|
160
|
+
raise "#{pn} did not get installed. Aborting!"
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -166,6 +166,16 @@ module Operations
|
|
166
166
|
log `#{adb_command} uninstall #{package_name}`
|
167
167
|
end
|
168
168
|
|
169
|
+
def app_running?
|
170
|
+
`#{adb_command} shell ps`.include?(package_name(@app_path))
|
171
|
+
end
|
172
|
+
|
173
|
+
def keyguard_enabled?
|
174
|
+
dumpsys = `#{adb_command} shell dumpsys window windows`
|
175
|
+
#If a line containing mCurrentFocus and Keyguard exists the keyguard is enabled
|
176
|
+
dumpsys.lines.any? { |l| l.include?("mCurrentFocus") and l.include?("Keyguard")}
|
177
|
+
end
|
178
|
+
|
169
179
|
def perform_action(action, *arguments)
|
170
180
|
log "Action: #{action} - Params: #{arguments.join(', ')}"
|
171
181
|
|
@@ -173,7 +183,7 @@ module Operations
|
|
173
183
|
|
174
184
|
Timeout.timeout(300) do
|
175
185
|
begin
|
176
|
-
result = http("/", params)
|
186
|
+
result = http("/", params, {:read_timeout => 350})
|
177
187
|
rescue Exception => e
|
178
188
|
log "Error communicating with test server: #{e}"
|
179
189
|
raise e
|
@@ -190,17 +200,19 @@ module Operations
|
|
190
200
|
raise Exception, "Step timed out"
|
191
201
|
end
|
192
202
|
|
193
|
-
def http(path, data = {})
|
194
|
-
retries = 0
|
203
|
+
def http(path, data = {}, options = {})
|
195
204
|
begin
|
196
205
|
http = Net::HTTP.new "127.0.0.1", @server_port
|
206
|
+
http.open_timeout = options[:open_timeout] if options[:open_timeout]
|
207
|
+
http.read_timeout = options[:read_timeout] if options[:read_timeout]
|
197
208
|
resp = http.post(path, "#{data.to_json}", {"Content-Type" => "application/json;charset=utf-8"})
|
198
209
|
resp.body
|
199
210
|
rescue Exception => e
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
211
|
+
if app_running?
|
212
|
+
raise e
|
213
|
+
else
|
214
|
+
raise "App no longer running"
|
215
|
+
end
|
204
216
|
end
|
205
217
|
end
|
206
218
|
|
@@ -280,19 +292,32 @@ module Operations
|
|
280
292
|
log "Waking up device using:"
|
281
293
|
log wake_up_cmd
|
282
294
|
raise "Could not wake up the device" unless system(wake_up_cmd)
|
295
|
+
|
296
|
+
retriable :tries => 10, :interval => 1 do
|
297
|
+
raise "Could not remove the keyguard" if keyguard_enabled?
|
298
|
+
end
|
283
299
|
end
|
284
300
|
|
285
301
|
def start_test_server_in_background
|
302
|
+
raise "Will not start test server because of previous failures." if Cucumber.wants_to_quit
|
303
|
+
|
304
|
+
if keyguard_enabled?
|
305
|
+
wake_up
|
306
|
+
end
|
307
|
+
|
286
308
|
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"
|
287
309
|
log "Starting test server using:"
|
288
310
|
log cmd
|
289
311
|
raise "Could not execute command to start test server" unless system("#{cmd} 2>&1")
|
290
312
|
|
313
|
+
raise "App did not start" unless app_running?
|
314
|
+
|
291
315
|
begin
|
292
316
|
retriable :tries => 10, :interval => 3 do
|
293
317
|
log "Checking if instrumentation backend is ready"
|
294
|
-
ready = http("/ready")
|
295
318
|
|
319
|
+
log "Is app running? #{app_running?}"
|
320
|
+
ready = http("/ready", {}, {:read_timeout => 1})
|
296
321
|
if ready != "true"
|
297
322
|
log "Instrumentation backend not yet ready"
|
298
323
|
raise "Not ready"
|
@@ -1,14 +1,16 @@
|
|
1
1
|
package sh.calaba.instrumentationbackend.actions;
|
2
2
|
|
3
|
-
import java.io
|
4
|
-
import java.io.ByteArrayOutputStream;
|
5
|
-
import java.io.File;
|
3
|
+
import java.io.*;
|
6
4
|
import java.util.Properties;
|
7
5
|
import java.util.List;
|
8
6
|
import java.util.concurrent.locks.Condition;
|
9
7
|
import java.util.concurrent.locks.Lock;
|
10
8
|
import java.util.concurrent.locks.ReentrantLock;
|
11
9
|
|
10
|
+
import android.Manifest;
|
11
|
+
import android.app.Activity;
|
12
|
+
import android.app.ActivityManager;
|
13
|
+
import android.content.pm.PackageManager;
|
12
14
|
import android.graphics.Bitmap;
|
13
15
|
import android.view.View;
|
14
16
|
import sh.calaba.instrumentationbackend.Command;
|
@@ -59,11 +61,11 @@ public class HttpServer extends NanoHTTPD {
|
|
59
61
|
super(7102, new File("/"));
|
60
62
|
}
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
public Response serve( String uri, String method, Properties header, Properties params, Properties files )
|
65
|
+
{
|
66
|
+
System.out.println("URI: " + uri);
|
67
|
+
if (uri.endsWith("/ping")) {
|
68
|
+
return new NanoHTTPD.Response( HTTP_OK, MIME_HTML, "pong");
|
67
69
|
|
68
70
|
} else if (uri.endsWith("/kill")) {
|
69
71
|
lock.lock();
|
@@ -83,16 +85,23 @@ public class HttpServer extends NanoHTTPD {
|
|
83
85
|
|
84
86
|
|
85
87
|
} else if (uri.endsWith("/screenshot")) {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
88
|
+
try {
|
89
|
+
Bitmap bitmap;
|
90
|
+
View rootView = getRootView();
|
91
|
+
rootView.setDrawingCacheEnabled(true);
|
92
|
+
rootView.buildDrawingCache(true);
|
93
|
+
bitmap = Bitmap.createBitmap(rootView.getDrawingCache());
|
94
|
+
rootView.setDrawingCacheEnabled(false);
|
95
|
+
|
96
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
97
|
+
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
|
98
|
+
return new NanoHTTPD.Response( HTTP_OK, "image/png", new ByteArrayInputStream(out.toByteArray()));
|
99
|
+
} catch (Exception e) {
|
100
|
+
StringWriter sw = new StringWriter();
|
101
|
+
PrintWriter pw = new PrintWriter(sw);
|
102
|
+
e.printStackTrace(pw);
|
103
|
+
return new NanoHTTPD.Response( HTTP_INTERNALERROR, null, sw.toString());
|
104
|
+
}
|
96
105
|
}
|
97
106
|
|
98
107
|
System.out.println("header: "+ header);
|
@@ -111,9 +120,12 @@ public class HttpServer extends NanoHTTPD {
|
|
111
120
|
private View getRootView() {
|
112
121
|
for ( int i = 0; i < 25; i++) {
|
113
122
|
try {
|
114
|
-
View
|
115
|
-
if (
|
116
|
-
|
123
|
+
View decorView = InstrumentationBackend.solo.getCurrentActivity().getWindow().getDecorView();
|
124
|
+
if (decorView != null) {
|
125
|
+
View rootView = decorView.findViewById(android.R.id.content);
|
126
|
+
if (rootView != null) {
|
127
|
+
return rootView;
|
128
|
+
}
|
117
129
|
}
|
118
130
|
System.out.println("Retry: " + i);
|
119
131
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calabash-android
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|