网易 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>python2Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> exit()#Python3检查C:\Users\cmd>python3Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> exit()#pip3部署C:\Users\cmd>python3 -m pip install --upgrade pip --force-reinstallCollecting pip  Downloading pip-9.0.2-py2.py3-none-any.whl (1.4MB)    100% |████████████████████████████████| 1.4MB 746kB/sInstalling 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#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虚拟环境的话,查起来就方便减少了迷惑.

#安装virtualenvC:\Users\cmd>pip3 install virtualenvCollecting virtualenv  Using cached virtualenv-15.1.0-py2.py3-none-any.whlInstalling collected packages: virtualenvSuccessfully installed virtualenv-15.1.0#激活使用该virtualenvC:\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 Airtest364Running virtualenv with interpreter D:\Python36\python3.exeUsing base prefix ‘D:\\Python36‘New python executable in C:\Users\cmd\Airtest364\Scripts\python3.exeAlso creating executable in C:\Users\cmd\Airtest364\Scripts\python.exeInstalling setuptools, pip, wheel...done.#切换到Airtest364下并激活该环境C:\Users\cmd>cd Airtest364\ScriptsC:\Users\cmd\Airtest364\Scripts>activate.bat#检查虚拟环境初始化安装的Python库(Airtest364) C:\Users\cmd\Airtest364\Scripts>pip 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 (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 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.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 -vAndroid Debug Bridge version 1.0.39Revision 3db08f2c6889-androidInstalled 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 -lList of devices attachedyourSerialNo          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 AndroidUiautomationPocopoco = AndroidUiautomationPoco(force_restart=False)

# start your script hereconnect_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.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自动化小案例.

原文地址:https://www.cnblogs.com/tiechui2015/p/9945964.html

时间: 2024-07-31 20:15:14

网易 UI 自动化工具 Airtest 浅用记录的相关文章

一款“燃到爆”的安卓UI自动化遍历测试工具

介绍:4399AT是一款基于APPIUM框架改造和集于算法遍历,图像识别技术的自动化测试工具 工具:适用于Android App UI自动化 电脑系统:win10 64位 工具好处:解决不同手机安装提示和APP操作提示框,兼容不容手机控件,adb不稳定,PO模式等问题,具体可关注微信公众号"测试一般不一般" 进行相关资料查看. 以下是关于该工具的使用说明,详情API可查看api文档 环境检查 点击该按钮,进行jdk-node-sdk-appium环境检查,当环境中缺少jdk.node或

如何用Airtest编写UI自动化脚本

前言 游戏并不像app一样直接把渲染树节点暴露出来,这就造成游戏UI自动化在元素定位上的不方便性,不过依赖airtest的图片识别,我们可以直接跳过元素检查,以图片对比的形式进行自动化,虽然效率可能会低一些,但是至少也是自动化了. 脚本文件的创建 首先需要创建脚本文件,airtest提供了两种格式的文件——.air后缀和.py后缀: 虽说分开了两种,但两者之前其实差别不是很大(源码中.air文件最终也是较换成.py文件执行),具体选择哪个看个人喜好,个人比较喜欢纯python文件,因此创建的为.

自动化--APP UI自动化--Airtest学习

看到其他同事在使用airtest,于是学习一下 AirtestIDE提供了一个比较全的官方文档,讲解.操作都蛮细的 http://airtest.netease.com/docs/docs_AirtestIDE-zh_CN/index.html 使用airtest执行ui自动化,首先要: 1.安卓 AirtestIDE 官方安装  http://airtest.netease.com/ 或 网盘安装: 链接:https://pan.baidu.com/s/1IaTR_ZPxy81mCPwGsyR

C#最佳工具集合:IDE、分析、自动化工具等

原文:C#最佳工具集合:IDE.分析.自动化工具等 C#是企业中广泛使用的编程语言,特别是那些依赖微软的程序语言.如果您使用C#构建应用程序,则最有可能使用Visual Studio,并且已经寻找了一些扩展来对您的开发进行管理.但是,这个工具列表可能会改变您编写C#代码的方式. C#编程的最佳工具有以下几类: IDE VS扩展 编译器.编辑器和序列化 反编译和代码转换工具 构建自动化和合并工具 版本控制 测试工具和VS扩展 性能分析 APM 部署自动化 容器 使用上面的链接直接跳转到特定工具,或

【Android测试】UI自动化代码优化之路(临时发布)

关于UI自动化的抱怨 听过不少人这样讲 "UI自动化非常不稳定,需求一改,界面一遍,全部都费了".我相信做过的人可能也会有同感.既然这个问题一直都是存在的,那么为什么没有人仔细分析原因呢? 我的老板georgeliao举了这样一个例子:每当需求变化的时候,开发没有跳起来,反而是测试跳了起来.然后不断的抱怨,界面元素全都改了,我的自动化的用例全部都要废弃掉了.那么我们是否想过,为什么开发可以从容不破的应对产品不断变化的需求?而我们却不能呢? 业内不少人也都放弃了UI自动化,觉得接口测试才

pytest+python下的UI自动化基础框架

整体设计模式: config目录:存放一些公共的静态文件,如项目名称,配置文件等这些环境变量(可以用其他组件替换,如sql,主要能把配置文件的内容被程序识别). httptrquest目录:存放接口代码,UI自动化因为其稳定性问题会出现有些地方出错导致后续无法进行,故添加接口操作. initailize目录:初始化代码,用于存放初始化操作的代码,比如初始化一些全局变量,初始化webdriver等,应用于整个项目的代码. test目录:真正执行的目录,用于存放测试用例的代码,会被pytest识别将

selenium-java,解决一些加了显性等待和隐性等待都不好使的情况,以及给UI自动化加上暂停功能

最近在UI自动化时遇到了,上一步成功操作后没有响应的情况(动画加载和浏览器加载导致实际没有问题),导致下一步无法成功操作,所有想在尝试2次操作后再次进行上一步操作解决这种情况导致的错误(其实是不想每一次有问题都要手动加线程沉睡) 1.java应用程序,暂停/开始按钮 import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionL

腾讯、网易、新浪新闻网站爬虫编写记录及评论格式分析

0 前言 先说说看这篇博客你能知道什么:1 腾讯.网易.新浪不同新闻的地址格式以及评论内容的地址格式(返回数据为json的异步接口):2 一些比较通用的设计方法,对软件设计的菜鸟可能有帮助: 之前也说了要写这边博客,现在终于写出来了.我的毕业设计的指导老师说毕设论文的字数不够--所以我决定把这些本不应该出现在论文中的实现细节凑到论文中.至于下面说到的东西要解决什么问题,各位可以先看看这个网站(我毕设的初步结果,目前还在优化中,包括代码结构还有UI设计):http://reetseenews.du

UI自动化,你值得拥有

去年春节联欢晚会,为了那张“敬业福”,全家都卯足了劲儿“咻一咻”,连节目都顾不上看了.当时我就想,要是能自动化该多好,不停点击屏幕,屏幕不疼手还疼呢,何况还不好分心,生怕错过了“敬业福”.玩“咻一咻”,是靠不停点击按钮来检查是否得到“敬业福”,而工作中的UI自动化,大抵也和“咻一咻”差不多,都是通过不断地输入,验证系统的输出是否正确.然而做UI自动化,效果并不好,收益低就算了,执行速度还慢.比如打开一个浏览器,可能就要等3-5秒,如果等浏览器访问网址,返回网页内容,就需要更长的时间.要是遇到问题