Airtest 网易 UI 自动化工具 Airtest 浅用记录

老马 · 2018年03月19日 · 最后由 皮大大的豆花皮 回复于 2019年04月10日 · 9534 次阅读
本帖已被设为精华帖!

一 使用目的

该工具主要是面向游戏 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 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.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 自动化小案例.

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 26 条回复 时间 点赞

小马哥这篇真是太详细了。。。。。!!!😘 😘 😘

超级赞,省的一个个找了!非常棒~~

这个写的还是写详细的,给你赞了。

思寒_seveniruby 将本帖设为了精华贴 03月19日 19:26

说的好详细 图文并茂 赞一个

只支持 python 吗?

之前问了下 ios app 也是支持的 不过现在的代码里是一个基于 facebook wda 的实现,不太好用,他们现在正在开发

写的很详细,点赞

没有 java 支持版么?遗憾😭 😭 😭 😭 😭 😭

回去研究一下,谢谢整理~

Google 方面评价,这可能是目前世界上最好的 Android 游戏自动化测试方案

https://news.cnblogs.com/n/592278/

匿名 #13 · 2018年03月21日
槽神 回复

这个东西的技术方面我还是觉得挺厉害的,但是不至于 google 合作发布跟 google 还认可 “这可能是世界上最好的 Android 自动化测试方案了”,不要太吹水贴金就行。

被 google 评价为可能是最好的游戏 app 自动化测试工具,牛逼的

请你看清楚再说话,哪里有这么一句 “这可能是世界上最好的 Android 自动化测试方案了”

试用一下挺爽的,录制和回放都很流畅。
目前有个缺憾是 gui 还没有开源,安装包在离线时候用不了,它要在线下载 jquery 的 js。


为何我这里的 poco 下拉菜单里,没有 netease 选项呢?..

匿名 #18 · 2018年03月27日
yyy 回复

netease 那个选项是给网易内部的几个自研引擎用的,就没有放出来

非常详细,感谢整理分享

非常详细,感谢分享~~

您好,我可以直接 pip 安装这个库,进行自动化吗?

我敢保证这个是我亲耳听的,当时合作立项阶段我们老大在跟 google FTL 项目组老大演示的时候,他惊讶的眼神,还有他的评价,我记得一清二楚。

请问 airtestIDE 的代码是开源的吗?github 上的开源代码并没有找到 ide 相关的内容呢?

网易,我他娘的爱死你了

激活使用 virtualenv 虚拟环境,为什么路径下找不到这个文件:activate.bat

simple 专栏文章:[精华帖] 社区历年精华帖分类归总 中提及了此贴 12月13日 14:44
simple [精彩盘点] TesterHome 社区 2018 年 度精华帖 中提及了此贴 01月07日 12:08

希望楼主出个进阶版的登录测试用例,比如账号密码参数化

我用连手机然后启动游戏横屏以后,网易自带的模拟器每次都不适配我的手机大小,找不到想要的元素,不知道为什么不适配

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册