selenium12_HTML测试报告(run_all)
在run_all.py中编写如下脚本:
# cording:utf-8
import unittest
import os
from common import HTMLTestRunner_cn
#os.path.dirname: 获取当前文件所在的文件夹路径。 os.path.realpath(__file__):根据不同的系统自动获取绝对路径,包含文件名
cur_path = os.path.dirname(os.path.realpath(__file__))
print("当前文件所在路径:",cur_path)
case_path = os.path.join(cur_path, "case")
print("testcase的路径:", case_path)
pattern = "test*.py"
#加载用例(start_dir为用例路径,pattern为用例文件)
discover = unittest.defaultTestLoader.discover(start_dir=case_path,pattern=pattern)
#报告的目录不存在会报错,此处判读报告的目录是否存在,不存在则创建
report_path = os.path.exists(os.path.join(cur_path, "report"))
if not report_path:
os.mkdir(os.path.join(cur_path, "report"))
report = os.path.join(cur_path, "report", "report.html")
fp = open(report, "wb")
#运行用例,生成HTML报告(stream为报告的保存路径; verbosity=1报告中不展示注释,=2展示注释)
runner = HTMLTestRunner_cn.HTMLTestRunner(stream=fp, verbosity=2, title="自动化测试结果", description="登陆成功")
runner.run(discover)

浙公网安备 33010602011771号