Appetizer Appetizer 整合梳理

老马 · 2017年09月27日 · 最后由 yaoziqi 回复于 2022年11月30日 · 4665 次阅读

使用目的:

1 可以补充我们目前的 APP 专项测试,比如提供了性能分析功能,异常捕获功能 ;

2 可以补充我们目前的功能回归测试,比如提供了操作回放和多设备镜像操作功能;

官方网站:

https://appetizer.io/cn/

介绍:

Appetizer 通过 DEX 插桩的方法,全自动地向 APP 内多处插入代码,在程序运行的过程中,监控异常和闪退、搜集主线程卡顿与耗时操作、HTTP/HTTPS 请求和响应、CPU 和 Java 堆内存消耗等。

采集代码经过调优,对 APP 运行性能影响小于 1%。 收集的运行数据存储在设备的本地,完成测试后上传到 Appetizer 服务端进行分析,产生详细的问题报告、各项指标等。

各项数据可以以多种格式导出,JSON, CSV, HTML,支持不同定制化数据分析以及集成服务。

特色与效果:
•测量逻辑和业务逻辑分离: Appetizer 提供测量点和测量方法,测量与业务低耦合。Appetizer 独立升级,服务升级带来更广的测量面。
•测量全面:APP 代码与库代码
•部署方便:测量代码与 APP 同进程,同权限,不需要搞 Root,HTTP 代理等等
•结合自动化遍历,夜间长时间自动遍历,找到的稳定性问题自动由质量监控捕获,上报完整、专业
•结合 UI 自动化测试,评测 APP 性能、HTTP 延时等性能问题
•低性能影响:log 到本地,控制 log 频率,数据量,以及 log 方式,对 APP 流畅性无影响

官方社区:

https://testerhome.com/topics/node127

功能组件:

1 录制与重放 Replaykit

https://github.com/appetizerio/replaykit
https://github.com/appetizerio/replaykit/blob/master/README.md
https://github.com/appetizerio/replaykit/blob/master/README.cn.md
https://github.com/appetizerio/replaykit.py/wiki/%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3
https://testerhome.com/topics/7168

Replaykit 是 Apptizer 的核心功能,它提供了如下功能:
•从单台设备录制屏幕触碰事件,在多台设备上重放(需要屏幕横宽比一致)
•同时控制多台设备(例如, 运行一个 shell 命令,安装 apk 等)
•将一台设备的屏幕触碰事件,镜像操作到多台设备上(需要屏幕横宽比一致)
•replaykit 是一个命令行工具,能够运行在 Windows 7+,MacOS Mavericks+ 和 Linux 操作系统上。一同提供的还包括 Python SDK 和 Nodejs SDK

2 插桩与监控 Insights.py

https://github.com/appetizerio/insights.py
https://testerhome.com/topics/8162

Insights.py 是 Appetizer 质量监控的 Python 客户端

windows 版本:

测试安卓应用:

需要 Appetizer 桌面客户端

应该只需要先部署好 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 及其相关工具。

关于 Android 开发环境的大家可以参考此人的博客:
Android SDK Manager 和 AVD Manager 使用

Android 开发环境配置

然后解压 Appetizer-1.2.2-win32-x64.zip 执行 Appetizer.exe 即可。

部署功能组件:

需要 Git 工具,可去\***\测试组\配置管理\ 下下载 Git-2.11.0.3-64-bit.exe 来安装。

需要 Python 环境,可去\***\测试组\Python 下来安装 py2 或 py3 。我的机器下有 appium 1.7.0 有 py3 的依赖同时有一个依赖 py2,所以如果想支持双版本同机,请先参考 Win10 下 python3 和 python2 同时安装并解决 pip 共存问题

Replaykit

先 git clone down 下来整个项目

根据官方指导,找到进入\replaykit\win32> 下即可运用相关命令行工具

也可设置 PATH,使得 appetizer 可以在全局使用
添加程序位置路径到 PATH 变量后追加即可 D:\Appetizer\replaykit\win32

Insights.py

先 git clone down 下来整个项目

进入有 requirements.txt 的项目目录下,安装相关依赖 注意选择是 python2 还是 python3 如果你已经配置了双版本 python 的话

