0
点赞
收藏
分享

微信扫一扫

Appium统计iOS或者Android应用的性能

我们知道可以通过Appium来控制iOS或者Android设备,进而做一些自动化测试的任务,那么如果我们想收集应用(APP)的基础性能数据呢?

1、手动统计方法

Andriod设备可以通过adb命令("adb shell top")来简单的手机,iOS设备可以xCode的instruments工具来统计,如下所示,事实上也适用于Mac设备。

2、自动化统计方法

那么这些统计方式怎么集成到我们的自动化工具中呢?

appium的官方给我们提供了对应封装,如:“Execute Mobile Command”方法,参考官网:Execute Mobile Command - Appium

我在使用的时候主要用的"mobile: startPerfRecord"“mobile: stopPerfRecord” ,具体参数等使用参考官网:https://github.com/appium/appium-xcuitest-driver#platform-specific-extensions

代码片段如下,timeout字段单位为毫秒(ms),代表的是最大的采集时间,默认为5分钟,如果你想要采集的时间大于5min,需要更改下。pid不填的话代表采集的是所有的进程,为current时代表的是当前活跃的进程。

# profileName不填的话默认为: {"profileName": "Activity Monitor"}

# 开启采集
driver.execute_script("mobile: startPerfRecord", {"profileName": "Activity Monitor",
                                                  "timeout": 600000, "pid": "current"})

# 采集时间: 80s
time.sleep(80)

# 结束采集, 并保存zip文件,如: trace.zip
b64_zip = str(driver.execute_script("mobile: stopPerfRecord"))
bytes_zip = base64.b64decode(b64_zip)

trace_zip_filename = "trace.zip"
with open(trace_zip_filename, 'wb') as fz:
    fz.write(bytes_zip)
举报

相关推荐

0 条评论