生活随笔
收集整理的這篇文章主要介紹了
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分別為紅綠藍,沒按壓的位置為白色。
?
總結
以上是生活随笔為你收集整理的Airtest多点触控测试的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。