生成测试报告 allure 测试报告
allure report:
1、下载allure-commandline-2.21.0.zip,解压把allure-2.21.0放到D盘;配置环境变量;
2、allure --version 检查版本是否显示;
3、安装allure-pytest pip install allure-pytest 测试报告中是有数据的,生成测试数据;(2.9.45)
编写运行测试报告的代码:
if __name__ == '__main__':
# pytest.main(['-s','-v','-rA','test_case01.py'])
pytest.main(['-s','test_case01.py','--clean-alluredir','D:\\idea_seleniumPro\\testpytest\\allure-result'])
os.system('allure generate D:\\idea_seleniumPro\\testpytest\\allure-result -o D:\\idea_seleniumPro\\testpytest\\reposts' )
生成报告样式:
unittest 框架测试 HTMLTestRunner 生成测试报告:
编写运行生成测试报告的代码
#coding=utf-8
import unittest
import HTMLTestRunner
if __name__ == '__main__':
# # -004----------------执行unittest.TestSuite()
# 指定测试用例的所在的目录路径,进行加载
suite = unittest.TestSuite()
loader = unittest.TestLoader()
suite.addTest(loader.discover(start_dir=r"D:\idea_seleniumPro\unittest", pattern="test*.py"))
html_file = "D:\\idea_seleniumPro\\Outputs\\reports\\reportSHTWEB.html"
fp = open(html_file, "wb")
HTMLTestRunner.HTMLTestRunner(fp,title="测试报告",description="点击系统项目测试内容:").run(suite)
fp.close()
#SendEmailReport().is_result_pass()
生成报告样式:
优化后自动化报告
1.批量执行用例,输出邮件消息或群消息、报告、日志、截图;
如何批量执行用例及用例执行完后需要数据处理?
#coding=utf-8
import allure
import pytest,os
from common.process_redis import Process
from common.ding_talk import send_dingtalk_msg_markdown
if __name__ == '__main__':
pytest.main(['-s', 'D:\\code\\idea_selenium_clicksystem\\case', '--alluredir', 'D:/code/idea_selenium_clicksystem/Outputs/allure-result'])
os.system('allure generate D:/code/idea_selenium_clicksystem/Outputs/allure-result -o D:/code/idea_selenium_clicksystem/Outputs/reports/allure-reports --clean')
# 获取测试结果
total, success, fail, _ = Process().get_result()
failed_testcases_name = ",失败的用例为:"
msg_str = f"测试通过{str(success)}个,失败{str(fail)}个"
# 如果有失败的,就加上失败的用例名称
if int(fail) > 0:
msg_str += failed_testcases_name
fail_testcase_names = Process().get_fail_testcase_names()
for i in range(len(fail_testcase_names)):
if i == len(fail_testcase_names) - 1:
failed_testcases_name += fail_testcase_names[i]
else:
failed_testcases_name += fail_testcase_names[i] + ","
msg_str += fail_testcase_names[i] + "\n"
else:
failed_testcases_name = ""
# 插入测试结束时间
Process().write_end_time()
# 更改运行状态为0
Process().modify_running_status(0)
# 项目名称
project_name = "click_system_autotest"
# 报告标题
report_title = "UI自动化测试-测试报告"
# allure测试报告地址
allure_url = "http://"
webhook = "https://"
send_dingtalk_msg_markdown(
ding_webhook=webhook,
allure_url=allure_url,
total_count=total,
success_count=success,
fail_count=fail,
failed_testcases_name=failed_testcases_name,
report_title=report_title
)
报告中优化步骤:
@allure.story('上传记录删除数据包功能') allure.dynamic.title(data['title']) allure.dynamic.description(data['description'])