Appium appium ios 自定义 UIViewController 导致 inspector 无法获取元素的解决方案

songz · 2016年04月22日 · 最后由 songz 回复于 2016年05月30日 · 2294 次阅读

问题:
我司的 ios app,主页面上的功能,为了做成卡片式的效果,采用了自定义的 UIViewController like this
用 appium inspector 无法获取元素,page source 打出来没有,ui automation 录制也录不到,简直愁死了。如果旁边有条狗。。。就。。扯远了。。言归正传,附上解决方法。
解决方法:

iOS Support

See Running on OS X: iOS for iOS requirements and setup instructions.

Versions: 7.1, 8.0, 8.1, 8.2, 8.3, 8.4, 9.0, 9.1 and 9.2 Devices:
iPhone Simulator, iPad Simulator, and real iPhones and iPads Native
app support: Yes, with debug version of .app (simulator), or
correctly-signed .ipa (real devices). Underlying support is provided
by Apple's UIAutomation framework. Mobile web support: Yes, via
automation of mobile Safari. For real devices,
ios-webkit-remote-debugger is required, and automation of native
aspects of the Safari interface is not possible. See the mobile web
doc for instructions. Hybrid support: Yes. For real devices,
ios-webkit-remote-debugger is required. See the hybrid doc for
instructions. Support for automating multiple apps in one session: No
Support for automating multiple devices simultaneously: No Support for
automating vendor-provided or third-party apps: Only vendor-provided
apps (Preferences, Maps, etc...), and only on the simulator Support
for automating custom, non-standard UI controls: Minimal. You need to
set accessibility information on the control which enables some basic
automation.

appium 的 github 上更新了关于自定义,非标准控件的内容,原为不支持,现在更新为可以通过设置 accessibility 信息来做基本的自动化操作。
在群里经过恒温的点播,动手打开源码,试验一番。
在.storyboard 中找到之前让我蛋疼让我忧无法定位到的控件,查看它的属性。这个 accessbility 不就是我需要的 accessbility info 吗,不妨一试,将属性改为上图所示。build 一把,跑起来,用 inspector 查看,之前无法获取的元素都都出现了。like this
可以看到该 view 下面的元素,都可以被识别到了。问题又来了,被识别出来的其它元素,name 和 label 属性也有值,它们并不是在 accessbility 里设置的,如果是的话也不会造成我遇到的问题了,那它们是在哪里被赋值的?又查了一把,发现是在源码中赋值的。还存在一些问题,不过至少能识别到自定义 UIViewController 下的元素了。还是比较欣慰的,在此分享下我的解决方法。

共收到 7 条回复 时间 点赞

这个其实是 uiautomation 的本质

#1 楼 @lihuazhang 嗯,关于 UI Testing 的之前没有了解,学习了一把,Accessibility 这功能的确很方便

中间那段引用看到眼都花了。。。

这种情况还算好了,至少里面元素都继承了 UIView ,都是一个个独立的界面控件。如果是自绘的控件就直接可以跪了。

后面继续加油!这类控件在 xib 上不好操作,所以 Accessibility 一般会直接用代码来写。

#3 楼 @chenhengjie123 嗯嗯好的一起加油!

#3 楼 @chenhengjie123 恒洁恒洁,关于这个问题。。还有个疑问。目前我是通过坐标点入口,page_source 里才会打出 CustomView 里面的元素,还是概率性的。。一般是第二次进入才行。如果是通过入口的控件点进去。。就无法获取到内部元素,这个问题困扰了好久😢

#5 楼 @neyo 这种情况得看应用源码,看是怎么触发 CustomView ,怎么实现 Accessibility 方法才知道了。

#6 楼 @chenhengjie123 好滴,谢啦~我再去折腾折腾

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