Appium 【结贴】在 Appium 中使用 Slendroid 模式时,出现 android.util.AndroidException 的报错导致无法启动 session

大东 · 2015年05月06日 · 最后由 杨! 回复于 2015年06月05日 · 1788 次阅读

前提

1、真机-4.2.2
2、在 Appium 模式下是正常起 session 的
3、desired_caps 配置了'app'
4、appium -UdevieceID的形式启动 APPIUM
5、Appium@1.3.7

出现问题

当在 desired_caps 配置了'automationName':'selendroid'之后,出现无法起 session 的错误。

server 端的 log 为

info: [debug] Screen already unlocked, continuing.
info: [debug] executing cmd: D:\AndroidSDK+Eclipse+ADT\adt-bundle-windows-x86_64-20131030\
sdk\platform-tools\adb.exe -s YSLREATWNFSO6SSO shell "am instrument -e main_activity 'com.
hujiang.hjclass.activity.SplashActivity' com.hujiang.hjclass.selendroid/io.selendroid.serv
er.ServerInstrumentation"
error: android.util.AndroidException: INSTRUMENTATION_FAILED: com.hujiang.hjclass.selendro
id/io.selendroid.server.ServerInstrumentation

        at com.android.commands.am.Am.runInstrument(Am.java:676)

        at com.android.commands.am.Am.run(Am.java:119)

        at com.android.commands.am.Am.main(Am.java:82)

        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)

        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:276)

        at dalvik.system.NativeStart.main(Native Method)
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: android.util.AndroidException: I
NSTRUMENTATION_FAILED: com.hujiang.hjclass.selendroid/io.selendroid.server.ServerInstrumen
tation

info: [debug] Error: android.util.AndroidException: INSTRUMENTATION_FAILED: com.hujiang.hj
class.selendroid/io.selendroid.server.ServerInstrumentation

    at C:\Users\huangweidong\AppData\Roaming\npm\node_modules\appium\node_modules\appium-a
db\lib\adb.js:1391:17
    at null.<anonymous> (C:\Users\huangweidong\AppData\Roaming\npm\node_modules\appium\nod
e_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 sess
ion could not be created. (Original error: android.util.AndroidException: INSTRUMENTATION_
FAILED: com.hujiang.hjclass.selendroid/io.selendroid.server.ServerInstrumentation\r\r)","o
rigValue":"android.util.AndroidException: INSTRUMENTATION_FAILED: com.hujiang.hjclass.sele
ndroid/io.selendroid.server.ServerInstrumentation\r\r"},"sessionId":null}
info: <-- POST /wd/hub/session 500 13698.893 ms - 386

client 部分的代码

import time
from appium import webdriver
desired_caps = {
            'automationName':'selendroid',
            'platformName' : 'Android',
            'platformVersion': '4.2.2',
            'appPackage': 'com.hujiang.xxxx',
            'appActivity': '.activity.xxxxxx',
            'app':app,
            'deviceName' : 'SS5',
        }
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(5)
driver.find_elements_by_class_name('android.widget.Button')[1].click()

我比较奇怪的是在日志前半部分会看到这句

info: [debug] Selendroid server exists!

个人猜测

会是因为 selendroid 的 server 已经存在的关系吗?
有在 github 上看到出现一样的 log 的帖子:https://github.com/appium/appium/issues/2916
但是我并没有通过 jar 的形式去启动 selendroid 的服务,还是说我有服务没关掉我不知道?

结论
没搞清楚原因,若还有出现这个问题的同学,建议将手机里的 selendroid 服务和 app 删除干净,然后再跑跑看吧少年。

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 12 条回复 时间 点赞

#8 楼 @sanlengjingvv 没有被占用啊,但是提示 (Original error: Command failed: /bin/sh -c /Users/apple/Desktop/software/sdk/platform-tools/adb -s CB5A23RRPE forward tcp:8080 tcp:8080

楼主,我这边改为 8080 端口的时候却提示这个:org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: /bin/sh -c /Users/apple/Desktop/software/sdk/platform-tools/adb -s CB5A23RRPE forward tcp:8080 tcp:8080,不知道你那个问题解决了没呢

跟踪了一个类似问题:
第一次跑报 error: Unhandled error: TypeError: Arguments to path.resolve must be strings
第二次再跑就报楼主的错误了
如果有遇到相同问题可以尝试:
1.查看 JAVA_HOME 有没有设置
2.删除 C:\Users\Administrator\AppData\Local\Temp 目录下被测 APP 文件夹和 “selendroid.被测包名”
3.重新卸载手机上的被测 APP 和 selendroid

@sanlengjingvv 我没注意端口的问题,我在网上找到了一个解决办法,http://selvakr208.blogspot.com/
就是用 adb install 把 APK 在手机上装一次就好了,具体我不是很懂,是帖子里的第二个问题,我就是安装了 apk 一下,其他的步骤我也没操作。

#7 楼 @xdlhy 看下 8080 端口有没有占用?

楼主找到问题的原因和解决办法了么?我用 4.1 的真机也遇到类似的问题了

#4 楼 @chenhengjie123
#5 楼 @xiaoyan
我了个去...
其实我啥也没干,我放到 osx 上去跑了一次,竟然跑通了,回到 Windows 跑,也通了。尼玛,我还什么都没做呢。

应该这个帖子http://stackoverflow.com/questions/14269687/android-util-androidexception-instrumentation-failed/17508003#17508003adb比较好跟踪,根据帖子意思是查看 shell pm list instrumentation,看看有没有 com.hujiang.hjclass.selendro
id/io.selendroid.server.ServerInstrumentation

#2 楼 @chenhengjie123
打出恒洁来的时候没忍住~哈哈
重启了手机其实也是一样的。
我已经尝试过删除 xxx.xxx.xxx.selendroid 这个东西了,不凑效~

#1 楼 @anikikun 我擦,我怎么成姐姐了。。。我也是哥哥啊。。。
你重启一下手机试试?如果确实是由于已经有 selendroid 服务在跑,重启后应该就关掉了。

360 度冰天雪地裸体跪求恒温哥哥恒洁姐姐 Q 大爷猴哥速速现行~先干活去了

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