Airtest图像识别原理

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
  • 7
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值