Skip to content

Commit 5b1e3d8

Browse files
Fix current_app on Android
1 parent aa6e93a commit 5b1e3d8

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

android_tests/appium.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[caps]
22
platformName = "android"
33
app = "./api.apk"
4-
appPackage = ""
5-
appActivity = ""
4+
appPackage = "io.appium.android.apis"
5+
appActivity = ".ApiDemos"
66

77
[appium_lib]
88
sauce_username = ""

android_tests/lib/android/specs/common/helper.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# regular rescue will not handle exceptions outside of StandardError hierarchy
1616
# must rescue Exception explicitly to rescue everything
1717
proc { wait(*wait_time) { raise NoMemoryError } }.must_raise Timeout::Error
18+
proc { wait(0.2, 0.0) { raise NoMemoryError } }.must_raise Timeout::Error
1819
end
1920

2021
t 'ignore' do
@@ -40,7 +41,8 @@
4041

4142
# regular rescue will not handle exceptions outside of StandardError hierarchy
4243
# must rescue Exception explicitly to rescue everything
43-
proc { wait(*wait_time) { raise NoMemoryError } }.must_raise Timeout::Error
44+
proc { wait_true(*wait_time) { raise NoMemoryError } }.must_raise Timeout::Error
45+
proc { wait_true(0.2, 0.0) { raise NoMemoryError } }.must_raise Timeout::Error
4446
end
4547

4648
t 'back' do

lib/appium_lib/android/helper.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,15 @@ def page opts={}
113113
# Lists package, activity, and adb shell am start -n value for current app.
114114
# Works on local host only (not remote).
115115
# noinspection RubyArgCount
116+
# example line:
117+
# "mFocusedApp=AppWindowToken{b1420058 token=Token{b128add0 ActivityRecord{b1264d10 u0 com.example.android.apis/.ApiDemos t23}}}"
116118
def current_app
117119
line = `adb shell dumpsys window windows`.each_line.grep(/mFocusedApp/).first.strip
118-
pair = line.split(' ').last.gsub('}', '').split '/'
120+
121+
match = line.match(/ ([^\/ ]+\/[^ ]+) /)
122+
return nil unless match && match[1]
123+
124+
pair = match[1].split '/'
119125
pkg = pair.first
120126
act = pair.last
121127
OpenStruct.new(line: line,

0 commit comments

Comments
 (0)