網易 UI 自動化工具 Airtest 淺用記錄
一 使用目的
該工具主要是面向遊戲UI測試基於圖像識別,如遊戲框架unity,Cocos-js以及網易內部的遊戲框架
同時也支持原生Android App 的基於元素識別的UI自動化測試.
本文主要使用目的是做安卓原生App的元素UI自動化.
二 資源索引
官方資源
網易遊戲新開源的 UI 自動化測試項目 [Airtest Project]
Airtest官網
Airtest官網上手教程
AirtestProject Github主頁
AirtestIDE官方中文文檔
Airtest 官方中文文檔
PocoUI自動化框架官方中文文檔
Android App UI自動化相關API
airtest.core.api module
poco.drivers.android.uiautomation module
三 環境準備
Python3 開發環境部署
如果只想用AirtestIDE這款前端集大成的開發IDE工具通過,前端點點點生成或錄制方式生成腳本的話,你完全可以開箱即用,完全不用搞以下Python開發環境.
如果想自己利用底層API擴展高級腳本框架,為了更便利的直接使用airtest 或 poco 的API,建議還是提前部署好Python3開發環境.
Python3.6.4
這裏提供了許多種格式的安裝包,如windows下常見的.exe格式.這種安裝方便,大多數的選擇.
找到你系統對應的安裝包,我是win10 64位操作系統 選擇的是python-3.6.4-amd64.exe
安裝到我本地的D:盤D:\Python36\ 下
配置環境變量(請註意根據跟人習慣統一添加到用戶變量還是系統變量,我個人一般全部添加到系統變量),追加到Path末尾,D:\Python36\;D:\Python36\Scripts\
筆者當前win10,是Python2和Python3共存的,如有需要具體部署請參考
Win10下python3和python2同時安裝並解決pip共存問題
附上最終的一些版本檢查與pip2 pip3部署檢查命令
#Python2 檢查
C:\Users\cmd>python2
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
#Python3檢查
C:\Users\cmd>python3
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
#pip3部署
C:\Users\cmd>python3 -m pip install --upgrade pip --force-reinstall
Collecting pip
Downloading pip-9.0.2-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 746kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Successfully uninstalled pip-9.0.1
Successfully installed pip-9.0.2#pip2部署C:\Users\cmd>python2 -m pip install --upgrade pip --force-reinstallCollecting pip Using cached pip-9.0.2-py2.py3-none-any.whlInstalling collected packages: pip Found existing installation: pip 9.0.1 Uninstalling pip-9.0.1: Successfully uninstalled pip-9.0.1Successfully installed pip-9.0.2#檢查pip2C:\Users\cmd>pip2 -Vpip 9.0.2 from d:\python27\lib\site-packages (python 2.7)#檢查pip3C:\Users\cmd>pip3 -Vpip 9.0.2 from d:\python36\lib\site-packages (python 3.6)#檢查pip2 python2已安裝庫C:\Users\cmd>pip2 listDEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.pip (9.0.2)setuptools (28.8.0)#檢查pip3 python3已安裝庫C:\Users\cmd>pip3 listDEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.pip (9.0.2)setuptools (28.8.0)#檢查哪些python3庫需要升級C:\Users\cmd>pip3 list -oDEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.setuptools (28.8.0) - Latest: 39.0.1 [wheel]# 升級該庫C:\Users\cmd>pip3 install --upgrade setuptoolsCollecting setuptools Downloading setuptools-39.0.1-py2.py3-none-any.whl (569kB) 100% |████████████████████████████████| 573kB 815kB/sInstalling collected packages: setuptools Found existing installation: setuptools 28.8.0 Uninstalling setuptools-28.8.0: Successfully uninstalled setuptools-28.8.0Successfully installed setuptools-39.0.1
虛擬Python virtualenv環境部署
為什麽要用virtualenv 虛擬環境,因為當你鼓搗Python開源項目多了的時候,比如自動化方向的selenium, Appium-Python-Client, ATX的uiautomator2的時候,如果放在一個Python環境下,用Pycharm找引用ctrl+B的時候,相似api方法名就會跳出多個,你就會不知道到底是引用的哪一個庫下的,獨立分開各個UI自動化Python虛擬環境的話,查起來就方便減少了迷惑.
#安裝virtualenv
C:\Users\cmd>pip3 install virtualenv
Collecting virtualenv
Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
#激活使用該virtualenv
C:\Users\cmd\venv\Scripts>activate.bat
#見到以下輸出即成功
(venv) C:\Users\cmd\venv\Scripts>
如果想創建獨立的Airtest Python3開發環境,可如下
#創建基於Python3.6.4的名為Airtest364的虛擬環境
C:\Users\cmd>virtualenv -p D:\Python36\python3.exe Airtest364
Running virtualenv with interpreter D:\Python36\python3.exe
Using base prefix ‘D:\\Python36‘
New python executable in C:\Users\cmd\Airtest364\Scripts\python3.exe
Also creating executable in C:\Users\cmd\Airtest364\Scripts\python.exe
Installing setuptools, pip, wheel...done.
#切換到Airtest364下並激活該環境
C:\Users\cmd>cd Airtest364\Scripts
C:\Users\cmd\Airtest364\Scripts>activate.bat
#檢查虛擬環境初始化安裝的Python庫
(Airtest364) C:\Users\cmd\Airtest364\Scripts>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.2)
setuptools (39.0.1)
wheel (0.30.0)
安裝Airtest提供的Android App UI測試庫pocoui
#安裝Airtest提供的Android App UI測試庫 pocoui
(Airtest364) C:\Users\cmd\Airtest364\Scripts>pip3 install pocoui
#檢查都依賴安裝了哪些
(Airtest364) C:\Users\cmd\Airtest364\Scripts>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
airtest (1.0.2)
AxmlParserPY (0.1)
certifi (2018.1.18)
chardet (3.0.4)
comtypes (1.1.4)
hrpc (1.0.3)
idna (2.6)
Jinja2 (2.10)
MarkupSafe (1.0)
numpy (1.14.2)
opencv-contrib-python (3.4.0.12)
Pillow (5.0.0)
pip (9.0.2)
pocoui (1.0.26)
pydash (4.4.1)
pypiwin32 (223)
pywin32 (223)
pywinauto (0.6.4)
requests (2.18.4)
setuptools (39.0.1)six (1.11.0)urllib3 (1.22)websocket-client (0.47.0)wheel (0.30.0)
Android sdk工具部署
下載地址 http://tools.android-studio.org/index.php/sdk 處下載 android-sdk_r24.4.1-windows.zip
將android-sdk-windows解壓到你需要的目錄下,筆者是D:\Android\android-sdk-windows
配置android-sdk環境變量:
ANDROID_HOME 變量值為android-sdk的解壓目錄,筆者為D:\Android\android-sdk-windows
PATH PATH變量值的最後追加 ;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\build-tools;
接下來你便可以用D:\Android\android-sdk-windows 下的SDK Manager.exe下載配置SDK 或AVD Manager.exe 配置 AVD模擬器了。
如果你需要測試android應用的話,請先安裝配置好某一版本的SDK及其相關工具。
如下圖,SDK manager必要配置:
Tools->Options設置
其它要下載的:
此處為了與Macaca環境兼容,目前穩定沒敢亂升級,大家也可用此.
此處的按需選擇與AVD模擬器配套使用的
關於Android開發環境的大家可以參考此人的博客
Android SDK Manager和AVD Manager使用
Android開發環境配置
該步驟,主要是為了部署adb工具而已,當然也有獨立部署adb的方案.這個你按需選擇吧,不過你既然要搞Android UI自動化相關了,Android sdk工具的部署最終還是逃不過的.
#檢查下最終的adb版本
C:\Users\cmd>adb -v
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as D:\Android\android-sdk-windows\platform-tools\adb.exe
手機真機相關設置
真機小米Mix2
需要開啟真機開發者選項->USB調試,模式和其他相關,主要是調試這一欄要打開的有
PyCharm 開發工具
Pycharm download
PyCharm+IDE+and+Python+Plugin+for+IntelliJ+IDEA
Meet PyCharm
請自行安裝配置部署好PyCharm開發工具.
AirTest Project Interpreter環境切換
打開Settings->Project Interpreter
如果上述步驟無誤的話,可以直接找到Existing environment選擇即可,如果沒有請使用添加並找到上述路徑C:\Users\cmd\Airtest364\Scripts\添加.
四 AirTestIDE工具簡單使用
先通過adb命令檢查小米Mix2真機是否連接正常
C:\Users\cmd>adb devices -l
List of devices attached
yourSerialNo device product:chiron model:MIX_2 device:chiron
AirTestIDE下載地址
然後去官網下載最新版本的AirTestIDE,直接解壓到D:盤即可,筆者解壓到的路徑是D:\AirtestIDE
解壓目錄下找到AirtestIDE.exe雙擊即可執行,目前還未GDC正式發布,所以你會看到打開了兩個窗口,一個是命令行的實時日誌(為了便捷的捕獲工具本身問題日誌),一個就是AirtestIDE主圖形工具窗口.
點擊設備窗口下的 connect即可看到一個實時同步的且可雙向操作的Device Screen窗口,怎麽樣很膩害吧,實時同步的且可雙向操作的呦
此時請註意觀察你連接的真機,會提示向手機安裝以下依賴包:
RotationWatcher
Poco輔助窗下的Poco Inspector
既是一個類似Macaca Inspector或Appium Inspector的一款界面UI元素查看工具.
使用方法,在Poco輔助窗下拉切換到Android.
此時請註意觀察你連接的真機,會提示向手機安裝以下依賴包和Poco組件服務:
PocoService
com.netease.open.pocoservice.test
Yosemite(與輸入法相關)
安裝成功後,我們再找到Poco輔助窗右側的Poco Inspector按鈕,點擊之,然後在Device Screen窗口便可即點即提示你當前的選中UI元素了,與其他工具類似.
然後在點擊Poco輔助窗右側的Poco Inspector按鈕左側的Poco Pause即可鎖定和樹形化展示元素dom樹.
如下圖
我們利用此方法,找到需要操作的UI元素後,便可以編輯業務流腳本了.
五 編輯登錄流程腳本
需要先首先創建個空文件,文件->新建腳本後,選擇一保存路徑我的是D:\scripts\Airtest\ 取名為Airtest01,確定後,即會發現一個名為Airtest01.air的文件夾.
然後以下,這裏用到的就是上述搭建好的Pycharm Python3 virtualenv Airtest364開發環境.
分別用到了兩個庫下的api airtest.core.api和poco.drivers.android.uiautomation,請自行根據官方文檔查看並使用.
最終腳本如下:
# -*- encoding=utf8 -*-
__author__ = "cmd"
__title__ = "Acp Login"
__desc__ = """
this is a test script.
"""
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(force_restart=False)
# start your script here
connect_device(‘Android:///yourSerialNo‘)
start_app(‘com.sinacp.ggaicai‘)
sleep(9)
poco("com.acp.main:id/tvTabImg4").click()
sleep(3)
poco("com.acp.main:id/tvAccount").click()
sleep(3)
poco("com.sinacp.ggaicai:id/etUserName").click()
poco("com.sinacp.ggaicai:id/etUserName").set_text(‘張三李四‘)
sleep(3)
poco("com.sinacp.ggaicai:id/etPwd").click()
poco("com.sinacp.ggaicai:id/etPwd").set_text(‘123UI895‘)
sleep(3)
poco("com.sinacp.ggaicai:id/tvLogin").click()
sleep(6)
編輯好無語法錯誤後,可以直接在AirtestIDE中打開,點擊Run Script(F5)執行該腳本.
Log查看窗日誌
"D:\AirtestIDE\AirtestIDE" runner "D:\scripts\Airtest\Airtest01.air" --device Android://127.0.0.1:5037/yourSerialNo --log "C:\Users\cmd\AppData\Local\Temp\AirtestIDE\scripts\c227edd84edf79234c03c3162327120c"
============================================================
[Start running..]
[02:14:11][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo wait-for-device
[02:14:11][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell getprop ro.build.version.sdk
[02:14:11][DEBUG]<airtest.utils.logwraper> main_script: {‘script‘: u‘D:\\scripts\\Airtest\\Airtest01.air‘}
[02:14:11][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell dumpsys activity top
[02:14:11][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell settings get secure default_input_method[02:14:11][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell ime list -a[02:14:12][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell dumpsys package com.netease.open.pocoservice[02:14:12][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell dumpsys package com.netease.open.pocoservice.test[02:14:12][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo forward --no-rebind tcp:19517 tcp:10080[02:14:12][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo forward --no-rebind tcp:17292 tcp:10081[02:14:13][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell ps[02:14:13][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo wait-for-device[02:14:13][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell getprop ro.build.version.sdk[02:14:13][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell monkey -p com.sinacp.ggaicai -c android.intent.category.LAUNCHER 1[02:14:14][DEBUG]<airtest.utils.logwraper> >start_app Time used: 0.596000s[02:14:14][DEBUG]<airtest.utils.logwraper> function: {‘time_used‘: 0.5959999561309814, ‘args‘: (‘com.sinacp.ggaicai‘,), ‘name‘: ‘start_app‘, ‘ret‘: None, ‘kwargs‘: {}}[02:14:23][DEBUG]<airtest.utils.logwraper> >sleep Time used: 9.012000s[02:14:23][DEBUG]<airtest.utils.logwraper> function: {‘time_used‘: 9.01200008392334, ‘args‘: (9,), ‘name‘: ‘sleep‘, ‘ret‘: None, ‘kwargs‘: {}}[02:14:23][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell pm path jp.co.cyberagent.stf.rotationwatcher[02:14:23][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell export CLASSPATH=/data/app/jp.co.cyberagent.stf.rotationwatcher-kp6OiHzpT4ITooezG-vtMA==/base.apk;exec app_process /system/bin jp.co.cyberagent.stf.rotationwatcher.RotationWatcher[02:14:23][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell ls /data/local/tmp/minicap[02:14:24][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell ls /data/local/tmp/minicap.so[02:14:24][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -v 2>&1[02:14:24][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell dumpsys display[02:14:24][DEBUG]<airtest.core.android.minicap> version:5[02:14:24][DEBUG]<airtest.core.android.minicap> skip install minicap[02:14:24][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo forward --no-rebind tcp:13151 localabstract:minicap_13151[02:14:24][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell dumpsys window[02:14:24][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell dumpsys SurfaceFlinger[02:14:25][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell getevent -p[02:14:25][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -n ‘minicap_13151‘ -P 1080x2160@1080x2160/0 -l 2>&1[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘PID: 28547‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: Using projection 1080x2160@1080x2160/0‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:241) Creating SurfaceComposerClient‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:244) Performing SurfaceComposerClient init check‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:255) Creating virtual display‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:261) Creating buffer queue‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:264) Setting buffer options‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:268) Creating CPU consumer‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:272) Creating frame waiter‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (external/MY_minicap/src/minicap_26.cpp:276) Publishing virtual display‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (jni/minicap/JpgEncoder.cpp:64) Allocating 7052292 bytes for JPG encoder‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (/home/lxn3032/minicap_for_ide/jni/minicap/minicap.cpp:473) Server start‘[02:14:25][DEBUG]<airtest.utils.nbsp> [minicap_server]‘INFO: (/home/lxn3032/minicap_for_ide/jni/minicap/minicap.cpp:475) New client connection‘[02:14:25][DEBUG]<airtest.core.android.minicap> (1, 24, 28547, 1080, 2160, 1080, 2160, 0, 2)[02:14:25][DEBUG]<airtest.utils.logwraper> >snapshot Time used: 2.319000s[02:14:25][DEBUG]<airtest.utils.logwraper> function: {‘name‘: ‘snapshot‘, ‘kwargs‘: {‘msg‘: u‘UIObjectProxy of "com.acp.main:id/tvTabImg4"‘}, ‘time_used‘: 2.319000005722046, ‘screen‘: ‘1521440065604.jpg‘, ‘args‘: (), ‘ret‘: u‘C:\\Users\\cmd\\AppData\\Local\\Temp\\AirtestIDE\\scripts\\c227edd84edf79234c03c3162327120c\\1521440063344.jpg‘}[02:14:29][DEBUG]<airtest.utils.logwraper> >sleep Time used: 3.005000s[02:14:29][DEBUG]<airtest.utils.logwraper> function: {‘time_used‘: 3.005000114440918, ‘args‘: (3,), ‘name‘: ‘sleep‘, ‘ret‘: None, ‘kwargs‘: {}}[02:14:29][DEBUG]<airtest.utils.logwraper> >snapshot Time used: 0.223000s[02:14:29][DEBUG]<airtest.utils.logwraper> function: {‘name‘: ‘snapshot‘, ‘kwargs‘: {‘msg‘: u‘UIObjectProxy of "com.acp.main:id/tvAccount"‘}, ‘time_used‘: 0.22300004959106445, ‘screen‘: ‘1521440069855.jpg‘, ‘args‘: (), ‘ret‘: u‘C:\\Users\\cmd\\AppData\\Local\\Temp\\AirtestIDE\\scripts\\c227edd84edf79234c03c3162327120c\\1521440069682.jpg‘}[02:14:33][DEBUG]<airtest.utils.logwraper> >sleep Time used: 3.015000s[02:14:33][DEBUG]<airtest.utils.logwraper> function: {‘time_used‘: 3.0149998664855957, ‘args‘: (3,), ‘name‘: ‘sleep‘, ‘ret‘: None, ‘kwargs‘: {}}[02:14:34][DEBUG]<airtest.utils.logwraper> >snapshot Time used: 0.443000s[02:14:34][DEBUG]<airtest.utils.logwraper> function: {‘name‘: ‘snapshot‘, ‘kwargs‘: {‘msg‘: u‘UIObjectProxy of "com.sinacp.ggaicai:id/etUserName"‘}, ‘time_used‘: 0.44300007820129395, ‘screen‘: ‘1521440074313.jpg‘, ‘args‘: (), ‘ret‘: u‘C:\\Users\\cmd\\AppData\\Local\\Temp\\AirtestIDE\\scripts\\c227edd84edf79234c03c3162327120c\\1521440073922.jpg‘}[02:14:35][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell dumpsys package com.netease.nie.yosemite[02:14:35][INFO]<airtest.core.android.yosemite> local version code is 281, installed version code is 281[02:14:35][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell am broadcast -a ADB_INPUT_TEXT --es msg ‘張三李四‘[02:14:38][DEBUG]<airtest.utils.logwraper> >sleep Time used: 3.001000s[02:14:38][DEBUG]<airtest.utils.logwraper> function: {‘time_used‘: 3.000999927520752, ‘args‘: (3,), ‘name‘: ‘sleep‘, ‘ret‘: None, ‘kwargs‘: {}}[02:14:39][DEBUG]<airtest.utils.logwraper> >snapshot Time used: 0.379000s[02:14:39][DEBUG]<airtest.utils.logwraper> function: {‘name‘: ‘snapshot‘, ‘kwargs‘: {‘msg‘: u‘UIObjectProxy of "com.sinacp.ggaicai:id/etPwd"‘}, ‘time_used‘: 0.3789999485015869, ‘screen‘: ‘1521440079428.jpg‘, ‘args‘: (), ‘ret‘: u‘C:\\Users\\cmd\\AppData\\Local\\Temp\\AirtestIDE\\scripts\\c227edd84edf79234c03c3162327120c\\1521440079098.jpg‘}[02:14:40][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo shell am broadcast -a ADB_INPUT_TEXT --es msg ‘123UI895‘[02:14:43][DEBUG]<airtest.utils.logwraper> >sleep Time used: 3.000000s[02:14:43][DEBUG]<airtest.utils.logwraper> function: {‘time_used‘: 3.0, ‘args‘: (3,), ‘name‘: ‘sleep‘, ‘ret‘: None, ‘kwargs‘: {}}[02:14:51][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -s yourSerialNo forward --remove tcp:13151[02:14:44][DEBUG]<airtest.utils.logwraper> >snapshot Time used: 0.454000s[02:14:44][DEBUG]<airtest.utils.logwraper> function: {‘name‘: ‘snapshot‘, ‘kwargs‘: {‘msg‘: u‘UIObjectProxy of "com.sinacp.ggaicai:id/tvLogin"‘}, ‘time_used‘: 0.45399999618530273, ‘screen‘: ‘1521440084269.jpg‘, ‘args‘: (), ‘ret‘: u‘C:\\Users\\cmd\\AppData\\Local\\Temp\\AirtestIDE\\scripts\\c227edd84edf79234c03c3162327120c\\1521440083861.jpg‘}[02:14:51][DEBUG]<airtest.utils.logwraper> >sleep Time used: 6.012000s[02:14:51][DEBUG]<airtest.utils.logwraper> function: {‘time_used‘: 6.01200008392334, ‘args‘: (6,), ‘name‘: ‘sleep‘, ‘ret‘: None, ‘kwargs‘: {}}----------------------------------------------------------------------Ran 1 test in 40.255sOK[02:14:51][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo forward --remove tcp:19517[02:14:51][DEBUG]<airtest.core.android.adb> D:\AIRTES~1\airtest\core\android\static\adb\windows\adb.exe -P 5037 -s yourSerialNo forward --remove tcp:17292[02:14:51][ERROR]<airtest.core.android.rotation> orientationWatcher has endedsave log in ‘C:\Users\cmd\AppData\Local\Temp\AirtestIDE\scripts\c227edd84edf79234c03c3162327120c‘installed version is 26, installer version is 26. force_reinstall=Falseinstalled version is 0, installer version is 0. force_reinstall=Falseexiting.......EndOfStream: minicap_server[Finished]============================================================
從執行日誌來分析發現
C:/Users/cmd/AppData/Local/Temp/AirtestIDE/scripts/**
目錄下會記錄每步操作的截圖
點一下AirtestIDE 工具欄最後一項View Report 還會在上述目錄 生成個 log.html
以上便是簡單的利用AirTest提供的Android App 基於元素識別做的UI自動化小案例.
網易 UI 自動化工具 Airtest 淺用記錄