1.python + appium +图片对比实现UI自动化:
背景:
当手机需要适配不同的语言时,测试过程中易出现因为语言不熟悉,导致UIbug被遗漏(例如setting中的描述性文字显示不完整等等问题)
环境搭建:
需使用模块PIL,Windows版本链接地址:http://pythonware.com/products/pil/
ubuntu (使用16.04虚拟机):sudo apt-get install python-imaging
安装过程遭遇
Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
强制解锁进行的下一步
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
各种小毛病:
安装PIL模块提示python2.7没有注册,解决方法:
https://www.cnblogs.com/thinksasa/p/3283695.html
虚拟机连接手机提示没有权限的问题:
在root账号下,kill-server 然后start-server
在win7 64位会报错:tThe _imaging C module is not installed,安装64位的PIL可解决,
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow
安装后在python下执行import ImageFon,不报错就OK。安装过程各种不爽,用python3.6搭配64位的PIL在Windows下成功执行(上面的网址可以下载)
在使用ImageChops.difference函数时,部分结果图片显示为一张网格图,导致压根看不到两张图的差异,结合如下链接
https://blog.csdn.net/qq_41500251/article/details/82919656
对图片进行取反,使得结果可见
逻辑梳理:
保存已确认过的UI截图,在测试时将当前页面进行截图,与保存的期望截图做对比
问题一
期望结果截图和测试结果截图时间不同,当前已运行的程序不同,会导致状态栏显示不同,并且有时候navigation bar也会不一样(Android P手机倾斜时,出现一个转屏操作按钮)
方案:将图片进行裁剪,只保留需要对比的部分。
截图使用到如下模块:
im = Image.open(im_path)
cropedIm = im.crop((700, 100, 1200, 1000))#此处为(左,上,右,下)坐标
cropedIm.save(r'C:\Users\Administrator\Desktop\cropped.png')
https://www.c