calabash-android 0.2.17 → 0.2.18
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +5 -0
- data/bin/calabash-android-run.rb +6 -1
- data/features-skeleton/support/hooks.rb +0 -34
- data/lib/calabash-android/operations.rb +53 -17
- data/lib/calabash-android/steps/screenshot_steps.rb +3 -3
- data/lib/calabash-android/version.rb +1 -1
- data/test-server/build.xml +1 -12
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +22 -4
- metadata +2 -2
data/CHANGES.txt
CHANGED
data/bin/calabash-android-run.rb
CHANGED
@@ -19,11 +19,16 @@ def calabash_run(app_path = nil)
|
|
19
19
|
end
|
20
20
|
|
21
21
|
test_server_path = test_server_path(app_path)
|
22
|
+
if ENV["TEST_SERVER_PORT"]
|
23
|
+
test_server_port = ENV["TEST_SERVER_PORT"]
|
24
|
+
else
|
25
|
+
test_server_port = "34777"
|
26
|
+
end
|
22
27
|
env = "PACKAGE_NAME=#{package_name(app_path)} "\
|
23
28
|
"TEST_PACKAGE_NAME=#{package_name(test_server_path)} "\
|
24
29
|
"APP_PATH=\"#{app_path}\" "\
|
25
30
|
"TEST_APP_PATH=\"#{test_server_path}\" "\
|
26
|
-
"TEST_SERVER_PORT
|
31
|
+
"TEST_SERVER_PORT=#{test_server_port}"
|
27
32
|
else
|
28
33
|
env = ""
|
29
34
|
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
Before do |scenario|
|
3
|
-
# https://groups.google.com/forum/?fromgroups#!topic/calabash-ios/ICA4f24eSsY
|
4
|
-
@scenario_is_outline = (scenario.class == Cucumber::Ast::OutlineTable::ExampleRow)
|
5
|
-
if @scenario_is_outline
|
6
|
-
scenario = scenario.scenario_outline
|
7
|
-
end
|
8
|
-
|
9
|
-
StepCounter.step_index = 0
|
10
|
-
# https://github.com/calabash/calabash-android/issues/58#issuecomment-6745642
|
11
|
-
if scenario.respond_to? :raw_steps
|
12
|
-
StepCounter.step_line = scenario.raw_steps[StepCounter.step_index].line
|
13
|
-
else
|
14
|
-
StepCounter.step_line = 0
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
AfterStep do |scenario|
|
19
|
-
#Handle multiline steps
|
20
|
-
StepCounter.step_index = StepCounter.step_index + 1
|
21
|
-
# https://github.com/calabash/calabash-android/issues/58#issuecomment-6745642
|
22
|
-
if scenario.respond_to? :raw_steps
|
23
|
-
StepCounter.step_line = scenario.raw_steps[StepCounter.step_index].line unless scenario.raw_steps[StepCounter.step_index].nil?
|
24
|
-
else
|
25
|
-
StepCounter.step_line = StepCounter.step_line + 1
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
StepCounter = Class.new
|
30
|
-
class << StepCounter
|
31
|
-
@step_index = 0
|
32
|
-
@step_line = 0
|
33
|
-
attr_accessor :step_index, :step_line
|
34
|
-
end
|
@@ -19,7 +19,7 @@ module Operations
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def take_screenshot
|
22
|
-
|
22
|
+
default_device.take_screenshot
|
23
23
|
end
|
24
24
|
|
25
25
|
def macro(txt)
|
@@ -29,28 +29,38 @@ module Operations
|
|
29
29
|
Then(txt)
|
30
30
|
end
|
31
31
|
end
|
32
|
+
def default_device
|
33
|
+
Device.default_device(self)
|
34
|
+
end
|
32
35
|
|
33
36
|
def shutdown_test_server
|
34
|
-
|
37
|
+
default_device.shutdown_test_server
|
35
38
|
end
|
36
39
|
|
37
40
|
def performAction(action, *arguments)
|
38
|
-
|
41
|
+
default_device.perform_action(action, *arguments)
|
39
42
|
end
|
40
43
|
|
41
44
|
def install_app(app_path)
|
42
|
-
|
45
|
+
default_device.install_app(app_path)
|
43
46
|
end
|
44
47
|
|
45
48
|
def uninstall_apps
|
46
|
-
|
47
|
-
|
49
|
+
default_device.uninstall_app(ENV["TEST_PACKAGE_NAME"])
|
50
|
+
default_device.uninstall_app(ENV["PACKAGE_NAME"])
|
48
51
|
end
|
49
52
|
|
50
53
|
def start_test_server_in_background
|
51
|
-
|
54
|
+
default_device.start_test_server_in_background()
|
52
55
|
end
|
53
56
|
|
57
|
+
def screenshot_embed(options={:prefix => nil, :name => nil, :label => nil})
|
58
|
+
default_device.screenshot_embed(options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def screenshot(options={:prefix => nil, :name => nil})
|
62
|
+
default_device.screenshot(options)
|
63
|
+
end
|
54
64
|
|
55
65
|
def wait_for(timeout, &block)
|
56
66
|
begin
|
@@ -99,9 +109,9 @@ module Operations
|
|
99
109
|
class Device
|
100
110
|
@@default_device = nil
|
101
111
|
|
102
|
-
def self.default_device
|
112
|
+
def self.default_device(cucumber_world)
|
103
113
|
unless @@default_device
|
104
|
-
@@default_device = Device.new(ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
|
114
|
+
@@default_device = Device.new(cucumber_world, ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
|
105
115
|
end
|
106
116
|
@@default_device
|
107
117
|
end
|
@@ -110,7 +120,8 @@ module Operations
|
|
110
120
|
@@default_device = self
|
111
121
|
end
|
112
122
|
|
113
|
-
def initialize(serial, server_port, app_path, test_server_path)
|
123
|
+
def initialize(cucumber_world, serial, server_port, app_path, test_server_path)
|
124
|
+
@cucumber_world = cucumber_world
|
114
125
|
@serial = serial
|
115
126
|
@server_port = server_port
|
116
127
|
@app_path = app_path
|
@@ -166,7 +177,7 @@ module Operations
|
|
166
177
|
raise "Empty result from TestServer" if result.chomp.empty?
|
167
178
|
result = JSON.parse(result)
|
168
179
|
if not result["success"] then
|
169
|
-
|
180
|
+
screenshot_embed
|
170
181
|
if result["bonusInformation"] && result["bonusInformation"].size > 0 && result["bonusInformation"][0].include?("Exception")
|
171
182
|
log result["bonusInformation"][0]
|
172
183
|
end
|
@@ -193,6 +204,7 @@ module Operations
|
|
193
204
|
end
|
194
205
|
|
195
206
|
def take_screenshot
|
207
|
+
puts "take_screenshot is deprecated. Use screenshot_embed instead."
|
196
208
|
path = ENV["SCREENSHOT_PATH_PREFIX"] || "results"
|
197
209
|
FileUtils.mkdir_p path unless File.exist? path
|
198
210
|
filename_prefix = FeatureNameMemory.feature_name.gsub(/\s+/, '_').downcase
|
@@ -203,13 +215,41 @@ module Operations
|
|
203
215
|
open(file_name ,"wb") { |file|
|
204
216
|
file.write(image)
|
205
217
|
}
|
206
|
-
log "Screenshot stored in: #{file_name}"
|
218
|
+
log "Screenshot stored in: #{file_name}!!!"
|
207
219
|
end
|
208
220
|
rescue Timeout::Error
|
209
221
|
raise Exception, "take_screenshot timed out"
|
210
222
|
end
|
211
223
|
end
|
212
224
|
|
225
|
+
def screenshot_embed(options={:prefix => nil, :name => nil, :label => nil})
|
226
|
+
path = screenshot(options)
|
227
|
+
@cucumber_world.embed(path, "image/png", options[:label] || File.basename(path))
|
228
|
+
end
|
229
|
+
|
230
|
+
def screenshot(options={:prefix => nil, :name => nil})
|
231
|
+
prefix = options[:prefix] || ENV['SCREENSHOT_PATH'] || ""
|
232
|
+
name = options[:name]
|
233
|
+
|
234
|
+
if name.nil?
|
235
|
+
name = "screenshot"
|
236
|
+
else
|
237
|
+
if File.extname(name).downcase == ".png"
|
238
|
+
name = name.split(".png")[0]
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
@@screenshot_count ||= 0
|
243
|
+
res = http("/screenshot")
|
244
|
+
|
245
|
+
path = "#{prefix}#{name}_#{@@screenshot_count}.png"
|
246
|
+
File.open(path, 'wb') do |f|
|
247
|
+
f.write res
|
248
|
+
end
|
249
|
+
@@screenshot_count += 1
|
250
|
+
path
|
251
|
+
end
|
252
|
+
|
213
253
|
def adb_command
|
214
254
|
if is_windows?
|
215
255
|
%Q("#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe" #{device_args})
|
@@ -283,7 +323,7 @@ module Operations
|
|
283
323
|
end
|
284
324
|
|
285
325
|
def screenshot_and_raise(msg)
|
286
|
-
|
326
|
+
screenshot_embed
|
287
327
|
sleep 5
|
288
328
|
raise(msg)
|
289
329
|
end
|
@@ -394,10 +434,6 @@ module Operations
|
|
394
434
|
def backdoor(sel, arg)
|
395
435
|
ni
|
396
436
|
end
|
397
|
-
|
398
|
-
def screenshot
|
399
|
-
ni
|
400
|
-
end
|
401
437
|
|
402
438
|
def map( query, method_name, *method_args )
|
403
439
|
ni
|
data/test-server/build.xml
CHANGED
@@ -46,18 +46,7 @@
|
|
46
46
|
<path id="android.target.classpath">
|
47
47
|
<fileset dir="${env.ANDROID_HOME}/platforms/android-${android.api.level}/" includes="*.jar"/>
|
48
48
|
</path>
|
49
|
-
|
50
|
-
<target name="test" description="Run test features" depends="package">
|
51
|
-
<exec executable="cucumber${bat}">
|
52
|
-
<env key="PACKAGE_NAME" value="${tested.package_name}" />
|
53
|
-
<env key="TEST_PACKAGE_NAME" value="${tested.package_name}.test" />
|
54
|
-
<env key="APP_PATH" value="${tested.project.apk}" />
|
55
|
-
<env key="TEST_APP_PATH" value="bin/Test.apk" />
|
56
|
-
<env key="TEST_SERVER_PORT" value="34777" />
|
57
|
-
<env key="ADB_DEVICE_ARG" value="${adb.device.arg}" />
|
58
|
-
<arg value="features" />
|
59
|
-
</exec>
|
60
|
-
</target>
|
49
|
+
|
61
50
|
<target name="-check.preconditions">
|
62
51
|
<available file="${tested.project.apk}" property="tested.apk.found" />
|
63
52
|
<fail unless="tested.apk.found" message="Tested apk: '${tested.project.apk}' could not be found"/>
|
@@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream;
|
|
4
4
|
import java.io.ByteArrayOutputStream;
|
5
5
|
import java.io.File;
|
6
6
|
import java.util.Properties;
|
7
|
+
import java.util.List;
|
7
8
|
import java.util.concurrent.locks.Condition;
|
8
9
|
import java.util.concurrent.locks.Lock;
|
9
10
|
import java.util.concurrent.locks.ReentrantLock;
|
@@ -83,10 +84,10 @@ public class HttpServer extends NanoHTTPD {
|
|
83
84
|
|
84
85
|
} else if (uri.endsWith("/screenshot")) {
|
85
86
|
Bitmap bitmap;
|
86
|
-
View
|
87
|
-
|
88
|
-
bitmap = Bitmap.createBitmap(
|
89
|
-
|
87
|
+
View rootView = getRootView();
|
88
|
+
rootView.setDrawingCacheEnabled(true);
|
89
|
+
bitmap = Bitmap.createBitmap(rootView.getDrawingCache());
|
90
|
+
rootView.setDrawingCacheEnabled(false);
|
90
91
|
|
91
92
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
92
93
|
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
|
@@ -106,6 +107,23 @@ public class HttpServer extends NanoHTTPD {
|
|
106
107
|
return new NanoHTTPD.Response( HTTP_OK, MIME_HTML, result);
|
107
108
|
}
|
108
109
|
|
110
|
+
private View getRootView() {
|
111
|
+
for ( int i = 0; i < 25; i++) {
|
112
|
+
try {
|
113
|
+
View rootView = InstrumentationBackend.solo.getCurrentActivity().getWindow().getDecorView();
|
114
|
+
if (rootView != null) {
|
115
|
+
return rootView;
|
116
|
+
}
|
117
|
+
System.out.println("Retry: " + i);
|
118
|
+
|
119
|
+
Thread.sleep(200);
|
120
|
+
} catch (Exception e) {
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
throw new RuntimeException("Could not find any views");
|
125
|
+
}
|
126
|
+
|
109
127
|
private ObjectMapper createJsonMapper() {
|
110
128
|
ObjectMapper mapper = new ObjectMapper();
|
111
129
|
mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, true);
|
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.2.
|
4
|
+
version: 0.2.18
|
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-09-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|