Appium Appium 报错后查错指南

陈恒捷 · March 14, 2015 · Last by 陈恒捷 replied at October 26, 2016 · 2038 hits
本帖已被设为精华帖!

20150317 Update:增加 appium 官方 issue 和讨论组的链接

很高兴最近论坛用 appium 的人多了不少,但也有不少由于不了解 appium 导致出现错误后不知道从何下手。这里根据我的个人经验给出一个简单的查错指南,不保证能解决所有错误,但至少让你知道你应该朝哪个方向去解决。

1. 阅读 Appium 文档

这是很多人忽略但却是最重要的方法。Appium 的文档说明了 如何正确使用 appium有哪些事情 appium 做不了或者要通过特殊方法做。大部分刚入门的同学的问题在这里面都能找到答案。

中文文档(由 testerhome 开源团队翻译,目前已和官方文档一致):https://github.com/testerhome/appium/tree/master/docs/cn
英文文档:https://github.com/appium/appium/tree/master/docs/en

2. 阅读 Appium log 后查询 google 或 stackoverflow

Appium 的 log 默认使用 debug 级别,所以内容很丰富。如果你懂得正确地阅读,你能很容易地从 google/stackoverflow 找到答案。

PS:不建议用百度。百度搜出来的其实大多都是 testerhome 的……

由于 Appium 的主要结构为:
Android:使用 adb 管理设备及安装应用,使用 UiAutomator/selendriod 驱动对应用的各种操作(找元素、点击等)
iOS:使用 Instruments 管理设备,使用 UiAutomation 驱动对应用的各种操作

因此 Appium 的 log 主要有以下几类:

1、 网络通讯 log(以--><--符号开头):

info: --> GET /wd/hub/status {}

info: <-- GET /wd/hub/status 200 1.335 ms - 104 {"status":0,"value":{"build":{"version":"1.3.4","revision":"c8c79a85fbd6870cd6fc3d66d038a115ebe22efe"}}}

此类 log 一般出现在 Appium client 与 Appium server 通信时,记录原始通信信息。一般出错只是因为下面执行出错然后反馈到上层(出错的话请看 http status code。如上面的状态码是 200,即处理成功)。

2、 Appium Server 内部处理 log(以类似[debug]的 log 级别开头,相比下面其他类型的 log 没有其他特别标志 ):

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.4","revision":"c8c79a85fbd6870cd6fc3d66d038a115ebe22efe"}}}
...
info: [debug] Configuring Safari session
info: [debug] We're on iOS8+ so not copying mobile safari app
info: [debug] Creating new appium session 59f933a1-ee07-45d3-bbec-cabfe89735d8
info: [debug] Removing any remaining instruments sockets
info: [debug] Cleaned up instruments socket /tmp/instruments_sock
info: [debug] Setting Xcode folder

此类 log 是 appium server 内部 log,出现频率最高,用于说明此时 Appium server 内部正在做什么(调用其他工具、创建会话等)。如果这里出错且无下面三类错误,那是 appium server 的错误。

3、 Apple Instruments log(log 内容中有额外时间戳。如果用.app 看,log 颜色为绿色):

info: [debug] [INST] 2015-03-13 23:31:59 +0000 Debug: evaluation finished

info: [debug] [INST] 2015-03-13 23:31:59 +0000 Debug: responding with:
info: [debug] [INST] 2015-03-13 23:31:59 +0000 Debug: Running system command #1: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":true}...

此类 log 为 Instruments 的 log,Appium 只是为了让大家方便查看而附在 appium log 里面。此类 log 出错请找 Instruments。