https://github.com/appetizerio/insights.py/issues/4 遇到了个 bug 根据提示 TabError: inconsistent use of tabs and spaces in indentation 修改 insights.py 相关行的 tab 缩进改为空格缩进即可了。
是 tab 键和空格 在 win 环境下的问题。

最终还是解决了。

Linux 版本:

测试安卓应用:

我的目前系统版本是 Ubuntu16.04.2 内核 4.4.0-96-generic .
已经部署好了 android-sdk

已经默认安装的就是 python2 和 python3 系统默认用的 python 版本是 python2

设置下 pip 和 pip3

http://blog.csdn.net/heatdeath/article/details/70473828

Replaykit

也可设置 PATH,使得 appetizer 可以在全局使用 添加到/etc/profile 或~/.profile 看你个人喜好

查看下当前执行程序位置

cmd@TR:~/replaykit/linux$ pwd
/home/cmd/replaykit/linux

编辑~/.profile
sudo gedit ~/.profile

末尾追加即可

#Appetizer replaykit Path
export PATH=$PATH:/home/cmd/replaykit/linux

Insights.py

录制与重放 Replaykit

可参考以下官方以及官微提供的使用帮助和命令帮助

https://testerhome.com/topics/7168

https://github.com/appetizerio/replaykit/blob/master/README.md

https://github.com/appetizerio/replaykit/blob/master/README.cn.md

备注:“模拟器都是用鼠标和键盘操作的文本框输入的话,录制会报错截图中输入的时候报的错”
需要设置下 genymotion 的 use vitual keyboard for text input 使用这个输入,就可正常录制了。

Genymotion 模拟器录制与回放:

用到的命令有

查看连接设备 appetizer devices list

启动录制 appetizer trace record --device 192.168.60.101:5555 sg6.trace

启动回放 appetizer trace replay sg6.trace 192.168.60.101:5555

设备控制命令:

 D:\Appetizer\replaykit\win32>appetizer devices control -h
usage: appetizer devices control [-h] [--port PORT] [--host HOST]
                                 device_list
                                 {reboot,shell,install,uninstall,launch,launch_pkg,force_stop,launch_service,stop_service,kill_all,push,pull}
                                 ...

positional arguments:
  device_list           Comma-separated device serialnos
  {reboot,shell,install,uninstall,launch,launch_pkg,force_stop,launch_service,stop_service,kill_all,push,pull}
                        Control command
    reboot              Reboot multiple devices
    shell               Run a shell command on multiple devices
    install             Install an apk to multiple devices
    uninstall           Uninstall an app (package name) from multiple devices
    launch              Launch an app (based on package name and activity
                        name)
    launch_pkg          Launch the default activity of an app (given package
                        name)
    force_stop          Force-stop an app, not graceful kill
    launch_service      Launch a service (based on package name and service
                        class name)
    stop_service        Stop a service (based on package name and service
                        class name)
    kill_all            Kill all background apps
    push                Push a file to the devices
    pull                Pull a file from the devices

optional arguments:
  -h, --help            show this help message and exit
  --port PORT, -P PORT  ADB server port
  --host HOST, -H HOST  ADB server host

安装 apk 命令:

待安装的 apk 需要放到 appetizer 执行路径下。如果未配置全局 PATH,就是\replaykit\win32\下。

 D:\Appetizer\replaykit\win32 的目录

2017/10/10  10:22    <DIR>          .
2017/10/10  10:22    <DIR>          ..
2017/05/19  09:33        17,876,212 acp_android_v4_2_0-233611.apk
2017/09/27  15:19            71,168 appetizer.exe
2017/09/27  15:19            93,696 bz2.pyd
2017/09/27  15:19           354,488 cacert.pem
2016/02/24  08:57            25,931 ContactManager.apk
2017/09/27  15:19         1,852,200 CRYPT32.dll
2017/09/27  15:19         4,396,757 library.zip
2017/09/27  15:19           180,736 pyexpat.pyd
2017/09/27  15:19         3,024,384 python27.dll
2017/09/27  15:19            12,800 select.pyd
2017/09/15  14:41        17,591,017 test.apk
2017/09/27  15:19           693,248 unicodedata.pyd
2017/09/27  15:19    <DIR>          vendor
2017/09/27  15:19           121,344 _ctypes.pyd
2017/09/27  15:19           181,760 _elementtree.pyd
2017/09/27  15:19         1,478,144 _hashlib.pyd
2017/09/27  15:19            35,840 _multiprocessing.pyd
2017/09/27  15:19            51,712 _socket.pyd
2017/09/27  15:19         2,094,592 _ssl.pyd
              18 个文件     50,136,029 字节
               3 个目录 96,896,315,392 可用字节

