赞
踩
AirtestIDE 是一个跨平台的UI自动化测试编辑器,适用于游戏和App。
自动化脚本录制、一键回放、报告查看,轻而易举实现自动化测试流程
支持基于图像识别的Airtest框架,适用于所有Android和Windows游戏
支持基于UI控件搜索的Poco框架,适用于Unity3d,Cocos2d与Android App
一句话总结:我们推出了两款基于Python的UI自动化测试框架Airtest(用截图写脚本)和Poco(用界面UI元素来写脚本),可以用我们提供的AirtestIDE来快速编写你的自动化测试脚本~
本文重点是针对Airtest中的图像识别进行代码走读,加深对图像识别原理的理解
1、准备工作,下载好源码 https://github.com/AirtestProject/Airtest
2、我们从最简单的touch方法入手,即为点击某个传入的图片,源码在api.py里面
- @logwrap
- def touch(v, times=1, **kwargs):
- """
- Perform the touch action on the device screen
-
- :param v: target to touch, either a Template instance or absolute coordinates (x, y)
- :param times: how many touches to be performed
- :param kwargs: platform specific `kwargs`, please refer to corresponding docs
- :return: finial position to be clicked
- :platforms: Android, Windows, iOS
- """
- if isinstance(v, Template):
- pos = loop_find(v, timeout=ST.FIND_TIMEOUT)
- else:
- try_log_screen()
- pos = v
- for _ in range(times):
- G.DEVICE.touch(pos, **kwargs)
- time.sleep(0.05)
- delay_after_operation()
- return pos
-
- click = touch # click is alias of touch
这个函数执行点击操作的是 G.DEVICE.touch(pos, **kwargs)
而pos就是图片匹配返回的坐标位置,我们重点看loop_find这个函数
- @logwrap
- def loop_find(query, timeout=ST.FIND_TIMEOUT, threshold=None, interval=0.5, intervalfunc=None):
- """
- Search for image template in the screen until timeout
-
- Args:
- query: image template to be found in screenshot
- timeout: time interval how long to look for the image template
- threshold: default is None
- interval: sleep interval before next attempt to find the image template
- intervalfunc: function that is executed after unsuccessful attempt to find the image template
-
- Raises:
- TargetN
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。