环境:
Windows 7
Appium 1.2.0 for windoows
appium.exe
AppiumDriver
备注:用的 Python 跟 Java 都一样的问题

问题一:
许久没有使用 Appium,回来后更新了 1.2 版本,但是发现一个奇葩问题,为什么无法自动启动已安装的应用?Appium 解锁后手动运行程序后可继续跑脚本,如果不手动运行会 Timeout 结束,贴 LOG

> info: --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformVersion":"4.4.4","platformName":"Android","deviceName":"148904d2"}}
> ERROR: debug: Appium request initiated at /wd/hub/session
> ERROR: debug: Request received with params: {"desiredCapabilities":{"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformVersion":"4.4.4","platformName":"Android","deviceName":"148904d2"}}
> info: Retrieving device
> ERROR: debug: Didn't get app but did get Android package, will attempt to launch it on the device
> ERROR: debug: Creating new appium session 26ca6b5b-851e-417b-bc0f-539f7e024b25
> ERROR: debug: Using fast reset? true
> ERROR: debug: Preparing device for session
> ERROR: debug: Not checking whether app is present since we are assuming it's already on the device
> ERROR: debug: Checking whether adb is present
> ERROR: debug: Using adb from E:\android-sdk-windows\platform-tools\adb.exe
> ERROR: debug: Trying to find a connected android device
> ERROR: debug: Getting connected devices...
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" devices
> ERROR: debug: 1 device(s) connected
> info: Found device 61625b81
> ERROR: debug: Setting device id to 61625b81
> ERROR: debug: Waiting for device to be ready and to respond to shell commands (timeout = 5)
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 wait-for-device
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "echo 'ready'"
> ERROR: debug: Starting logcat capture
> warn: No app capability, can't parse package/activity
> ERROR: debug: Getting device API level
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "getprop ro.build.version.sdk"
> ERROR: debug: Device is at API Level 19
> info: Device API level is: 19
> ERROR: debug: Apk doesn't exist locally
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "rm -rf /data/local/tmp/strings.json"
> ERROR: debug: Not uninstalling app since server not started with --full-reset
> ERROR: debug: Skipping install since we launched with a package instead of an app path
> ERROR: debug: Forwarding system:4724 to device:4724
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 forward tcp:4724 tcp:4724
> ERROR: debug: Pushing appium bootstrap to device...
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 push "E:\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
> ERROR: debug: Pushing settings apk to device...
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 install "E:\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> ERROR: debug: Pushing unlock helper app to device...
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 install "E:\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
> info: Starting App
> ERROR: debug: Attempting to kill all 'uiautomator' processes
> ERROR: debug: Getting all processes with 'uiautomator'
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "ps 'uiautomator'"
> ERROR: debug: No matching processes found
> ERROR: debug: Running bootstrap
> ERROR: debug: spawning: E:\android-sdk-windows\platform-tools\adb.exe -s 61625b81 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap
> ERROR: debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> ERROR: debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> ERROR: debug: [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> ERROR: debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> ERROR: debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> ERROR: debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> ERROR: debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> ERROR: debug: [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
> ERROR: debug: [BOOTSTRAP] [debug] Socket opened on port 4724
> ERROR: debug: [BOOTSTRAP] [debug] Appium Socket Server Ready
> ERROR: debug: [BOOTSTRAP] [debug] Loading json...
> ERROR: debug: Waking up device if it's not alive
> ERROR: debug: Pushing command to appium work queue: ["wake",{}]
> ERROR: debug: [BOOTSTRAP] [debug] Registered crash watchers.
> ERROR: debug: [BOOTSTRAP] [debug] Client connected
> ERROR: debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
> ERROR: debug: [BOOTSTRAP] [debug] Got command of type ACTION
> ERROR: debug: [BOOTSTRAP] [debug] Got command action: wake
> ERROR: debug: [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window"
> ERROR: debug: Writing dumpsys output to E:\Appium\node_modules\appium\.dumpsys.log
> info: Unlocking screen
> ERROR: debug: Screen is locked, trying to unlock
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock"
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window"
> ERROR: debug: Writing dumpsys output to E:\Appium\node_modules\appium\.dumpsys.log
> ERROR: debug: Screen is unlocked, continuing
> ERROR: debug: Pushing command to appium work queue: ["getDataDir",{}]
> ERROR: debug: [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
> ERROR: debug: [BOOTSTRAP] [debug] Got command of type ACTION
> ERROR: debug: [BOOTSTRAP] [debug] Got command action: getDataDir
> ERROR: debug: [BOOTSTRAP] [debug] Returning result: {"value":"\/data\/local\/tmp","status":0}
> ERROR: debug: dataDir set to: /data/local/tmp
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.test.android.app/.ui.main.MainActivity"
> ERROR: debug: Waiting for pkg "com.test.android.app" and activity ".ui.main.MainActivity" to be focused
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Getting focused package and activity
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "dumpsys window windows"
> ERROR: debug: Device launched! Ready for commands
> info: <-- POST /wd/hub/session 303 20725.861 ms - 9 
> ERROR: debug: Setting command timeout to the default of 60 secs
> ERROR: debug: Appium session started with sessionId 26ca6b5b-851e-417b-bc0f-539f7e024b25
> info: --> GET /wd/hub/session/26ca6b5b-851e-417b-bc0f-539f7e024b25 {}
> ERROR: debug: Appium request initiated at /wd/hub/session/26ca6b5b-851e-417b-bc0f-539f7e024b25
> info: <-- GET /wd/hub/session/26ca6b5b-851e-417b-bc0f-539f7e024b25 200 2.179 ms - 534 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"warnings":{},"desired":{"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformVersion":"4.4.4","platformName":"Android","deviceName":"148904d2"},"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformName":"Android","deviceName":"148904d2"},"sessionId":"26ca6b5b-851e-417b-bc0f-539f7e024b25"}
> ERROR: debug: Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.4","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"warnings":{},"desired":{"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformVersion":"4.4.4","platformName":"Android","deviceName":"148904d2"},"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformName":"Android","deviceName":"148904d2"},"sessionId":"26ca6b5b-851e-417b-bc0f-539f7e024b25"}