D:\Appetizer\replaykit\win32>appetizer devices control 192.168.60.101:5555 install acp_android_v4_2_0-233611.apk

重复安装提示已存在

D:\Appetizer\replaykit\win32>appetizer devices control 192.168.60.101:5555 install acp_android_v4_2_0-233611.apk
Error while executing shell command Install: WARNING: linker: /system/lib/libhoudini.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
        pkg: /data/local/tmp/acp_android_v4_2_0-233611.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]

启动 apk 命令:

先查下当前 app 的 package 名
这个是原生的 adb shell 命令查看

D:\Appetizer\replaykit\win32>adb shell pm list packages -3
WARNING: linker: /system/lib/libhoudini.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
package:com.macaca.android.testing.test
package:com.acp.aicaitencent
package:com.github.android_app_bootstrap
package:xdf.android_unlock
package:com.macaca.android.testing
package:com.qdtevc.teld.app
package:com.example.android.apis
package:com.android.gesture.builder

这个是 appetizer 方式,根据说明 appetizer 是完全兼容 adb 命令的,adb 有的 appetizer 都可以稍微改下即可用。

D:\Appetizer\replaykit\win32>appetizer devices control 192.168.60.101:5555 shell  pm list packages -3
{"192.168.60.101:5555": "WARNING: linker: /system/lib/libhoudini.so has text relocations. This is wasting memory and prevents security hardening. Please fix.\r\npackage:com.macaca.android.testing.test\r\npackage:com.acp.aicaitencent\r\npackage:com.github.android_app_bootstrap\r\npackage:xdf.android_unlock\r\npackage:com.macaca.android.testing\r\npackage:com.qdtevc.teld.app\r\npackage:com.example.android.apis\r\npackage:com.android.gesture.builder\r\n"}

启动该 app

D:\Appetizer\replaykit\win32>appetizer devices control 192.168.60.101:5555 launch_pkg com.acp.aicaitencent

Replaykit1.0.6 命令行:

官方的 GitHub 的命令行帮助我对比了下,不是最新内容的。大家可以自行利用逐级添加 -h 来了解提供的命令行参数。几乎每个 -h 都有帮助。
比如 第一级 appetizer -h 第二级 appetizer trace -h 第 2.1 级 appetizer trace info -h 第 2.2 级 appetizer trace replay -h 第 2.3 级 appetizer trace record -h,其余用法类似。
整体上比较有层次感 ,我逐级选主要的提纲如下:

1

appetizer -h
usage: appetizer [-h] [-v VERBOSE]
                 {version,update,trace,adb,devices,plan,insight} ...

positional arguments:
  {version,update,trace,adb,devices,plan,insight}
                        commands
    version             Print the version information and exit
    update              Check and update the appetizer
    trace               Record and replay touchscreen events
    adb                 Control the local ADB
    devices             Command devices
    plan                Compose and execute a test plan file
    insight             Appetizer Insight commands

optional arguments:
  -h, --help            show this help message and exit
  -v VERBOSE, --verbose VERBOSE
                        Set the verbose

2

appetizer trace -h
usage: appetizer trace [-h] {info,replay,record} ...

positional arguments:
  {info,replay,record}  actions
    info                Get the detail of a trace file
    replay              Replay a touchscreen event trace to some devices
    record              Record a trace of touchscreen events

optional arguments:
  -h, --help            show this help message and exit

3

appetizer adb -h
usage: appetizer adb [-h]
                     {check-server,start-server,kill-server,detectadb} ...

positional arguments:
  {check-server,start-server,kill-server,detectadb}
                        actions on the adb server
    check-server        Check the state of the adb server
    start-server        Start the adb server
    kill-server         Kill the adb server
    detectadb           Detect the path to the adb program

optional arguments:
  -h, --help            show this help message and exit

4

appetizer devices -h
usage: appetizer devices [-h] {list,screenshot,mirror,control} ...

