calabash-android 0.4.3 → 0.4.4
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.
- data/Rakefile +1 -1
- data/lib/calabash-android.rb +2 -1
- data/lib/calabash-android/abase.rb +89 -0
- data/lib/calabash-android/lib/TestServer.apk +0 -0
- data/lib/calabash-android/lib/screenshotTaker.jar +0 -0
- data/lib/calabash-android/operations.rb +40 -10
- data/lib/calabash-android/steps/additions_manual_steps.rb +1 -1
- data/lib/calabash-android/version.rb +1 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/Actions.java +2 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForScreen.java +2 -2
- metadata +4 -3
- data/lib/calabash-android/lib/screenShotTaker.jar +0 -0
data/Rakefile
CHANGED
data/lib/calabash-android.rb
CHANGED
@@ -0,0 +1,89 @@
|
|
1
|
+
class Calabash::ABase
|
2
|
+
include Calabash::Android::Operations
|
3
|
+
|
4
|
+
|
5
|
+
attr_accessor :world, :transition_duration
|
6
|
+
|
7
|
+
def initialize(world, transition_duration=0.5)
|
8
|
+
self.world = world
|
9
|
+
self.transition_duration = transition_duration
|
10
|
+
end
|
11
|
+
|
12
|
+
def trait
|
13
|
+
raise "You should define a trait method or a title method" unless respond_to?(:title)
|
14
|
+
"* marked:'#{self.title}'"
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_page?
|
18
|
+
element_exists(trait)
|
19
|
+
end
|
20
|
+
|
21
|
+
def page(clz, *args)
|
22
|
+
clz.new(world, *args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def await(wait_opts={})
|
26
|
+
wait_for_elements_exist([trait], wait_opts)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Performs a transition from receiver page to another by performing a +:tap+ gesture
|
32
|
+
# or a user specified +:action+.
|
33
|
+
# Caller must supply a hash of options +transition_options+ to describe the transition.
|
34
|
+
# Transition options may have the following keys
|
35
|
+
#
|
36
|
+
# +:tap+: A uiquery used to perform a tap gesture to begin transition
|
37
|
+
# +:action+: A proc to use begin transition (either :tap or :action must be supplied)
|
38
|
+
# +:page+: A page object or page object class to transition to (target page). If a class is provided this
|
39
|
+
# is instantiated using the +page+ method of self. If no +:page+ is supplied, +self+ is used.
|
40
|
+
# +:await+: If specified and truthy will await the +:page+ after performing gesture (usually to wait
|
41
|
+
# for animation to finish)
|
42
|
+
# +:tap_options+: If +:tap+ is provided used to pass as options to touch
|
43
|
+
# +:wait_options+: When awaiting target page, pass these options to the +await+ method
|
44
|
+
#
|
45
|
+
# Returns the transition target page
|
46
|
+
#
|
47
|
+
# Note it is assumed that the target page is a Calabash::ABase (or acts accordingly)
|
48
|
+
def transition(transition_options={})
|
49
|
+
uiquery = transition_options[:tap]
|
50
|
+
action = transition_options[:action]
|
51
|
+
page_arg = transition_options[:page]
|
52
|
+
should_await = transition_options.has_key?(:await) ? transition_options[:await] : true
|
53
|
+
|
54
|
+
if action.nil? && uiquery.nil?
|
55
|
+
raise "Called transition without providing a gesture (:tap or :action) #{transition_options}"
|
56
|
+
end
|
57
|
+
|
58
|
+
if uiquery
|
59
|
+
tap_options = transition_options[:tap_options] || {}
|
60
|
+
touch(uiquery, tap_options)
|
61
|
+
else
|
62
|
+
action.call()
|
63
|
+
end
|
64
|
+
|
65
|
+
page_obj = page_arg.is_a?(Class) ? page(page_arg) : page_arg
|
66
|
+
page_obj ||= self
|
67
|
+
|
68
|
+
if should_await
|
69
|
+
unless page_obj == self
|
70
|
+
wait_opts = transition_options[:wait_options] || {}
|
71
|
+
page_obj.await(wait_opts)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
page_obj
|
76
|
+
end
|
77
|
+
|
78
|
+
def await_screenshot(wait_opts={}, screenshot_opts={})
|
79
|
+
await(wait_opts)
|
80
|
+
screenshot_embed(screenshot_opts)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
protected
|
85
|
+
def method_missing(name, *args, &block)
|
86
|
+
world.send(name, *args, &block)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
Binary file
|
Binary file
|
@@ -19,6 +19,10 @@ module Operations
|
|
19
19
|
include Calabash::Android::WaitHelpers
|
20
20
|
include Calabash::Android::TouchHelpers
|
21
21
|
|
22
|
+
def current_activity
|
23
|
+
`#{default_device.adb_command} shell dumpsys window windows`.each_line.grep(/mFocusedApp.+[\.\/]([^.\/\}]+)\}/){$1}.first
|
24
|
+
end
|
25
|
+
|
22
26
|
def log(message)
|
23
27
|
$stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose")
|
24
28
|
end
|
@@ -142,6 +146,14 @@ module Operations
|
|
142
146
|
|
143
147
|
###
|
144
148
|
|
149
|
+
### simple page object helper
|
150
|
+
|
151
|
+
def page(clz, *args)
|
152
|
+
clz.new(self, *args)
|
153
|
+
end
|
154
|
+
|
155
|
+
###
|
156
|
+
|
145
157
|
### app life cycle
|
146
158
|
def connect_to_test_server
|
147
159
|
puts "Explicit calls to connect_to_test_server should be removed."
|
@@ -277,8 +289,7 @@ module Operations
|
|
277
289
|
f.write res
|
278
290
|
end
|
279
291
|
else
|
280
|
-
|
281
|
-
screenshot_cmd = "java -jar #{File.join(File.dirname(__FILE__), 'lib', 'screenShotTaker.jar')} #{path} #{device_args}"
|
292
|
+
screenshot_cmd = "java -jar #{File.join(File.dirname(__FILE__), 'lib', 'screenshotTaker.jar')} #{serial} #{path}"
|
282
293
|
log screenshot_cmd
|
283
294
|
raise "Could not take screenshot" unless system(screenshot_cmd)
|
284
295
|
end
|
@@ -288,21 +299,35 @@ module Operations
|
|
288
299
|
end
|
289
300
|
|
290
301
|
def adb_command
|
302
|
+
"#{adb} -s #{serial}"
|
303
|
+
end
|
304
|
+
|
305
|
+
def adb
|
291
306
|
if is_windows?
|
292
|
-
%Q("#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe"
|
307
|
+
%Q("#{ENV["ANDROID_HOME"]}\\platform-tools\\adb.exe")
|
293
308
|
else
|
294
|
-
%Q("#{ENV["ANDROID_HOME"]}/platform-tools/adb"
|
309
|
+
%Q("#{ENV["ANDROID_HOME"]}/platform-tools/adb")
|
295
310
|
end
|
296
311
|
end
|
297
312
|
|
298
|
-
def
|
299
|
-
|
300
|
-
"-s #{@serial}"
|
301
|
-
else
|
302
|
-
""
|
303
|
-
end
|
313
|
+
def serial
|
314
|
+
@serial || default_serial
|
304
315
|
end
|
305
316
|
|
317
|
+
def default_serial
|
318
|
+
devices = connected_devices
|
319
|
+
log "connected_devices: #{devices}"
|
320
|
+
raise "No connected devices" if devices.empty?
|
321
|
+
raise "More than one device connected. Specify device serial using ADB_DEVICE_ARG" if devices.length > 1
|
322
|
+
devices.first
|
323
|
+
end
|
324
|
+
|
325
|
+
def connected_devices
|
326
|
+
lines = `#{adb} devices`.split("\n")
|
327
|
+
lines.shift
|
328
|
+
lines.collect { |l| l.split("\t").first}
|
329
|
+
end
|
330
|
+
|
306
331
|
def wake_up
|
307
332
|
wake_up_cmd = "#{adb_command} shell am start -a android.intent.action.MAIN -n #{package_name(@test_server_path)}/sh.calaba.instrumentationbackend.WakeUp"
|
308
333
|
log "Waking up device using:"
|
@@ -413,6 +438,11 @@ module Operations
|
|
413
438
|
def shutdown_test_server
|
414
439
|
begin
|
415
440
|
http("/kill")
|
441
|
+
Timeout::timeout(3) do
|
442
|
+
sleep 0.3 while app_running?
|
443
|
+
end
|
444
|
+
rescue Timeout::Error
|
445
|
+
log ("Could not kill app. Waited to 3 seconds.")
|
416
446
|
rescue EOFError
|
417
447
|
log ("Could not kill app. App is most likely not running anymore.")
|
418
448
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Then /^I compare the current screen with the reference image "([^\"]*) manually
|
1
|
+
Then /^I compare the current screen with the reference image "([^\"]*)" manually$/ do |name|
|
2
2
|
# TODO: once test artifacts directory is configurable, the image location
|
3
3
|
# will need to be either a fully qualified path somewhere (webserver?) or
|
4
4
|
# be relative to the output HTML file
|
@@ -16,7 +16,7 @@ public class WaitForScreen implements Action {
|
|
16
16
|
if (InstrumentationBackend.solo.waitForActivity(args[0], DEFAULT_TIMEOUT)) {
|
17
17
|
return Result.successResult();
|
18
18
|
} else {
|
19
|
-
String currentActivity = InstrumentationBackend.solo.getCurrentActivity().
|
19
|
+
String currentActivity = InstrumentationBackend.solo.getCurrentActivity().getClass().getSimpleName();
|
20
20
|
Result result = new Result(false, "Screen " + args[0] + " not found. Current activity is " + currentActivity);
|
21
21
|
result.addBonusInformation(currentActivity);
|
22
22
|
return result;
|
@@ -35,7 +35,7 @@ public class WaitForScreen implements Action {
|
|
35
35
|
if (InstrumentationBackend.solo.waitForActivity(args[0], timeout)) {
|
36
36
|
return Result.successResult();
|
37
37
|
} else {
|
38
|
-
String currentActivity = InstrumentationBackend.solo.getCurrentActivity().
|
38
|
+
String currentActivity = InstrumentationBackend.solo.getCurrentActivity().getClass().getSimpleName();
|
39
39
|
Result result = new Result(false, "Screen " + args[0] + " not found. Current activity is " + currentActivity);
|
40
40
|
result.addBonusInformation(currentActivity);
|
41
41
|
return result;
|
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.4.
|
4
|
+
version: 0.4.4
|
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: 2013-
|
12
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- features-skeleton/support/hooks.rb
|
139
139
|
- irbrc
|
140
140
|
- lib/calabash-android.rb
|
141
|
+
- lib/calabash-android/abase.rb
|
141
142
|
- lib/calabash-android/calabash_steps.rb
|
142
143
|
- lib/calabash-android/canned_steps.md
|
143
144
|
- lib/calabash-android/color_helper.rb
|
@@ -145,7 +146,7 @@ files:
|
|
145
146
|
- lib/calabash-android/helpers.rb
|
146
147
|
- lib/calabash-android/lib/AXMLPrinter2.jar
|
147
148
|
- lib/calabash-android/lib/manifest_extractor.jar
|
148
|
-
- lib/calabash-android/lib/
|
149
|
+
- lib/calabash-android/lib/screenshotTaker.jar
|
149
150
|
- lib/calabash-android/lib/unsign.jar
|
150
151
|
- lib/calabash-android/management/adb.rb
|
151
152
|
- lib/calabash-android/management/app_installation.rb
|
Binary file
|