通过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分别为红绿蓝,没按压的位置为白色。