positional arguments:
  {list,screenshot,mirror,control}
                        actions on the devices
    list                List the details of connected devices
    screenshot          Take a screenshot
    mirror              Mirror the touchscreen events from one device to many
                        in real-time
    control             Control devices

optional arguments:
  -h, --help            show this help message and exit

5

appetizer plan -h
usage: appetizer plan [-h] {run} ...

positional arguments:
  {run}       actions on a test plan
    run       Run a test plan containing multiple steps

optional arguments:
  -h, --help  show this help message and exit

6

appetizer insight -h
usage: appetizer insight [-h] {fetchlog,clearlog} ...

positional arguments:
  {fetchlog,clearlog}  sub commands
    fetchlog           Fetch execution logs from multiple devices and compress
                       into single file
    clearlog           Delete execution logs generated by an app on multiple
                       devices

optional arguments:
  -h, --help           show this help message and exit

Appetizer 主要操作步骤

参考:
https://github.com/appetizerio/insights.py
https://testerhome.com/topics/7168
https://testerhome.com/topics/8162

可直接用 Appetizer Desktop UI 界面中的质量监控手工图形化操作,也可利用命令行工具操作

一 插桩 APK

登录 Appetizer 账号

cd insights.py
python insights.py login username password

插桩 apk
python insights.py process my.apk my_processed.apk

二 安装插桩后 apk

安装插桩后 apk
adb install my_processed.apk

向多个设备安装插桩后 apk
python insigths.py install my_processed.apk -s serialno1 -s serialno2

可选操作:
清除老的 apk 生成的 log
adb shell rm /sdcard/io.appetizer/.log

赋权限,确认 APP 有读写 sdcard 的权限
adb shell pm grant my.apk android.permission.READ_EXTERNAL_STORAGE
adb shell pm grant my.apk android.permission.WRITE_EXTERNAL_STORAGE
注意这里的 my.apk 应该是包名 : 如我的就是 com.acp.aicaitencent

三 手工或用其他自动化框架测试插桩后 APP

可启动插桩后 app,进行手工业务测试。这时插桩后 app 将在设备的/sdcard/io.appetizer/ 目录生成日志。
也可选择调用其他 appium macaca Appcrawler monkey 等第三方自动化测试框架驱动来进行自动化 UI 业务随机遍历或业务串流测试。

比如 Appcrawler:

我们可以在 Appetizer Desktop UI 界面中。质量监控-》我的插桩包。下载插桩过的 apk 到本地 D:\appcrawler\apk 目录下,并重命名为 acp.apk。同时创建结果保存目录 D:\appcrawler\result

参考如下执行 Appcrawler 遍历测试。

appium --session-override -p 4730

java -jar appcrawler-2.0.0.jar -p android -a D:\\appcrawler\\apk\\acp.apk -u http://127.0.0.1:4730/wd/hub -o result/
或者
java -jar appcrawler-2.1.1.jar   -p android  --capability appPackage=packagename appActivity=activityname -u  http://127.0.0.1:4730/wd/hub   -o result/ 

四 上传 log 获取报告

先登录 insights.py
cd insights.py
python insights.py login username password

上传 log 获取分析报告
python insights.py analyze my_processed.apk

上传多个设备上的 log 获取分析报告
python insights.py analyze my_processed.apk -s serialno1 -s serialno2 --clear
--clear 是可选参数,用于设备下载 log 后将设备上 log 清空

其他功能
将设备上有指定插桩后的 apk 的 log 清除
python insigths.py clearlog my_processed.apk -s serialno1 -s serialno2 --clear

报告动图:

附录:

adb 命令帮助:
https://github.com/mzlogin/awesome-adb

Bug 修复

1 win10 python 命令行登录 bug。

D:\Appetizer\insights.py>python3 insights.py login name password
Traceback (most recent call last):
  File "insights.py", line 404, in <module>
    sys.exit(main())
  File "insights.py", line 400, in main
    return args.func(args)
  File "insights.py", line 97, in login
    }, verify=False)
  File "D:\Python36\lib\site-packages\requests\api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "D:\Python36\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\Python36\lib\site-packages\requests\sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Python36\lib\site-packages\requests\sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "D:\Python36\lib\site-packages\requests\adapters.py", line 440, in send
    timeout=timeout
  File "D:\Python36\lib\site-packages\urllib3\connectionpool.py", line 595, in urlopen
    self._prepare_proxy(conn)
  File "D:\Python36\lib\site-packages\urllib3\connectionpool.py", line 816, in _prepare_proxy
    conn.connect()
  File "D:\Python36\lib\site-packages\urllib3\connection.py", line 284, in connect
    conn = self._new_conn()
  File "D:\Python36\lib\site-packages\urllib3\connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "D:\Python36\lib\site-packages\urllib3\util\connection.py", line 51, in create_connection
    if host.startswith('['):
