Appium [已解决] Appium 运行报错:error: Failed to start an Appium session, err was:Activity never started.

suxiaomo · 2015年03月30日 · 最后由 多久没有爱了 回复于 2018年07月30日 · 4029 次阅读

(额,各位大侠,我是新人菜鸟,求轻拍~~ps:头像不是我不想传喔,点击修改头像的链接报错 “504 网关超时”,maybe 是我网络太差吧

问题是这样的:
包名和 activity 没有问题,执行 python 脚本,app 可以启动,但是在注册界面后,就不跑了,报错。error: Failed to start an Appium session, err was: Error: com.syswin.toon/.activity.login.WelcomeActivity never started. Current: com.syswin.toon/.activity.login.VerifyActivity

补充:今天下午在 dr = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) 后面每一行之间都加了一句 print ,跑通过一次。但是由于从注册界面进入登录界面后,输入账号密码后键盘挡住了登录按钮,失败。之后就再也没跑成功。
求各位大侠指点一下~谢谢!

----------------------------------------------------------以下是 pytho 脚本~~-------------------------------------------------------------

import unittest
import os
from appium import webdriver
from time import sleep

desired_caps = {}
desired_caps['platformName'] = 'Android'                       
desired_caps['platformVersion'] = '4.4.4 KTU84P'              
desired_caps['deviceName'] = '11f68396'                
desired_caps['appPackage'] = 'com.syswin.toon'                 
desired_caps['appActivity'] = '.activity.login.WelcomeActivity' 
dr = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
dr.find_element_by_id("com.syswin.toon:id/tv_change_account").click()  
dr.find_element_by_id("com.syswin.toon:id/et_phone").send_keys("18500231523")
dr.find_element_by_id("com.syswin.toon:id/et_password").send_keys("111111")
dr.find_element_by_id("com.syswin.toon:id/btn_login").click() 
print 'login success!'

-----------------------------------------------------以下是错误报告-------------------------------------------------------------------------------------------
info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.4.4
KTU84P","deviceName":"11f68396","platformName":"Android","appActivity":".activit
y.login.WelcomeActivity","appPackage":"com.syswin.toon"}}
info: Client User-Agent string: Python-urllib/2.7
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 b3854f44-eff2-43ab-9f52-ff59676f3fcb
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_40
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it's alr
eady on the device
info: [debug] Checking whether adb is present
info: [debug] Using adb from E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device 11f68396
info: [debug] Setting device id to 11f68396
info: [debug] Waiting for device to be ready and to respond to shell commands (t
imeout = 5)
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 wait-for-device
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "echo 'ready'"
info: [debug] Starting logcat capture
warn: No app capability, can't parse package/activity
info: [debug] Getting device API level
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: Device API level is: 19
info: [debug] Apk doesn't exist locally
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 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 ap
p path
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 push "E:\Automation2\AppiumForWindows-1.
3.4.1\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.j
ar" /data/local/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 install "E:\Automation2\AppiumForWindows-1
.3.4.1\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 install "E:\Automation2\AppiumForWindows-1
.3.4.1\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:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: E:\Automation2\adt-bundle-windows-x86_64-20140702\sdk\pl
atform-tools\adb.exe -s 11f68396 shell uiautomator runtest AppiumBootstrap.jar -
c io.appium.android.bootstrap.Bootstrap
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=UiAutomatorTestRun
ner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.andro
id.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] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window"
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
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: {"value":"\/data\/local\/tmp
","status":0}
info: [debug] dataDir set to: /data/local/tmp
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: {"value":false,"status":0}
info: [debug] Getting device API level
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "am start -S -a android.intent.actio
n.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.syswin.toon/.act
ivity.login.WelcomeActivity"
info: [debug] Waiting for pkg "com.syswin.toon" and activity ".activity.login.We
lcomeActivity" to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
info: [debug] Getting focused package and activity
info: [debug] executing cmd: E:\Automation2\adt-bundle-windows-x86_64-20140702\s
dk\platform-tools\adb.exe -s 11f68396 shell "dumpsys window windows"
error: com.syswin.toon/.activity.login.WelcomeActivity never started. Current: c
om.syswin.toon/.activity.login.VerifyActivity
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: {"value":"OK, shutting down"
,"status":0}
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=UiAutomatorTestRun
ner
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.andro
id.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.815
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.syswin.toon/.activ
ity.login.WelcomeActivity never started. Current: com.syswin.toon/.activity.logi
n.VerifyActivity
info: [debug] Error: com.syswin.toon/.activity.login.WelcomeActivity never start
ed. Current: com.syswin.toon/.activity.login.VerifyActivity
at null. (E:\Automation2\AppiumForWindows-1.3.4.1\Appium\node_mod
ules\appium\node_modules\appium-adb\lib\adb.js:1298:12)
at null. (E:\Automation2\AppiumForWindows-1.3.4.1\Appium\node_mod
ules\appium\node_modules\appium-adb\lib\adb.js:1242:7)
at null. (E:\Automation2\AppiumForWindows-1.3.4.1\Appium\node_mod
ules\appium\node_modules\appium-adb\lib\adb.js:172:9)
at ChildProcess.exithandler (child_process.js:735:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1008:16)
at Process.ChildProcess._handle.onexit (child_process.js:1080:5)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"
A new session could not be created. (Original error: com.syswin.toon/.activity.l
ogin.WelcomeActivity never started. Current: com.syswin.toon/.activity.login.Ver
ifyActivity)","origValue":"com.syswin.toon/.activity.login.WelcomeActivity never
started. Current: com.syswin.toon/.activity.login.VerifyActivity"},"sessionId":
null}
info: <-- POST /wd/hub/session 500 46583.539 ms - 358