LOG 很长,至此 APP 启动过程结束,才会执行下一句的代码,实在无法理解为何不自动启动应用了。。

问题二:
使用了 selendroid 后,仍然告诉我没有大于 17 的 API 设备,贴 LOG

> Starting Node Server
> info: Welcome to Appium v1.2.0 (REV e53f49c706a25242e66d36685c268b599cc18da5)
> ERROR: debug: Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"19","automationName":"Appium"}
> info: Appium REST http interface listener started on 127.0.0.1:4723
> info: LogLevel: debug
> info: --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformVersion":"4.1.2","automationName":"Selendroid","platformName":"Android","deviceName":"148904d2"}}
> ERROR: debug: Appium request initiated at /wd/hub/session
> ERROR: debug: Request received with params: {"desiredCapabilities":{"appPackage":"com.test.android.app","appActivity":".ui.main.MainActivity","platformVersion":"4.1.2","automationName":"Selendroid","platformName":"Android","deviceName":"148904d2"}}
> info: Retrieving device
> ERROR: debug: Didn't get app but did get Android package, will attempt to launch it on the device
> ERROR: debug: Creating new appium session bbcb99fe-20b2-4436-b552-7ad4c2b2e765
> ERROR: debug: Starting selendroid server
> ERROR: debug: Checking whether selendroid is built yet
> ERROR: debug: Selendroid server exists!
> ERROR: debug: Preparing device for session
> ERROR: debug: Not checking whether app is present since we are assuming it's already on the device
> ERROR: debug: Checking whether adb is present
> ERROR: debug: Using adb from E:\android-sdk-windows\platform-tools\adb.exe
> ERROR: debug: Trying to find a connected android device
> ERROR: debug: Getting connected devices...
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" devices
> ERROR: debug: 1 device(s) connected
> info: Found device 61625b81
> ERROR: debug: Setting device id to 61625b81
> ERROR: debug: Waiting for device to be ready and to respond to shell commands (timeout = 5)
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 wait-for-device
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "echo 'ready'"
> ERROR: debug: Starting logcat capture
> warn: No app capability, can't parse package/activity
> ERROR: debug: Rebuilt selendroid apk does not exist, uninstalling any instances of it on device to make way for new one
> ERROR: debug: Uninstalling com.test.android.app.selendroid
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 shell "am force-stop com.test.android.app.selendroid"
> ERROR: debug: executing: "E:\android-sdk-windows\platform-tools\adb.exe" -s 61625b81 uninstall com.test.android.app.selendroid
> ERROR: debug: App was not uninstalled, maybe it wasn't on device?
> ERROR: debug: Rebuilt selendroid server does not exist, inserting modified manifest
> ERROR: debug: Inserting selendroid manifest
> info: <-- POST /wd/hub/session 500 2712.442 ms - 220 
> ERROR: debug: Checking whether aapt is present
> ERROR: debug: Using aapt from E:\android-sdk-windows\build-tools\20.0.0\aapt.exe
> ERROR: debug: Compiling manifest C:\Windows\Temp\com.test.android.app\AndroidManifest.xml
> ERROR: debug: Cleaning up appium session
> ERROR: error: Failed to start an Appium session, err was: Error: Required platform doesn't exist (API level >= 17)
> ERROR: debug: Error: Required platform doesn't exist (API level >= 17)
> ERROR:     at ADB.compileManifest (E:\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:290:15)
> ERROR:     at null.<anonymous> (E:\Appium\node_modules\appium\lib\devices\android\selendroid.js:390:16)
> ERROR:     at E:\Appium\node_modules\appium\node_modules\async\lib\async.js:610:21
> ERROR:     at E:\Appium\node_modules\appium\node_modules\async\lib\async.js:249:17
> ERROR:     at iterate (E:\Appium\node_modules\appium\node_modules\async\lib\async.js:149:13)
> ERROR:     at E:\Appium\node_modules\appium\node_modules\async\lib\async.js:160:25
> ERROR:     at E:\Appium\node_modules\appium\node_modules\async\lib\async.js:251:21
> ERROR:     at E:\Appium\node_modules\appium\node_modules\async\lib\async.js:615:34
> ERROR:     at ADB.checkSdkBinaryPresent (E:\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:113:5)
> ERROR:     at null.<anonymous> (E:\Appium\node_modules\appium\lib\devices\android\selendroid.js:388:30)
> ERROR: debug: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Required platform doesn't exist (API level >= 17))","origValue":"Required platform doesn't exist (API level >= 17)"},"sessionId":null}

LOG 截止,贴代码,此代码在问题一与问题中无任何修改,仅是否注释 automationName 的参数:

@Before
public void setUp() throws Exception {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "148904d2");
        capabilities.setCapability("platformVersion", "4.1.2");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.test.android.app");
        capabilities.setCapability("appActivity", ".ui.main.MainActivity");
        capabilities.setCapability("automationName", "Selendroid");
        driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),
        capabilities);

    }


↙↙↙阅读原文可查看相关链接,并与作者交流