引言
- 随着版本迭代加快,app复杂度增加,手工测试无法满足版本快速迭代需要,需要引入自动化进行回归测试
- 多分支开发,提高打包转测的质量,打包后自动执行一些自动化case,保障主业务通畅
基于这两点原因,希望引入[低成本]自动化解决这些问题
airtest框架
是一个跨平台的、基于图像识别的UI自动化测试框架,适用于游戏和App,支持平台有Windows、Android和iOS
主流框架对比
appium

airtest

投入产出
传统级别的移动端UI自动化 id/class/tag、des/xpath/pos/text
| 对比项 | 传统控件识别 | 图像识别 |
|---|---|---|
| 原理 | id && 其他 | 图像 |
| 脚本编写成本 | 高 | 低 |
| 后期维护成本 | 高 | 低 |
| 入门难度 | 高 | 低 |
| 跨进程 | 有一定门槛 | 不存在 |
| 跨平台 | 成本高 | 零成本 |
成本
- 新功能编写用例
- 旧功能修改用例
- android/ios的成本
- 执行用例
产出
- 功能回归验证
- 测试报告
原理
图像识别
截图--识别--点击
for method in ST.CVSTRATEGY:
# get function definition and execute:
func = MATCHING_METHODS.get(method, None)
if func is None:
raise InvalidMatchingMethodError("Undefined method in CVSTRATEGY: '%s', try 'kaze'/'brisk'/'akaze'/'orb'/'surf'/'sift'/'brief' instead." % method)
else:
ret = self._try_match(func, image, screen, threshold=self.threshold, rgb=self.rgb)
if ret:
break
airtest优先匹配模板算法,次匹配特征点算法
template_matching
模板匹配
- 无法跨分辨率识别
- 一定有相对最佳的匹配结果
keypoint_matching
特征点的匹配
- 跨分辨率识别
- 不一定有匹配结果
android
- 截图方式 MINICAP、ADBCAP、JAVACAP
ios
- 截图方式 MINICAP、WDACAP
WebDriverAgent is a WebDriver server implementation for iOS that can be used to remote control iOS devices. It allows you to launch & kill applications, tap & scroll views or confirm view presence on a screen. This makes it a perfect tool for application end-to-end testing or general purpose device automation. It works by linking XCTest.framework and calling Apple's API to execute commands directly on a device. WebDriverAgent is developed and used at Facebook for end-to-end testing and is successfully adopted by Appium.
使用和demo
环境搭建
直接演示
hello airtest
autocasedemo by android
- 新安装并打开小火箭app
- 登录账号
- 进入进阶课星球
- 播放视频
- 返回首页
- 退出登录
二次开发和CI
适配性
- lbkrunner
codemao运行器,单个.air文件为一条case,多个air集成一个app的casesuit
演示...
- 适配性api
- 数据库操作
- 测试报告
CI/CD
测试报告
邮件预警