Airtest多点触控测试

通过airtest实现多点按压和检测按压位置的RGB数值来判断测试是否成功。

代码:
 

from airtest.core.api import *
from airtest.core.android.touch_methods.base_touch import *
from os import getcwd
from PIL import Image

# 连接设备
auto_setup(__file__,logdir=True,devices=["android://127.0.0.1:5037/HA1L00JJ"])
dev = device()

# 编写minitouch执行文件,DownEvent([500, 500], 0) = d 0 500 500 50, 在单点以50压力轻敲(500, 500),
# minitouch中最后一个参数50为敲击压力,airtest的DownEvent默认参数为50,也可以通过pressure参数自定义
multiTouchEvent = [
    DownEvent([500, 500], 0),
    DownEvent([500, 700], 1),
    DownEvent([500, 900], 2)]

# 发送下压信号
dev.touch_proxy.perform(multiTouchEvent)

# 截图并读取点击位置的像素.
pic_path = getcwd()
snapshot(f'{pic_path}//multiTouchPic.png')
multi_touch_pic = Image.open(f'{pic_path}//multiTouchPic.png')
print(multi_touch_pic.getpixel((500, 500)))
print(multi_touch_pic.getpixel((500, 700)))
print(multi_touch_pic.getpixel((500, 900)))
print(multi_touch_pic.getpixel((500, 1200)))

发送按压信号之后的设备界面

输出:

(254, 0, 0)
(0, 255, 1)
(0, 0, 254)
(246, 246, 246)

从输出的结果可以看出按压位置的RGB分别为红绿蓝,没按压的位置为白色。

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值