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

调整钉钉发送消息的密钥和接口获取方式,通过最外层传参来进行控制需要发送的钉钉群。优化appium相关代码的注释。

上级 89748c45
......@@ -501,7 +501,7 @@ def get_latest_report_file(report_dir, base_url):
# 返回完整的URL
return full_url
def dingding_send_message(test_report_url, title, text, mobile):
def dingding_send_message(test_report_url, title, mobile, ding_type):
"""
发送钉钉机器人消息
参考接口文档:https://open.dingtalk.com/document/orgapp/custom-robots-send-group-messages#title-7fs-kgs-36x
......@@ -517,10 +517,13 @@ def dingding_send_message(test_report_url, title, text, mobile):
# webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=b0eea0bbf097ce3badb4c832d2cd0267a50486f395ec8beca6e2042102bb295b'
# secret = 'SEC928b11659c5fd6476cfa2042edbf56da876abf759289f7e4d3c671fb9a81bf43'
# 钉钉机器人的 Webhook URL 和密钥(测试环境)
# webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=7fbf40798cad98b1b5db55ff844ba376b1816e80c5777e6f47ae1d9165dacbb4'
# secret = 'SEC610498ed6261ae2df1d071d0880aaa70abf5e67efe47f75a809c1f2314e0dbd6'
webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=061b6e9b1ae436f356cfda7fe19b6e58e46b62670046a78bd3a4d869118c612d'
secret = 'SEC93212bd880aad638cc0df2b28a72ef4fdf6651cacb8a6a4bc71dcf09705d458d'
if ding_type == '标准版巡检':
webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=7fbf40798cad98b1b5db55ff844ba376b1816e80c5777e6f47ae1d9165dacbb4'
secret = 'SEC610498ed6261ae2df1d071d0880aaa70abf5e67efe47f75a809c1f2314e0dbd6'
elif ding_type == '展厅巡检':
webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=061b6e9b1ae436f356cfda7fe19b6e58e46b62670046a78bd3a4d869118c612d'
secret = 'SEC93212bd880aad638cc0df2b28a72ef4fdf6651cacb8a6a4bc71dcf09705d458d'
# 生成时间戳
timestamp = str(round(time.time() * 1000))
......@@ -574,7 +577,7 @@ def dingding_send_message(test_report_url, title, text, mobile):
logging.error(f'请求异常: {e}')
def run_automation_test(report_title, report_url_prefix, test_case):
def run_automation_test(report_title, report_url_prefix, test_case , ding_type):
"""
运行自动化测试并生成报告。
......@@ -615,9 +618,9 @@ def run_automation_test(report_title, report_url_prefix, test_case):
logging.info("自动化测试完成。")
# 调用回调函数处理后续操作
get_reportfile_send_dingding(f"{report_title}", report_url_prefix)
get_reportfile_send_dingding(f"{report_title}", report_url_prefix, ding_type)
def get_reportfile_send_dingding(report_title, report_url_prefix):
def get_reportfile_send_dingding(report_title, report_url_prefix, ding_type):
try:
# 获取报告文件所在的目录
report_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..','reports')
......@@ -637,7 +640,7 @@ def get_reportfile_send_dingding(report_title, report_url_prefix):
logging.info("开始调用钉钉消息通知函数")
# 调用钉钉发送消息接口进行推送测试报告链接
dingding_send_message(latest_report, report_title, f"{report_title}_定时任务执行完成", "13724387318")
dingding_send_message(latest_report, report_title, f"{report_title}_定时任务执行完成", "13724387318", ding_type)
# 记录钉钉消息通知函数调用成功的日志
logging.info("钉钉消息通知函数调用成功")
......
......@@ -110,5 +110,10 @@
- 补充展厅预定巡检的截图信息,补充开发调试使用的毫米波雷达模拟.
- 修改主README文档,补充目录说明,执行指令,以及报告查看内容.
- 调整展厅巡检脚本的操作流程,增加会场静音等操作与截图。输出会议修改相关代码。
32. 2024-12-17
- 处理展厅无纸化1.0的巡检流程,保留原无纸化2.0的验证流程。增加相关的信息截图。
- 处理展厅巡检流程。
\ No newline at end of file
- 处理展厅巡检流程。
33. 2024-12-19
- 处理富创项目的mqtt消息体参数值。
- 调整钉钉发送消息的密钥和接口获取方式,通过最外层传参来进行控制需要发送的钉钉群。
- 优化appium相关代码的注释。
\ No newline at end of file
......@@ -41,16 +41,9 @@ class Exhibition_hall_inspection_000x:
message_name:会议名称
message_type:会议类型
book_type:预约类型
repetitive_cycle:重复周期
host_name:主持人名称
message_content:会议内容
book_start_time:会议开始时间
book_end_time:会议结束时间
inside_participant_name:内部参会人名称
outside_participant_name:外部参会人名称
outside_participant_phone:外部参会人手机号码
message_notification:消息提醒时间
notification_method:通知方式
check_text:检查提示文本
"""
# 初始化通知文本为空字符串
......
......@@ -10,14 +10,18 @@ class Exhibition_hall_Txinspection_000x:
"""
执行指令:
1.cd 预定系统
2.hytest --report_title 会议预约测试报告 --report_url_prefix http://192.168.1.225 --tag 展厅巡检_腾讯会议
2.hytest --report_title 会议预约测试报告 --report_url_prefix http://192.168.1.225 --tag 腾讯会议
"""
tags = ['展厅巡检','腾讯会议']
def teststeps(self):
"""
执行测试步骤以自动化测试腾讯会议应用的登录和会议加入流程。
该方法初始化应用驱动,等待应用加载,定位并点击会议按钮,加入会议,并截取会议画面。
"""
app_drive = None
try:
# 腾讯:"com.tencent.wemeet.app" ".StartupActivity"
# 初始化应用驱动,连接到指定的设备和应用
app_drive = app_setup_driver("Android", "7.1.2", "127.0.0.1:62001", "com.tencent.wemeet.app",
".StartupActivity", "127.0.0.1:62001")
app_drive.implicitly_wait(20) # 设置缺省等待时间
......@@ -27,9 +31,8 @@ class Exhibition_hall_Txinspection_000x:
# 定位第一场会议按钮元素,并点击按钮
logging.info("尝试定位【会议名称】按钮元素,并点击按钮")
# meeting_button = app_drive.find_element(AppiumBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/android.widget.LinearLayout[1]/android.view.ViewGroup/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[4]/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat[1]/android.view.ViewGroup/android.widget.TextView")
# meeting_button = app_drive.find_element(AppiumBy.ID,"com.tencent.wemeet.app:id/cb4")
meeting_button = app_drive.find_element(AppiumBy.XPATH,"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/android.widget.LinearLayout[1]/android.view.ViewGroup/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat/android.view.ViewGroup/android.widget.TextView")
meeting_button = app_drive.find_element(AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/android.widget.LinearLayout[1]/android.view.ViewGroup/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat/android.view.ViewGroup/android.widget.TextView")
logging.info("定位会议成功")
# 点击【加入会议】按钮
meeting_button.click()
......@@ -44,88 +47,25 @@ class Exhibition_hall_Txinspection_000x:
join_meeting_button.click()
logging.info("点击【加入会议】按钮成功")
sleep(8)
# 会议开始后,截取会议画面
app_drive.get_screenshot_as_file(
r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Tx_meeting\会场画面截屏.png")
sleep(8)
# 退出会议
app_drive.back()
sleep(3)
meeting_quit_button = app_drive.find_element(AppiumBy.XPATH,
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.TextView")
sleep(1)
meeting_quit_button.click()
sleep(4)
except Exception as e:
# 捕获并记录任何发生的错误
logging.error(f"发生错误: {e}", exc_info=True)
finally:
# 确保驱动程序在测试结束后正确关闭
if app_drive:
app_drive.quit()
logging.info("驱动程序已退出。")
# from appium.webdriver.common.appiumby import AppiumBy
# from 预定系统.Base.app_base import *
# import logging
# from time import sleep
# import unittest
# import os
# from HtmlTestRunner import HTMLTestRunner
#
# # 配置日志记录
# logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
#
# class TestAppTXCent(unittest.TestCase):
# def setUp(self):
# self.app_drive = None
# try:
# # 腾讯:"com.tencent.wemeet.app" ".StartupActivity"
# self.app_drive = app_setup_driver("Android", "7.1.2", "127.0.0.1:62001", "com.tencent.wemeet.app", ".StartupActivity")
# self.app_drive.implicitly_wait(20) # 设置缺省等待时间
# except Exception as e:
# logging.error(f"初始化驱动程序时发生错误: {e}", exc_info=True)
# self.fail(f"初始化驱动程序时发生错误: {e}")
#
# def tearDown(self):
# if self.app_drive:
# input('**** 按任意键退出..')
# self.app_drive.quit()
# logging.info("驱动程序已退出。")
#
# def test_app_txcent(self):
# try:
# # 使用显式等待来等待元素出现
# logging.info("等待登录页加载...")
#
# # 定位第一场会议按钮元素,并点击按钮
# logging.info("尝试定位【会议名称】按钮元素,并点击按钮")
# meeting_button = self.app_drive.find_element(AppiumBy.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/androidx.viewpager.widget.ViewPager/android.view.ViewGroup/android.widget.LinearLayout[1]/android.view.ViewGroup/android.widget.RelativeLayout/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[4]/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat[1]/android.view.ViewGroup/android.widget.TextView")
# logging.info("定位会议成功")
# # 点击【加入会议】按钮
# meeting_button.click()
# logging.info("点击【会议】按钮成功")
# sleep(2)
#
# # 点击【加入会议】按钮
# logging.info("尝试定位【加入会议】按钮元素,并点击按钮")
# join_meeting_button = self.app_drive.find_element(AppiumBy.XPATH, "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.appcompat.widget.LinearLayoutCompat/androidx.appcompat.widget.LinearLayoutCompat/android.widget.TextView")
# logging.info("定位【加入会议】按钮成功")
# join_meeting_button.click()
# logging.info("点击【加入会议】按钮成功")
# sleep(8)
#
# # 截图并保存
# screenshot_path = os.path.join(os.getcwd(), "reports", "imgs", "Exhibit_Inspect", "Tx_meeting", "会场控制截屏.png")
# os.makedirs(os.path.dirname(screenshot_path), exist_ok=True)
# self.app_drive.get_screenshot_as_file(screenshot_path)
# logging.info(f"截图已保存到: {screenshot_path}")
# except Exception as e:
# logging.error(f"发生错误: {e}", exc_info=True)
# self.fail(f"测试过程中发生错误: {e}")
#
# if __name__ == '__main__':
# # 创建测试套件
# suite = unittest.TestSuite()
# suite.addTest(TestAppTXCent('test_app_txcent'))
#
# # 定义报告文件路径
# report_path = os.path.join(os.getcwd(), "reports", "Exhibit_Inspect", "Tx_meeting", "test_report.html")
# os.makedirs(os.path.dirname(report_path), exist_ok=True)
#
# # 运行测试并生成报告
# with open(report_path, 'wb') as f:
# runner = HTMLTestRunner(stream=f, title='腾讯会议自动化测试报告', description='测试报告详情')
# runner.run(suite)
logging.info("驱动程序已退出。")
\ No newline at end of file
......@@ -25,10 +25,10 @@ if __name__ == "__main__":
# 读取配置文件
configs = Mqtt.read_config_from_csv(csv_file_path)
broker_address = "192.168.1.193"
port = 1883
num_repeats = 1000 # 重复执行的次数
interval_between_repeats = 0.2 # 每次重复之间的间隔时间(秒)
broker_address = "192.168.1.131"
port = 1881
num_repeats = 2000 # 重复执行的次数
interval_between_repeats = 1 # 每次重复之间的间隔时间(秒)
# 创建 MQTT 客户端实例-
mqtt_client = Mqtt(broker_address, port)
......
......@@ -68,9 +68,9 @@ start_workers(3)
# 定义每天定时执行的任务
# 每天早上07:50执行后台系统设置功能测试
schedule.every().saturday.at("12:00").do(run_task, run_automation_test, report_title="预定系统_后台管理功能_测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="后台管理功能")
schedule.every().saturday.at("12:00").do(run_task, run_automation_test, report_title="预定系统_后台管理功能_测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="后台管理功能", type="标准版巡检")
schedule.every().day.at("08:15").do(run_task, run_automation_test, report_title="展厅巡检_会议预约测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检")
schedule.every().day.at("08:15").do(run_task, run_automation_test, report_title="展厅巡检_会议预约测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", type="展厅巡检")
#
# schedule.every().day.at("08:25").do(run_task, run_automation_test, report_title="展厅巡检_腾讯终端入会测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检_腾讯会议")
#
......
name,conference_name,message_name,book_type,issue_name,book_start_time,book_end_time,message_notification,check_text
展厅巡检_001,展厅会议室,展厅巡检测试,普通会议,议题1,17:45,18:00,开会前一天提醒,预定成功
\ No newline at end of file
展厅巡检_001,展厅会议室,展厅巡检测试,普通会议,议题1,08:30,09:00,开会前一天提醒,预定成功
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论