提交 ab675143 authored 作者: 陈泽健's avatar 陈泽健

增加get_test_result函数通过正则匹配获取通过率、失败率以及异常率,再调用钉钉消息通知输出通过率等值。

上级 a84fc014
...@@ -563,12 +563,12 @@ def get_latest_report_file(report_dir, base_url): ...@@ -563,12 +563,12 @@ def get_latest_report_file(report_dir, base_url):
# 返回完整的URL # 返回完整的URL
return full_url return full_url
def dingding_send_message(test_report_url, title, mobile, ding_type): def dingding_send_message(latest_report, title, mobile, ding_type):
""" """
发送钉钉机器人消息 发送钉钉机器人消息
参考接口文档:https://open.dingtalk.com/document/orgapp/custom-robots-send-group-messages#title-7fs-kgs-36x 参考接口文档:https://open.dingtalk.com/document/orgapp/custom-robots-send-group-messages#title-7fs-kgs-36x
:param test_report_url: 测试报告链接 :param latest_report: 测试报告链接
:param title: 消息标题 :param title: 消息标题
:param text: 消息内容 :param text: 消息内容
:param mobile: 需要@的手机号列表 :param mobile: 需要@的手机号列表
...@@ -609,14 +609,21 @@ def dingding_send_message(test_report_url, title, mobile, ding_type): ...@@ -609,14 +609,21 @@ def dingding_send_message(test_report_url, title, mobile, ding_type):
# 记录最终的 Webhook URL # 记录最终的 Webhook URL
logging.info(f"钉钉机器人Webhook URL: {final_webhook_url}") logging.info(f"钉钉机器人Webhook URL: {final_webhook_url}")
# 调用测试结果获取函数
browser_init("标准版预定系统")
wd = GSTORE['wd']
print(latest_report)
test_result = get_test_result(latest_report, wd)
# 构建消息体 # 构建消息体
headers = {'Content-Type': 'application/json'} headers = {'Content-Type': 'application/json'}
message = { message = {
'msgtype': 'link', 'msgtype': 'link',
'link': { 'link': {
'title': title, 'title': title,
'messageUrl': test_report_url, 'messageUrl': latest_report,
'text': test_report_url 'text': f"通过:{test_result['pass_percent']}" + f"失败:{test_result['fail_percent']}" + f"异常:{test_result['exception_percent']}",
}, },
"at": { "at": {
"atMobiles": [mobile], "atMobiles": [mobile],
...@@ -683,7 +690,7 @@ def run_automation_test(report_title, report_url_prefix, test_case , ding_type): ...@@ -683,7 +690,7 @@ def run_automation_test(report_title, report_url_prefix, test_case , ding_type):
get_reportfile_send_dingding(f"{report_title}", report_url_prefix, ding_type) get_reportfile_send_dingding(f"{report_title}", report_url_prefix, ding_type)
def get_reportfile_send_dingding(report_title, report_url_prefix, ding_type): def get_reportfile_send_dingding(report_title, report_url_prefix, ding_type):
print(GSTORE['case_pass']) # print(GSTORE['case_pass'])
try: try:
# 获取报告文件所在的目录 # 获取报告文件所在的目录
report_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..','reports') report_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..','reports')
...@@ -1002,8 +1009,69 @@ def play_cloud_voice(app_id, app_secret, device_sn): ...@@ -1002,8 +1009,69 @@ def play_cloud_voice(app_id, app_secret, device_sn):
logging.error(f"发生未知异常: {e}") logging.error(f"发生未知异常: {e}")
# # 示例调用 # # 示例调用
if __name__ == "__main__": # if __name__ == "__main__":
app_id = os.getenv("APP_ID", "a98a124c6c3252f6612fc544a0d0fa79") # app_id = os.getenv("APP_ID", "a98a124c6c3252f6612fc544a0d0fa79")
app_secret = os.getenv("APP_SECRET", "88bc1ec4eba624f47b2200a4ce8c3852") # app_secret = os.getenv("APP_SECRET", "88bc1ec4eba624f47b2200a4ce8c3852")
device_sn = os.getenv("DEVICE_SN", "W703BB44444") # device_sn = os.getenv("DEVICE_SN", "W703BB44444")
play_cloud_voice(app_id, app_secret, device_sn) # play_cloud_voice(app_id, app_secret, device_sn)
\ No newline at end of file
def get_test_result(latest_report, wd):
"""
获取测试结果页面的通过率、失败率和异常率
:param latest_report: 测试结果页面的URL
:param wd: WebDriver实例,用于访问和操作网页
:return: 包含通过率、失败率和异常率的字典
"""
# 初始化测试结果字典
test_result = {
"pass_percent": "",
"fail_percent": "",
"exception_percent": ""
}
# 访问测试结果页面
wd.get(latest_report)
# 获取通过率
pass_percent = elment_get_text((By.CSS_SELECTOR, "div[class='result_barchart'] div:nth-child(1) span:nth-child(1)"),
wd)
logging.info(f"获取的通过率:{pass_percent}")
match = re.search(r'(\d+)%', pass_percent)
if match:
pass_percent = match.group(0)
else:
pass_percent = "0"
test_result["pass_percent"] = pass_percent
# 获取失败率
fail_percent = elment_get_text(
(By.CSS_SELECTOR, "body > div.main_section > div.result > div > div:nth-child(2) > span"), wd)
logging.info(f"获取的失败率:{fail_percent}")
match = re.search(r'(\d+)%', fail_percent)
if match:
fail_percent = match.group(0)
else:
fail_percent = "0"
test_result["fail_percent"] = fail_percent
# 获取异常率
exception_percent = elment_get_text(
(By.CSS_SELECTOR, "body > div.main_section > div.result > div > div:nth-child(3) > span"), wd)
logging.info(f"获取的异常率:{exception_percent}")
match = re.search(r'(\d+)%', exception_percent)
if match:
exception_percent = match.group(0)
else:
exception_percent = "0"
test_result["exception_percent"] = exception_percent
# 返回测试结果字典
return test_result
# if __name__ == '__main__':
# browser_init("标准版预定系统")
# wd = GSTORE['wd']
# data_result = get_test_result('http://nat.ubainsyun.com:31133/report_20250213_181722.html',wd)
# logging.info(data_result)
# print(data_result)
\ No newline at end of file
...@@ -206,4 +206,6 @@ ...@@ -206,4 +206,6 @@
52. 2025-02-12 52. 2025-02-12
- 排查展厅巡检中的语音转录与摄像头关闭操作失效问题,原因是缺少一个返回操作,并且麦克风和摄像头的元素定位发生变化导致操作失败,缩短等待时间。 - 排查展厅巡检中的语音转录与摄像头关闭操作失效问题,原因是缺少一个返回操作,并且麦克风和摄像头的元素定位发生变化导致操作失败,缩短等待时间。
- 历史会议模块与会议审批模块补充调用清除浏览器驱动函数。 - 历史会议模块与会议审批模块补充调用清除浏览器驱动函数。
- 补充审批会议模块的日志输出。调整审批会议创建的执行步骤。 - 补充审批会议模块的日志输出。调整审批会议创建的执行步骤。
\ No newline at end of file 53. 2025-02-13
- 增加get_test_result函数通过正则匹配获取通过率、失败率以及异常率,再调用钉钉消息通知输出通过率等值。
\ No newline at end of file
...@@ -69,10 +69,10 @@ def start_workers(num_workers): ...@@ -69,10 +69,10 @@ def start_workers(num_workers):
start_workers(3) start_workers(3)
# 定时执行预定系统测试任务1 # 定时执行预定系统测试任务1
# schedule.every().day.at("09:00").do(run_task, run_automation_test, report_title="预定系统测试报告", report_url_prefix="http://nat.ubainsyun.com:31134", test_case="预定系统功能", ding_type="标准版巡检") schedule.every().day.at("19:04").do(run_task, run_automation_test, report_title="预定系统测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="登录功能", ding_type="标准版巡检")
# 定时执行展厅巡检任务 # 定时执行展厅巡检任务
schedule.every().day.at("07:50").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检") schedule.every().day.at("07:45").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
try: try:
# 无限循环,持续检查并执行计划任务 # 无限循环,持续检查并执行计划任务
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论