步骤一:搭建nginx
# 带ip的方式
server {
listen 9999;
server_name 100.100.100.159;
location / {
root /usr/share/nginx/reports;
autoindex on;
}
error_page 500 502 503 504 /50x.html;
}
# 带域名的方式
server {
listen 9999;
server_name 你的域名.com;
location / {
root /usr/share/nginx/reports;
autoindex on;
}
error_page 500 502 503 504 /50x.html;
}
步骤二:运行测试测试用例,生成测试报告
- 运行自己的代码,生成测试报告
- 并把移动测试报告到nginx地址: /usr/share/nginx/reports
- 浏览器打开域名/ip:9999,查看测试报告
步骤三:通过jenkins发送测试报告到飞书机器人
1. 配置机器人
2. 配置 webhook
3. 开发代码
def send_feishu(report_url):
"""
发送到飞书
:return:
"""
url = "自定义机器人webhook 地址"
header = {"Content-Type": "application/json"}
data = {"msg_type": "post", "content": {"post": {"zh_cn": {"title": "测试报告",
"content": [[{"tag": "text", "text": "测试报告已生成,请查看:"}],
[{"tag": "text", "text": report_url}],
[{"tag": "at", "user_id": "all", "user_name": "所有人"}]]}}}}
s = requests.post(url=url, data=json.dumps(data), headers=header)
print(s.json())