一份漂亮的使用Airtest批量执行案例脚本并聚合报告的方法
通过搜集网络上已有的解决方案以及自己研究airtest底层的代码,整理出适合大致的批量执行Airtest脚本的解决方法。
效果图如下:
代码目录结构:
执行结果图:
点击案例名称调整至详细报告:
解决方案:
在Python3.6环境下新建myRunner.py文件:编写如下代码
from airtest.cli.runner import AirtestCase, run_script
from argparse import *
import airtest.report.report as report
import jinja2
import shutil
import os
import io
class CustomAirtestCase(AirtestCase):
def setUp(self):
print("custom setup")
# add var/function/class/.. to globals
# self.scope["hunter"] = "i am hunter"
# self.scope["add"] = lambda x: x+1
# exec setup script
# self.exec_other_script("setup.owl")
super(CustomAirtestCase, self).setUp()
def tearDown(self):
print("custom tearDown")
# exec teardown script
# self.exec_other_script("teardown.owl")
super(CustomAirtestCase, self).setUp()
def run_air(self, root_dir='D:\\tools\\airtestCase\\案例集', device=['android://127.0.0.1:5037/99.12.74.40:7281']):
# 聚合结果
results = []
# 获取所有用例集
root_log = root_dir + '\\' + 'log'
if os.path.isdir(root_log):
shutil.rmtree(root_log)
else:
o