4、 Android UiAutomator log(以[UIAUTOMATOR STDOUT][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=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...

此类 log 为 UiAutomator 的 log。其中[UIAUTOMATOR STDOUT]是启动 UiAutomatorTestRunner 的 log,[BOOTSTRAP]是 Appium 装在被测设备上的 BOOTSTRAP 工具的 log(由于 UiAutomator 必须在 Android 系统上运行,所以 Appium 做了一个特殊的 UiAutomator 的测试用例在被测设备上接收 Appium 命令并执行命令)。此处 log 出错请找 UiAutomator(虽然 BootStrap 也是 Appium 的一部分,但一般是调用 UiAutomator API 时出错)。

5、 Selendroid log(以[SELENDROID]开头):

info: [debug] [SELENDROID] mSeq=0 mSystemUiVisibility=0x0
info: [debug] [SELENDROID] mSystemDecorRect=[0,38][480,728] last=[0,38][480,728]

此类 log 为 Selendroid 内部处理的 log。此处出错请找 Selendroid。

3. 根据出错信息查询 appium 官方 issue 和讨论组以及 testerhome(建议 google 前先看这些地方):

issue:https://github.com/appium/appium/issues
讨论组:https://discuss.appium.io/
testerhome:http://testerhome.com/

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

很赞!!

我觉得后续有不同的错误,解决了后可以回复此帖就好了

@xuxu 好主意,欢迎各位遇到其它错误后在这里跟帖补充,让新手们更快学会自主解决问题。

#2 楼 @xuxu 到时候这个帖子沉下去估计就没人看到了并回复了. 这篇文章写的很好. 另外对于深入的报错, 可以借助一些插桩工具做测试.我们公司 oneapm 目前已经支持了 nodejs 和 android 的监控. 到时候可以融合进去, 直接定位到出错的代码行, 这样就算没有 log, 也可以定位原因了.

@seveniruby 我相信对于会使用搜索功能的有心人,帖子再怎么沉下去,也会对其有帮助并回复帖子的!

#4 楼 @seveniruby 我建议增加置顶帖这个功能,把一些小白经常问的问题放在置顶帖。
你说的功能非常不错!能具体说说吗?应用源代码变更量大吗?

#6 楼 @chenhengjie123 置顶帖有啊。但是置顶帖不宜过多。

#7 楼 @lihuazhang 有这功能吗?
我看到首页的帖子貌似每天都在变,最前面的总是最新的。

我觉得有些帖子还是需要置顶的,可以仿照其他论坛把置顶帖做成合集,甚至把某个 wiki 置顶也行。如【安装包】Appium 国内下载地址(百度云盘,已更新至 1.3.6),这个帖子就很值得置顶。

#8 楼 @chenhengjie123 这个帖子以前置顶过,后来有更需要置顶的帖子出现,就把它放到侧边栏了~等置顶区域没什么特别重要的内容时再考虑置顶这个帖子~
wiki 的话,估计现阶段,适合把 appium 的中文 doc 和最新版本的应用实例写进 gitbook~然后放置顶帖了~

nice~不过感觉 appium 的 log 跑太快~回看又有点乱(这也是自己打 log 的原因吧)~mark 学习了~

写得非常好。

mark 一个~~

想问下 怎么把 sever 的 log 导出本地 log 文件呢?(如果可以 能否配置筛选 log 等级的 类似 log4j 这样子)

陈恒捷 #14 · March 31, 2015 Author

log 等级和 log 记录到哪个文件都是可以配置的。命令行关于 log 的参数配置:

-g LOG, --log LOG     Also send log output to this file
--log-level {info,info:debug,info:info,info:warn,info:error,warn,warn:debug,warn:info,warn:warn,warn:error,error,error:debug,error:info,error:warn,error:error,debug,debug:debug,debug:info,debug:warn,debug:error}
                      log level; default (console[:file]): debug[:debug]
--log-timestamp       Show timestamps in console output
--log-no-colors       Don't use colors in console output
--show-sim-log        (IOS-only) if set, the iOS simulator log will be
                      written to the console
--show-ios-log        (IOS-only) if set, the iOS system log will be written
                      to the console
--debug-log-spacing   Add exaggerated spacing in logs to help with visual
                      inspection

用图形化界面的看看各个设置页面,里面有的。

不错,给我们这些新人很多引导,谢谢

写的很用心,支持

掌握 appium 很有帮助,支持!!!,必须收藏

陈恒捷 [Topic was deleted] 中提及了此贴 26 Oct 15:46
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up