关于Appium的坑

    作为一个IT测试工程师,由于种种原因,又开始关注UI自动化了,APP自动化,iOS和Android的,几个月前,搞了一段儿时间,接触到了Android官网的UIAutomator和Appium。大家比较喜欢Appium,所以,再次接触一下,把以前的case和Demo拿出来,试验了一下,结果各种跑不通,最后一次接触的时候,appium更新到了1.3,现在都1.4.13了。

    这个开源框架是从去年开始搞的,bug一大堆,唯一的好处就是,社区特别活跃,一直在修bug,从昨天开始,一直在调试。总算有点儿成果。

    本人有个Android手机,但是一直没办法root,所以调试起来比较麻烦。还是先说说iOS吧。

    坑1:模拟器无法启动,报错:ideviceinstaller的问题

    不知道是从哪个版本开始,appium喜欢上了ideviceinstaller,后来Google一下,发现这个工具是可以自动打包和安装app的开源工具。

报错:

info: [debug] Couldn’t find ideviceinstaller, trying built-in at /Users/eclose/Projects/appium/build/libimobiledevice-macosx/ideviceinstaller

error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

info: [debug] Cleaning up appium session

error: Failed to start an Appium session, err was: Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

我当时查看了我的目录,是有这个文件的,当时非常不明白为啥没有识别。又Google了一下,看了一下社区的bug内容,其中的回复是这样的:

ideviceinstaller is a system requirement for working on ios real devices. we bundle one but it isn’t always built for the same platform you’re using.

说的很明白了,确实提供了一个编译好的,但是平台不一样,有可能不识别,例如我是在mac上,就不好用了,所以,自己编译吧!mac上最好用的安装工具无非就是brew了

brew install ideviceinstaller

结果是各种报错,因为好多依赖都在很老的官网上去获取和本地编译,而这些网站有些都挂掉了,例如第一个依赖:libxml2,我一开始的解决方案是自己Google,下载编译。最后终于搞定了。满怀信心的跑了一下appium,结果报错:

Segmentation fault: 11

好像是程序core了一样。Google一下,有篇帖子说,是因为brew的问题,所以,想update一下,结果各种没反应。没办法,去brew的官网

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

It appears Homebrew is already installed. If your intent is to reinstall you

should do the following before running this installer again:

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)”

The current contents of /usr/local are bin Cellar chromedriver CODEOFCONDUCT.md CONTRIBUTING.md etc include lib Library LICENSE.txt mysql mysql-5.6.20-osx10.8-x86_64 mysql-connector-python-1.2.3 node_modules opt README.md share SUPPORTERS.md .git .gitignore

没办法,我已经安装过了,所以手动执行一下uninstall

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)”

卸载前,最好备份一下,备份哪些东西,执行命令时,会提示你,它会删除那些东西,如果你觉得那些目录的东西你没用了,那就直接输入y,就行了,我是备份了一下

然后,再次执行命令:

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

安装后,再次执行命令:

brew install ideviceinstaller

这次安装的时候,你会发现,安装的依赖都是在brewHome下载的,如果早更新brew,我得节省2个小时,哎!坑啊!

安装后,ideviceinstaller应该是可以使用了,但是后面还有坑,继续!

此时我遇到一种情况,非常诡异,就是应用一直都在闪退,重复启动,重复闪退,对了,这里说一下,ideviceinstaller是在真机上运行时会用到的一个工具,现在我说的也是在真机上运行遇到的问题,一会儿再说一下在模拟器上运行遇到的问题。

对于闪退的问题,其实在console的日志里可以看到,是因为手机没有开启uiautomation的开关,开启过程是:

设置–>开发者–>Enable UI Automation 

这样应该就没有问题了!

在真机上还有一个坑!

启动时,会报错:

Instruments crashed on startup

Instruments exited with code 253

有两个原因,一个原因是Instruments已经启动了一个了,所以,你可以把Xcode退出一下,应该有正在运行的应用。另外一个:如果看到类似于

Targetfailed to run: Permission to debug xxxx was denied

那应该就是权限问题,因为,只有debug的app才可以运行,不像Android中的uiautomator,可以搞任何安装的应用。或者说,只能搞你自己签名过的

下面说一下模拟器的坑:

现在我用的最新版本,1.4.13,需要在设置里或者运行的使用,加个参数–native-instruments-lib,UI版本的,在Developer Settings –> Custom Server Flags 里添加。

另外一个,在模拟器里面启动时,也会出现重复crash的问题。这时,运行一下

appium-doctor.js,我当时是没有安装Xcode Command Line Tools

好了,差不多就这些了!

还有一个东西,Safari,appium启动是通过了一个代理app,SafariLauncher,这个app自己编译一下把debug的.app包,用zip打包放到appium的目录下,就可以使用了。有个自动跳转的时间,自己可以调一下

最后,Appuim还是不太稳定,有两个外因:一个是iOS的Xcode一直在更新,每次更新都有很多问题需要兼容,第二个:现在hybrid的兴起,有些东西混合的太多了。

    原文作者:最后一次被盗
    原文地址: https://www.jianshu.com/p/335ad848037d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