AirTest介紹:
Airtest是一款基於Python的、跨平台的UI自動化測試框架,基於圖像識別原理,適用於游戲和App。
訪問Github上的 Airtest源碼地址 ,可以獲得更多信息,也歡迎各位幫忙完善項目,提交PR,也可以在issues頁面中 提交bug或建議 。
如何快速上手
首先,想要編寫Airtest腳本,需要具備基礎的Python語法知識。雖然借助我們的AirtestIDE提供的錄制功能,也能簡單地根據操作步驟錄制出可以回放操作的腳本,但是通常來說,熟練掌握Python語法能夠幫助我們寫出應用更廣泛、更不容易出錯的腳本。
若對 Python 語法不熟悉,網絡上有不少非常優秀的Python教程可以學習,例如 廖雪峰的Python新手教程。
關於Airtest項目的安裝、基本使用方法和簡單的例子,請查看Airtest文檔頁的 快速上手 章節。
官方網址(必看)
airtest介紹與腳本入門
https://airtest.doc.io.netease.com/tutorial/2_Airtest_introduction/
模擬點擊
Airtest作為自動化測試框架,模擬的是人的操作,常見接口主要有:
touch
點擊某個位置,可以設定被點擊的位置、次數、按住時長等參數swipe
從一個位置滑動到另外一個位置text
調用輸入法輸入指定內容keyevent
輸入某個按鍵響應,例如回車鍵、刪除鍵wait
等待某個指定的圖片元素出現snapshot
對當前畫面截一張圖- 其他
使用本地python環境運行腳本
http://airtest.netease.com/docs/en/1_online_help/running_scripts.html
1.部署Python環境,安裝Python(2.7 或 <= 3.6),Mac 安裝 brew install python3
windows注意配置環境變量,C:\Python27\Scripts、C:\Python27
2.pip install airtest
3.pip install pocoui
4.跑腳本
airtest run E:\AutoTest\Normal.air --device Android:///設備信息
airtest run E:\AutoTest\Normal.air --device Android:///設備信息 --log log/
airtest run E:\AutoTest\Normal.air --device Android:///設備信息 --log log/ --outfile log.html /// 運行結果
adb devices 查看設備信息
如果你連接了多個設備,或者有遠程設備,那么使用參數來指定要連接的設備
# connect an android phone with adb init_device("Android") # or use connect_device api with default params connect_device("android:///") # connect a remote device using custom params connect_device("android://adbhost:adbport/1234566?cap_method=javacap&touch_method=adb")