AttributeError: 'NoneType' object has no attribute 'startswith'`

可能遇到该问题,可如下修复:
该登录问题已经确认,是由于 windows 系统 注册表一个键值引起的。
大家可如下解决:
win+R 输入 regedit 回车打开注册表
在操作注册表前,请利用导出功能备份注册表。以防误操作或操作不当引发其他系统故障后可恢复。
找到 计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
该位置下 找到 ProxyEnable 并删除掉。然后关掉注册表。
在尝试命令登录 python3 insights.py login 账号 密码

便可成功登录了。
补充说明,原贴是要求删除该键值 ProxyEnable 并重新建一同名 ProxyEnable 键值,值设置为 REG_DWORD 16 进制 0 而我并无法按照原贴新建,遇到无法重命名的问题。我是直接删掉关闭注册表,试了下,就登录 OK 了。再重新打开注册表,发现系统自动创建了该值。如下图,如果删除再登录无效,可尝试手工建立该值。

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

还有测试报告点击打开,页面空白,这是怎么搞

问一下为什么一启动驱动,server 就关闭了

楼主你好,连接手机后,点击开始测试没问题,后面再点击的时候,总提示 “设备上的插桩数据不存在或者没内容”。您知道是怎么回事吗?

楼主你好,我想问下我使用了 appetizer 运行 Maxim,配置都设置好了,点击开始测试后,控制台输出为空,而且并没有执行 adb 命令,这是为什么呢,如果不使用 appetizer 只使用 adb 命令就没问题

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

2018年6月14日replaykit 文件夹下 git pull 后,有重大更新.
以前的命令 appetizer 开头的 都将替换调整为

cmd@TR:~$ replaykit -h
usage: replaykit [-h] [-v VERBOSE]
                 {version,update,trace,adb,devices,plan,insight} ...

positional arguments:
  {version,update,trace,adb,devices,plan,insight}
                        commands
    version             Print the version information and exit
    update              Check and update the appetizer
    trace               Record and replay touchscreen events
    adb                 Control the local ADB
    devices             Command devices
    plan                Compose and execute a test plan file
    insight             Appetizer Insight commands

optional arguments:
  -h, --help            show this help message and exit
  -v VERBOSE, --verbose VERBOSE
                        Set the verbose

replaykit 发新版了,这次大变革是改了名字 ./darwin/appetizer 变成了./darwin/replaykit,是为了更好地区分 Appetizer (图形化界面,插桩等)和 replaykit(设备控制,录制重放),README 也更新了,之前接入了 jenkins/python 的同学们可能要调整一下;此次更新主要是更新驱动,支持到 Android P,然后修了修改 trace 描述的命令的 bug

老马 回复

插桩的部分有开源吗?

镜像同步好像用不了,报告也生成不了,加群没反应。。。

老马 #11 · 2017年10月26日 Author
原生 回复

appetizer trace replay -h

AppetizerIO 回复

突然又好了,可能是本机的环境问题。请问下,回放录制 有什么方式可以添加回放次数,。现在录制完后执行只有一遍。

原生 回复

加群发截图看看

无法识别设备,是怎么回事,adb devices 设备是正常出现的

adonisjph 回复

录制,重放,批量 adb 命令。可以 adb shell 的用 adb shell,不行的可以打开设置后用重放之类的~

adonisjph 回复

应该可以,有重新封装 adb shell。

replaykit 针对应用录制外,可以对录制包括对系统设置的操作么,比如修改系统语言,修改时区等。

老马 回复

明天看下 replaykit 前几天刚好有人提这需求

老马 #19 · 2017年09月27日 Author
codeskyblue 回复

国产实力原创!!!全部开源

没想到还有这玩意,功能好强大。开源的吗?

总结的不错.. 👏 👏 👏

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