Appium 4.2.2 系统设备上用 findElementsByClassName 方法或 findElementsByAndroidUIAutomator 方法报错

abyssalknight · 2014年12月22日 · 最后由 衔尾蛇 回复于 2015年01月08日 · 1897 次阅读

我想用 appium 跑安卓所有系统版本的自动化,抛开 4.1 以下的 selendroid 模式不谈,我连用 4.2 的系统也有问题,appium 官方不是说支持 sdk>=17 的吗?以下是报错 log,感觉是 appium 的 bug 啊,有同学知道如何解决吗?

> info: --> POST /wd/hub/session/90fe7172-7ac1-4f8b-8d6e-d7bf4dd9ab0b/elements {"using":"class name","value":"android.widget.RadioButton"}
> info: [debug] Waiting up to 10000ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"class name","selector":"android.widget.RadioButton","context":"","multiple":true}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"class name","selector":"android.widget.RadioButton","context":"","multiple":true}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding android.widget.RadioButton using CLASS_NAME with the contextId:  multiple: true
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.RadioButton]
> info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[CLASS=android.widget.RadioButton]
> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (0)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[CLASS=android.widget.RadioButton, INSTANCE=0]
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Error in testRunServer:
> info: [debug] [UIAUTOMATOR STDOUT] java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElement.<init>(AndroidElement.java:26)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.addElement(AndroidElementsHash.java:47)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.getElements(AndroidElementsHash.java:155)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.fetchElements(Find.java:167)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.execute(Find.java:104)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidCommandExecutor.execute(AndroidCommandExecutor.java:64)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.runCommand(SocketServer.java:168)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.handleClientData(SocketServer.java:89)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.listenForever(SocketServer.java:133)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.Bootstrap.testRunServer(Bootstrap.java:16)
> info: [debug] [UIAUTOMATOR STDOUT] at java.lang.reflect.Method.invokeNative(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:144)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:87)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:90)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
> info: [debug] [UIAUTOMATOR STDOUT] at dalvik.system.NativeStart.main(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stack=java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElement.<init>(AndroidElement.java:26)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.addElement(AndroidElementsHash.java:47)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.getElements(AndroidElementsHash.java:155)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.fetchElements(Find.java:167)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.execute(Find.java:104)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidCommandExecutor.execute(AndroidCommandExecutor.java:64)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.runCommand(SocketServer.java:168)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.handleClientData(SocketServer.java:89)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.listenForever(SocketServer.java:133)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.Bootstrap.testRunServer(Bootstrap.java:16)
> info: [debug] [UIAUTOMATOR STDOUT] at java.lang.reflect.Method.invokeNative(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:144)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:87)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:90)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
> info: [debug] [UIAUTOMATOR STDOUT] at dalvik.system.NativeStart.main(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.E
> info: [debug] [UIAUTOMATOR STDOUT] Time: 16.652
> info: [debug] [UIAUTOMATOR STDOUT] FAILURES!!!
> info: [debug] [UIAUTOMATOR STDOUT] Tests run: 1,  Failures: 0,  Errors: 1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] UiAutomator exited
> info: [debug] executing cmd: E:\adt-bundle-windows-x86_64-20131030\sdk\platform-tools\adb.exe -s 0123456789ABCDEF shell "echo 'ping'"
> info: [debug] Attempting to uninstall app
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Cleaning up android objects
> info: [debug] Waited for 441ms so far
> info: [debug] Cleaning up appium session
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"class name","selector":"android.widget.RadioButton","context":"","multiple":true}]
> info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"Tried to send command to non-existent Android device, maybe it shut down?"},"sessionId":null}
> info: <-- POST /wd/hub/session/90fe7172-7ac1-4f8b-8d6e-d7bf4dd9ab0b/elements 500 956.105 ms - 208 
> info: --> DELETE /wd/hub/session/90fe7172-7ac1-4f8b-8d6e-d7bf4dd9ab0b {}
> info: <-- DELETE /wd/hub/session/90fe7172-7ac1-4f8b-8d6e-d7bf4dd9ab0b 404 3.373 ms - 40 
> Update not available
> Killed Node Server.
> Node Server Process Ended

共收到 7 条回复 时间 点赞

官方的说明是指 api17 以上, 不包括 api17. 你可以用 api18 试试. 这个错误前几天有人发过帖子讨论了
就是这个错误
java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator

4.2 版本应该是 api18 了吧. 你用的 appium 版本是多少, 我还没研究最新的框架.

我的也是这样,手机 4.2.2,appium 版本 1.3.4

info: [debug] [UIAUTOMATOR STDOUT] at dalvik.system.NativeStart.main(Native Method)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.E
info: [debug] [UIAUTOMATOR STDOUT] Time: 18.08
info: [debug] [UIAUTOMATOR STDOUT] FAILURES!!!
info: [debug] [UIAUTOMATOR STDOUT] Tests run: 1,  Failures: 0,  Errors: 1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] UiAutomator exited
info: [debug] executing cmd: /home/hanz/android-sdk-linux/platform-tools/adb -s MSM8974 shell "echo 'ping'"
info: [debug] Attempting to uninstall app
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Cleaning up android objects
info: [debug] Condition unmet after 744ms. Timing out.
info: [debug] Responding to client with error: {"status":13,"value":{"message":"UiAutomator died while responding to command, please check appium logs!","name":"UnknownError","origValue":"UiAutomator died while responding to command, please check appium logs!"},"sessionId":"65bfaf39-b7df-4035-bcd8-415304d1aa73"}
info: <-- POST /wd/hub/session/65bfaf39-b7df-4035-bcd8-415304d1aa73/elements 500 745.840 ms - 266 
info: [debug] Cleaning up appium session
info: --> DELETE /wd/hub/session/65bfaf39-b7df-4035-bcd8-415304d1aa73 {}
info: <-- DELETE /wd/hub/session/65bfaf39-b7df-4035-bcd8-415304d1aa73 404 1.150 ms - 40 

我的也是 Appium v1.3.4 用 classname 不行

遇到相同问题,准备换高版本的 Android 试试

那低版本的用什么办法来获取控件呢

之前我也遇到这个问题。
4.2.2 的系统的 api 是 17,升级到 19 后就可以使用 class_name 进行定位。

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