通过AppiumUI自动化收集iOS-App性能数据的方法:
1.自定义Instruments 模板
通过自定义 Instruments 模板可以实现在执行自动化操作的同时记录性能数据。模板需包含如下 instrument:
UI Automation
Activity Monitor
Core Animation
2.Appium 参数配置
2.1配置 iOS Settings > Advanced > Trace Template Path 指向上述模板,让 Appium 使用该模板启动 Instruments
2.2 或者Appium命令行参数里增加tracetemplate模板
Appium –tracetemplate AUTOMATIONTRACETEMPLATEPATH
(IOS-only) .tracetemplate file to use with Instruments
3.执行测试case
Appium测试脚本跑完后,Instruments 生成的 Trace 数据默认保存在 /tmp/appium-instruments 下面
4.解析结果
用./InstrumentsParser解析instrumentscli0.trace文件成.json文件
$ ./InstrumentsParser -p DPScope -i /tmp/appium-instruments/instrumentscli0.trace
5.结果展示
1.json2csv
2.处理数据,使用 Highcharts 图表库 进行展示
if __name__ == '__main__':
trace_template = os.path.join(os.path.dirname(__file__), "perf-report/NovaPerfDevice.tracetemplate")
trace_template = os.path.abspath(trace_template)
appiumServer = subprocess.Popen("appium --no-reset --log-level error:error --tracetemplate " + trace_template, shell=True)
#appiumServer = subprocess.Popen("appium --no-reset --tracetemplate " + trace_template, shell=True)
time.sleep(5)
suite = unittest.TestLoader().loadTestsFromTestCase(PerformanceCollectionTest)
result = unittest.TextTestRunner(verbosity=2).run(suite)
time.sleep(2)
print('Generating report...')
subprocess.Popen("sh generate-ios-perf-report.sh", shell=True)
time.sleep(5)
os.system("ps -ef | grep appium |"
" awk '{print $2}' |xargs kill {} 2>/dev/null")
if not result.wasSuccessful():
exit(1)