1. 程式人生 > >Airtest網易自動化測試工具

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-reinstall
Collecting pip
  Using cached pip-9.0.2-py2.py3-none-any.whl
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>pip2 -V
pip 9.0.2 from d:\python27\lib\site-packages (python 2.7)
#檢查pip3
C:\Users\cmd>pip3 -V
pip 9.0.2 from d:\python36\lib\site-packages (python 3.6)
#檢查pip2 python2已安裝庫
C:\Users\cmd>pip2 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 (28.8.0)
#檢查pip3 python3已安裝庫
C:\Users\cmd>pip3 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 (28.8.0)
#檢查哪些python3庫需要升級
C:\Users\cmd>pip3 list -o
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.
setuptools (28.8.0) - Latest: 39.0.1 [wheel]
# 升級該庫
C:\Users\cmd>pip3 install --upgrade setuptools
Collecting setuptools
  Downloading setuptools-39.0.1-py2.py3-none-any.whl (569kB)
    100% |████████████████████████████████| 573kB 815kB/s
Installing collected packages: setuptools
  Found existing installation: setuptools 28.8.0
    Uninstalling setuptools-28.8.0:
      Successfully uninstalled setuptools-28.8.0
Successfully 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 [email protected]/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 [email protected]/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.255s

OK
[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 ended
save log in 'C:\Users\cmd\AppData\Local\Temp\AirtestIDE\scripts\c227edd84edf79234c03c3162327120c'
installed version is 26, installer version is 26. force_reinstall=False
installed version is 0, installer version is 0. force_reinstall=False
exiting.......
EndOfStream: minicap_server
[Finished]

============================================================

從執行日誌來分析發現 
C:/Users/cmd/AppData/Local/Temp/AirtestIDE/scripts/**    
目錄下會記錄每步操作的截圖

點一下AirtestIDE 工具欄最後一項View Report 還會在上述目錄 生成個 log.html

 

以上便是簡單的利用AirTest提供的Android App 基於元素識別做的UI自動化小案例.