解决方法:
用拼接方法指定 APP_PATH,如下:
APP_PATH = File.join(File.dirname(__FILE__),'..','SuerApp9_6.apk')
昨天在写一个 app 自动化脚本时,运到如上问题。
论坛中之前有相关帖子,但是没有解决办法。参https://testerhome.com/topics/1834
我自己也去 StackOverflow 查找,试过将 APP_PATH 设置成绝对路径,请开发将包名更改成 com.changhong.supperapp 后将 appActivity 设置成'.activity.SplashActivity',均未解决。
目前我怀疑是不是因为启动页是一个 Splash 引起的问题,纯属猜测哈。
测试环境:
Win7_32bit
appium_server:1.4.10
appium_lib:7.0.0
jdk:1.8.25
手动执行,通过 Monitor 工具抓取的 Activity 日志:
09-08 21:25:31.482: I/ActivityManager(679): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.changhong.ssc.cookbook cmp=com.changhong.ssc.cookbook/com.changhong.superapp.activity.SplashActivity} from pid 32669
09-08 21:25:31.497: W/ActivityManager(679): [LTK] pid, app, 3d=32669, 0, 199913472
09-08 21:25:31.543: I/ActivityManager(679): Start proc com.changhong.ssc.cookbook for activity com.changhong.ssc.cookbook/com.changhong.superapp.activity.SplashActivity: pid=499 uid=10083 gids={50083, 3002, 3003, 1015, 1006, 1028}
09-08 21:25:32.430: I/ActivityManager(679): [AppLaunch] Displayed Displayed com.changhong.ssc.cookbook/com.changhong.superapp.activity.SplashActivity: +906ms
09-08 21:25:35.204: I/ActivityManager(679): START u0 {cmp=com.changhong.ssc.cookbook/com.changhong.superapp.activity.main.MainActivity (has extras)} from pid 499
09-08 21:25:35.207: W/ActivityManager(679): [LTK] pid, app, 3d=499, 0, 220106752
09-08 21:25:36.414: I/ActivityManager(679): [AppLaunch] Displayed Displayed com.changhong.ssc.cookbook/com.changhong.superapp.activity.main.MainActivity: +1s200ms
Ruby 部分代码如下:
APP_PATH = '../SuerApp9_6.apk'
def desired_caps
{
caps: {
app: APP_PATH,
appPackage: 'com.changhong.ssc.cookbook',
appActivity: 'com.changhong.superapp.activity.SplashActivity',
appWaitActivity: 'com.changhong.superapp.activity.main.MainActivity', #这个是尝试无果后增加的
platformName: 'android',
platformVersion: '4.4.4',#API:19
deviceName: '274b3f06',#MI 3真机
unicodeKeyboard: 'true',
resetKeyboard: 'true',
noSign: 'true', #Skip checking and signing of app with debug keys
noReset: 'false'
}
}
Appium-Server 报错的 log 如下:
info: [debug] Device is at API Level 19
info: [debug] executing cmd: E:\adt-bundle-windows-x86-20140702\sdk\platform-tools\adb.exe -s 274b3f06 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.changhong.ssc.cookbook/com.changhong.superapp.activity.SplashActivity"
info: [debug] We tried to start an activity that doesn't exist, retrying with . prepended to activity
info: [debug] Getting device API level
info: [debug] executing cmd: E:\adt-bundle-windows-x86-20140702\sdk\platform-tools\adb.exe -s 274b3f06 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: [debug] executing cmd: E:\adt-bundle-windows-x86-20140702\sdk\platform-tools\adb.exe -s 274b3f06 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.changhong.ssc.cookbook/.com.changhong.superapp.activity.SplashActivity"
error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
~~~中间log略去
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
info: [debug] Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity
at [object Object].<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\adb.js:1146:21)
at [object Object].<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
at ChildProcess.exithandler (child_process.js:656:7)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)","origValue":"Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity"},"sessionId":null}
info: <-- POST /wd/hub/session 500 30130.327 ms - 346