Airtest 學(xué)習(xí)筆記

Airtest 學(xué)習(xí)筆記

模擬輸入

.touch

模擬點(diǎn)觸操作

touch(v, times=2, **kwargs)

參數(shù)v - 點(diǎn)觸的目標(biāo):Template對象或是絕對坐標(biāo)

例如:

# 絕對坐標(biāo)
>>> touch((100,200))
# 點(diǎn)擊圖片中心
>>> touch(Template(r"tp1150.png",target_pos=5))
# 相對坐標(biāo),如下為屏幕中心
>>> touch((0.5,0.5))

.swipe

模擬滑動(dòng)操作

swipe(v1, v2=None, vector=None, **kwargs)

參數(shù)v1, v2- 滑動(dòng)的目標(biāo):Template對象或是絕對坐標(biāo);

vector 滑動(dòng)向量。

例如:

>>> swipe(Template(r"tpl1606814865574.png"), vector=[-0.0316, -0.3311])
>>> swipe((100, 100), (200, 200))

.text

模擬文字輸入

text(text, enter=True, **kwargs)

例如:

# 輸入test,然后點(diǎn)擊回車/確認(rèn)
>>> text("test")
# 輸入test,不點(diǎn)回車/確認(rèn)
>>> text("test", enter=False)

.keyevent

模擬按鍵輸入

keyevent(keyname, **kwargs)

例如:

>>> keyevent("HOME")
# The constant corresponding to the home key is 3
>>> keyevent("3")  # same as keyevent("HOME")
>>> keyevent("BACK")
>>> keyevent("KEYCODE_DEL")

.snapshot

屏幕截圖

snapshot(filename=None, msg='', quality=None, max_size=None)
  • filename - 保存的截圖文件名
  • msg - 截圖描述
  • quality - 圖片質(zhì)量[1,99]之間
  • max_size - 圖片最大尺寸

例如:

# Set the screenshot quality to 30
>>> ST.SNAPSHOT_QUALITY = 30
# Set the screenshot size not to exceed 600*600
# if not set, the default size is the original image size
>>> ST.IMAGE_MAXSIZE = 600
# The quality of the screenshot is 30, and the size does not exceed 600*600
>>> touch((100, 100))
# The quality of the screenshot of this sentence is 90
>>> snapshot(filename="test.png", msg="test", quality=90)
# The quality of the screenshot is 90, and the size does not exceed 1200*1200
>>> snapshot(filename="test2.png", msg="test", quality=90, max_size=1200)

.wait

等待在設(shè)備屏幕上找到匹配圖片

wait(v, timeout=None, interval=0.5, intervalfunc=None)

例如:

# 每次執(zhí)行失敗后執(zhí)行特定命令
>>> def notfound():
>>>     print("No target found")
>>> wait(Template(r"tpl1607510661400.png"), intervalfunc=notfound)

斷言

# 圖案是否存在
>>> assert_exists(v, msg='')
>>> assert_not_exists(v, msg='')
# 值是否相等
>>> assert_equal(first, second, msg='', snapshot=True)
>>> assert_not_equal(first, second, msg='', snapshot=True)
# 表達(dá)式是否為True
>>> assert_true(expr, msg='', snapshot=True)
>>> assert_false(expr, msg='', snapshot=True)
# 是否是同一個(gè)對象
>>> assert_is(first, second, msg='', snapshot=True)
>>> assert_is_not(first, second, msg='', snapshot=True)
# 是否包含
>>> assert_in(first, second, msg='', snapshot=True)
>>> assert_not_in(first, second, msg='', snapshot=True)
# 是否是該類的實(shí)例
>>> assert_is_instance(obj, cls, msg='', snapshot=True)
>>> assert_not_is_instance(obj, cls, msg='', snapshot=True)
# 是否大于/大于等于
>>> assert_greater(first, second, msg='', snapshot=True)
>>> assert_greater_equal(first, second, msg='', snapshot=True)
# 是否小于/小于等于
>>> assert_less(first, second, msg='', snapshot=True)
>>> assert_less_equal(first, second, msg='', snapshot=True)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容