Appium 已解决:使用手机可以启动进入应用,但是任何操作都不行。

付兰 · 2016年09月08日 · 最后由 付兰 回复于 2017年04月18日 · 1484 次阅读

测试环境:Appium v1.4.16+android6.0.1
测试代码如下:

#coding=utf-8
from appium import webdriver

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = '1df0f13d'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

driver.find_element_by_name("1").click()

driver.find_element_by_name("5").click()

driver.find_element_by_name("9").click()

driver.find_element_by_name("delete").click()

driver.find_element_by_name("9").click()

driver.find_element_by_name("5").click()

driver.find_element_by_name("+").click()

driver.find_element_by_name("6").click()

driver.find_element_by_name("=").click()

driver.quit()

测试时可以进入计算器,但是点击就报错了,

> info: --> POST /wd/hub/session {"desiredCapabilities":{"deviceName":"1df0f13d","appActivity":".Calculator","platformVersion":"6.0","appPackage":"com.android.calculator2","platformName":"Android"}}
> info: Client User-Agent string: Python-urllib/3.5
> info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
> info: [debug] Creating new appium session bbb18055-561a-40a2-bfc5-bf93b7c9069d
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_91
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from E:\android-sdk\platform-tools\adb.exe
> warn: No app capability, can't parse package/activity
> info: [debug] Using fast reset? false
> info: [debug] Preparing device for session
> info: [debug] Not checking whether app is present since we are assuming it's already on the device
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device 1df0f13d
> info: [debug] Setting device id to 1df0f13d
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d wait-for-device
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 23
> info: Device API level is: 23
> info: [debug] Extracting strings for language: default
> info: [debug] Apk doesn't exist locally
> info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "rm -rf /data/local/tmp/strings.json"
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Skipping install since we launched with a package instead of an app path
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d forward tcp:4724 tcp:4724
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d push "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
> info: [debug] Pushing settings apk to device...
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> info: [debug] Pushing unlock helper app to device...
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
> info: Starting App
> info: [debug] Attempting to kill all 'uiautomator' processes
> info: [debug] Getting all processes with 'uiautomator'
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "ps 'uiautomator'"
> info: [debug] No matching processes found
> info: [debug] Running bootstrap
> info: [debug] spawning: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.android.calculator2 -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
> info: [debug] [BOOTSTRAP] [debug] Loading json...
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> info: [debug] Waking up device if it's not alive
> info: [debug] Pushing command to appium work queue: ["wake",{}]
> info: [debug] [BOOTSTRAP] [debug] Client connected
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: wake
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window"
> info: [debug] Screen already unlocked, continuing.
> info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data"}
> info: [debug] dataDir set to: /data
> info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":false}
> info: [debug] Getting device API level
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 23
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.android.calculator2/.Calculator"
> info: [debug] Waiting for pkg "com.android.calculator2" and activity ".Calculator" to be focused
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> info: [debug] Getting focused package and activity
> info: [debug] executing cmd: E:\android-sdk\platform-tools\adb.exe -s 1df0f13d shell "dumpsys window windows"
> error: com.android.calculator2/.Calculator never started. Current: com.android.calculator2/.Calculator,
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] [BOOTSTRAP] [debug] Closed client connection
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
> info: [debug] [UIAUTOMATOR STDOUT] Time: 22.544
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] UiAutomator shut down normally
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> error: Failed to start an Appium session, err was: Error: com.android.calculator2/.Calculator never started. Current: com.android.calculator2/.Calculator,
> info: [debug] Error: com.android.calculator2/.Calculator never started. Current: com.android.calculator2/.Calculator,
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1314:12)
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1258:7)
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
>     at ChildProcess.exithandler (child_process.js:742:7)
>     at ChildProcess.emit (events.js:110:17)
>     at maybeClose (child_process.js:1016:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:1088:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: com.android.calculator2/.Calculator never started. Current: com.android.calculator2/.Calculator,)","origValue":"com.android.calculator2/.Calculator never started. Current: com.android.calculator2/.Calculator,"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 26817.004 ms - 314 

来个好人帮忙,谢谢!!

解决方式:更新到新版本,安装了 1.6.4 的 desktop 就可以了。

共收到 17 条回复 时间 点赞

是不是 activity 不正确的原因呢?.Calculator 貌似我的手机上 activity 就不是这个,也是菜鸟,猜测

嗯,换个 activity 试试

你用的是真机测试吧,你看你手机里的计算器的包名、应用名叫啥,这个脚本写的计算器包名和应用名是安卓原生的,所以一般用来测模拟器是没问题的。你看你的 appium 设置的端口是不是 4723。

#1 楼 @rik782 都是菜鸟。我获取的 activity 就是这个,要命的是他可以启动进去,就是点击不了

#3 楼 @WeiNa 😤 获取的设置什么都是对的,我换了个应用也是报这个错,天啊

error: com.android.calculator2/.Calculator never started. Current: com.android.calculator2/.Calculator
有点懵逼。。

@a3096556718 ,试试下面这个,

看报错是

info: [debug] Waiting for pkg "com.android.calculator2" and activity ".Calculator" to be focused
> info: [debug] Getting focused package and activity

提示没有获取到 package 名和 activity 名,试试使用 driver.start_activity('packagename','activityname') 试试

本人新手

@a3096556718 楼主问题解决了吗?之前后端 qa,移动端完全小白,被同样的问题卡一天了,前后 activity 名字一模一样,就是报错,看 logcat 貌似是约 50s 后 activity 才再次变成 I am_focused_activity,不知道是不是这个的原因😀

哈哈哈 我之前也遇到过 结果是报名前边多了个空格 我把空格去掉就 OK 当时错误提示跟你的提示一样

#9 楼 @boxiangcen 我测试的 app 的 launcher 是一个欢迎页面,启动显示欢迎页面后会进入 home 页面
在有的手机上会出现这样的问题,有的手机上就没有这样的问题。网上查了不少,也还没找到原因
试过指定 appWaitActivity,还是不好用
[debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: com.example.test/.ui.FirstActivity never started. Current: com.example.test/.ui.FirstActivity,)","origValue":"com.example.test/.ui.FirstActivity never started. Current: com.example.test/.ui.FirstActivity,"},"sessionId":null}
显示未启动的 Activity 和当前 Activity 是一样的,还报错。。。

#7 楼 @rik782 %SystemRoot%system32 一般本来就在 Path 中存在的,我看我的 PATH 中有

@a3096556718 @Pastel @boxiangcen 这个问题解决了吗

此问题和手机有关,换个手机就 ok 了

楼主解决了吗?我也被这个问题困扰好久了。解决了帮下忙。我的 qq865349382

换手机或者更新 Appium 版本可以解决

付兰 #17 · 2017年04月18日 Author
王中生 回复

今天更新版本到 1.6.4 可以了,用命令更新搞死了升不上去,直接下载了个 appium desktop 就可以了

付兰 关闭了讨论 04月18日 14:40
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册