共收到 21 条回复 时间 点赞

你确定.activity.login.WelcomeActivity是 launcher?
从 log 来看,启动的 activity 是.activity.login.VerifyActivity,不是.activity.login.WelcomeActivity
我猜测.activity.login.WelcomeActivity是启动引导页,只有首次安装才会出现。

两个 activity 都有 log 吗?
你可以用 logcat 看看到底起来的是哪个 activity。我从 appium 的 log 看到就是起来的不是.activity.login.WelcomeActivity,而且 appium 等待了一段时间后这个 activity 还是没起来,所以才会报错。

写.activity.login.WelcomeActivity,app 可以启动起来,但是进入第一个界面后就报错了:error: Failed to start an Appium session, err was: Error: Permission to start activity denied.;
我也试过修改为.activity.login.VerifyActivity,然后 app 启动不起,报错是:error: Failed to start an Appium session, err was: Error: Permission to start activity denied.
@chenhengjie123

木有权限?貌似 appium 是用类似外部启动的方法来启动你指定的 activity 的。
那你试试不指定 activity 来启动?

我试过直接指定 path 从本地安装到手机上,不指定 activity 和 package,依然是提示 welcomeactivity 起不来。
@chenhengjie123

现在问题解决了:解决方法是先登录,然后再执行脚本,就没有问题了。估计跟我们的 app 自己的实现有关。
@chenhengjie123

其实上次的解决方法是不对的,先登录知识绕开了注册的过程,没有解决根本问题。最终解决根本问题是在 desired_caps['appActivity'] 后面加了 desired_caps['waitappActivity'] = '.activity.login.VerifyActivity'

#8 楼 @suxiaomo 你所说的先登录是你手动进行登录吗?

运行 demo 时,提示 error: Failed to start an Appium session, err was: Error: apk does not have INTERNET permissions. Selendroid needs internet permission to proceed, please check if you have in your AndroidManifest.xml
已经添加 ,可还是报错怎么解决呢?

各位大神,我现在只能安装上 app,启动不了 app 啊。

error: Unhandled error: Error: getaddrinfo ENOENT
at Object.exports._errnoException (util.js:746:11)
at errnoException (dns.js:49:15)
at GetAddrInfoReqWrap.onlookup as oncomplete context: [POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.4.2","deviceName":"b91b9b66","app":"D:\android\app\rtring_c_zhengyuan.apk","platformName":"Android"}}]
info: [debug] [BOOTSTRAP] [debug] json loading complete.
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: <-- POST /wd/hub/session - - ms - -
undefined

感觉 driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
这句就没过去,有人知道怎么解决吗

我也遇到过楼上的问题,有的手机能行,有的手机不行

Aquarius、 [该话题已被删除] 中提及了此贴 08月03日 18:06

#12 楼 @fullsen 是的,有的机器有问题,现在解决了吗?

#12 楼 @fullsen 同问,这个问题解决了么

😩 楼楼,你的问题解决了么~我遇到了一模一样的问题,百度了 N 种方法,都解决不了。心好累~呜呜

这都是 15 年 3 月的问题了。😭
我真的解决不了了……

》》最终解决根本问题是在 desired_caps['appActivity'] 后面加了 desired_caps['waitappActivity'] = '.activity.login.VerifyActivity'

我也加了 desired_caps['waitappActivity'],但是也报错,提示 activity never start, current activity…😭

这个问题我来回答下:
要加上这行类似这样的代码:
desired_caps['appWaitActivity'] = 'com.opera.android.OperaMainActivity'

如果 app 能起来,说明不是 adb 的问题,它报错说 activity 没能找到,那就把哪个 activity 加在 appWaitActivity 上面。
这个原因是因为,有些 activity 要想起来,必须依赖某个 activity。我之前遇到过,加上这行代码就不报错了。

看下英文版解释:
appWaitActivity: A new session could not be created
While exploring Appium with mobile devices I hit the following error

WebDriverException: Message: u’A new session could not be created. (Original error: atpwta.live/.activity.Main never started. Current: atpwta.live/.activity.root.TournamentList)’

So why did appWaitActivity help?
A simplified (but technically incorrect) way of understanding this error is that Appium was waiting for a screen name .activity.Main and timed out. The error helpfully tells you the current active screen is .activity.root.TournamentList. The desired capability appWaitActivity tells Appium what Android activity it should wait for. If you see a similar error, set your appWaitActivity to match the current activity in the error message.

mutou 回复

升级 appium 版本试一试。我也遇到过类似的问题,appium 版本是 1.4.16,在乐视的手机上碰到了这样的问题(其他的手机不会),然后升级 appium 版本到 1.5.3,就可以了。

https://github.com/appium/appium/issues/3514 记录一下这个相关 issue,与解决方法无关。

我也遇到乐视手机这个问题,坑了我几天,换其他手机就没有问题~坑啊我也升级 appium 得了

mutou 回复

你现在解决了 可不可以留个联系方式一起交流一下 我也是遇到这种问题了

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册