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

MQTT相关模块目前调整了Mqtt_Send.py文件中封装的方法优化,增加异常处理。处理了登录成功断言失败的问题。

上级 77ec55c5
......@@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.10 (ubains-module-test)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (ubains-module-test)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
......@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (ubains-module-test)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
......
此差异已折叠。
......@@ -21,4 +21,4 @@
- 优化了Mqtt_Send中封装的函数,补充异常处理以及日志优化。
6. 2024-11-02
- 将原有pytest框架代码改为hytest框架使用,优化了脚本执行效率,并对应增加异常处理。
- MQTT相关模块还未调整完。
\ No newline at end of file
- MQTT相关模块目前调整了Mqtt_Send.py文件中封装的方法优化,增加异常处理。处理了登录成功断言失败的问题。
\ No newline at end of file
......@@ -35,7 +35,7 @@ XPATH_WELCOME_TEXT = '//*[@id="app"]/div/div[1]/div/span[1]'
CLASS_MESSAGE_CONTENT = 'el-message__content'
# 消息内容的 CSS 类名
DEFAULT_WAIT_TIME = 10
DEFAULT_WAIT_TIME = 20
# 默认等待时间(秒),用于元素加载或操作之间的等待
......@@ -64,7 +64,7 @@ def clear_and_send_keys(wd, locator, value):
element.send_keys(value)
class UI_000x:
class Login_000x:
ddt_cases = [
{
......@@ -145,7 +145,7 @@ class UI_000x:
# 等待1秒以允许页面响应
sleep(2)
# 根据预期的检查文本类型,获取并记录提示信息
if check_text == "欢迎":
if check_text == "欢迎 预定标准版测试":
notify_text = WebDriverWait(wd, DEFAULT_WAIT_TIME).until(
EC.presence_of_element_located((By.XPATH, XPATH_WELCOME_TEXT))
).text
......
# from datetime import datetime
# import time
# from hytest import *
# import sys
# import os
# # 获取当前脚本的绝对路径
# current_dir = os.path.dirname(os.path.abspath(__file__))
# # 构建预定系统的绝对路径
# 预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..','..'))
# # 添加路径
# sys.path.append(预定系统_path)
# # 导入模块
# try:
# from 预定系统.Base.Mqtt_Send import *
# except ModuleNotFoundError as e:
# print(f"ModuleNotFoundError: {e}")
# print("尝试使用绝对路径导入")
# from 预定系统.Base.Mqtt_Send import *
#
# if __name__ == "__main__":
# # 读取配置文件
# configs = Mqtt.read_config_from_csv('../测试数据/MQTT安卓上报数据.csv')
#
# broker_address = "192.168.5.218"
# port = 1883
# # topic = "rebootResponseTopic"
# num_repeats = 100 # 重复执行的次数
# interval_between_repeats = 0.2 # 每次重复之间的间隔时间(秒)
#
# # 创建 MQTT 客户端实例
# mqtt_client = Mqtt(broker_address, port)
#
# try:
# # 连接到 MQTT 服务器
# mqtt_client.connect()
#
# for repeat in range(num_repeats):
# logging.info(f"开始第 {repeat + 1} 次上报")
#
# # 遍历配置文件中的每一行数据
# for config in configs:
# # 构建消息内容-
# # 构建消息内容
# topic = config["topic"]
import time
import sys
import os
from datetime import datetime
from hytest import *
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径
预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..','..'))
# 添加路径
sys.path.append(预定系统_path)
# 导入模块
try:
from 预定系统.Base.Mqtt_Send import *
except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入")
from 预定系统.Base.Mqtt_Send import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../测试数据/MQTT安卓上报数据.csv')
if __name__ == "__main__":
# 读取配置文件
configs = Mqtt.read_config_from_csv(csv_file_path)
broker_address = "192.168.5.218"
port = 1883
# topic = "rebootResponseTopic"
num_repeats = 100 # 重复执行的次数
interval_between_repeats = 0.2 # 每次重复之间的间隔时间(秒)
# 创建 MQTT 客户端实例
mqtt_client = Mqtt(broker_address, port)
try:
# 连接到 MQTT 服务器
mqtt_client.connect()
print('连接成功')
for repeat in range(num_repeats):
logging.info(f"开始第 {repeat + 1} 次上报")
# 遍历配置文件中的每一行数据
for config in configs:
# 构建消息内容-
# 构建消息内容
topic = config["topic"]
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(config)
message = Mqtt.build_message(config, current_time, topic)
# 发送消息
mqtt_client.publish(topic, message)
# 每次发送之间可以设置一个间隔时间
time.sleep(interval_between_repeats)
# 每次重复之间设置一个间隔时间
time.sleep(interval_between_repeats)
except Exception as e:
logging.error(f"发送消息时发生错误: {e}")
finally:
# 断开与 MQTT 服务器的连接
mqtt_client.disconnect()
# class Android_000x:
# with open(csv_file_path, mode='r', encoding='utf-8') as file:
# reader = csv.DictReader(file)
# ddt_cases = []
# for i, row in enumerate(reader):
# # 将CSV行转换为ddt_cases的格式
# case = {
# 'name': row['name'],
# 'para': [
# row['topic'], row['clientId'], row['appToken'], row['companyNumber'],
# row['cnum'], row['conferenceId'], row['macAddress'], row['authCode']
# ]
# }
# ddt_cases.append(case)
#
# # 打印结果
# # print(f"Total cases: {len(ddt_cases)}")
# # print(ddt_cases)
#
# def teststeps(self):
#
# broker_address = "nat.ubainsyun.com"
# port = 1883
# # topic = "rebootResponseTopic"
# num_repeats = 100 # 重复执行的次数
# interval_between_repeats = 0.2 # 每次重复之间的间隔时间(秒)
# topic, clientId, appToken, companyNumber, cnum, conferenceId, macAddress, authCode = self.para
#
# # 创建 MQTT 客户端实例
# mqtt_client = Mqtt(broker_address, port)
#
# try:
# STEP(1,"连接MQTT")
# # 连接到 MQTT 服务器
# mqtt_client.connect()
# STEP(2,"MQTT发送消息")
# for repeat in range(num_repeats):
# logging.info(f"开始第 {repeat + 1} 次上报")
# current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# message = Mqtt.build_message(config, current_time, topic)
# message = Mqtt.build_message(topic, clientId, appToken, companyNumber, cnum, conferenceId, macAddress, authCode, current_time, "deviceId")
#
# print(message)
#
# # 发送消息
# #发送消息
# mqtt_client.publish(topic, message)
#
# # 每次发送之间可以设置一个间隔时间
# time.sleep(interval_between_repeats)
#
# # 每次重复之间设置一个间隔时间
# time.sleep(interval_between_repeats)
#
# except Exception as e:
# logging.error(f"发送消息时发生错误: {e}")
# except Exception as e:
# logging.error(f"发送消息时发生错误: {e}")
#
# finally:
# # 断开与 MQTT 服务器的连接
# mqtt_client.disconnect()
# finally:
# # 断开与 MQTT 服务器的连接
# mqtt_client.disconnect()
# from datetime import datetime
# import logging
# import time
# import sys
# import os
# # 获取当前脚本的绝对路径
# current_dir = os.path.dirname(os.path.abspath(__file__))
# # 构建预定系统的绝对路径
# 预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..','..'))
# # 添加路径
# sys.path.append(预定系统_path)
# # 导入模块
# try:
# from 预定系统.Base.Mqtt_Send import *
# except ModuleNotFoundError as e:
# print(f"ModuleNotFoundError: {e}")
# print("尝试使用绝对路径导入")
# from 预定系统.Base.Mqtt_Send import *
#
# if __name__ == "__main__":
# # 读取配置文件
# configs = Mqtt.read_config_from_csv('../测试数据/MQTT毫米波上报数据.csv')
#
# broker_address = "192.168.5.218"
# port = 1883
# num_repeats = 100 # 重复执行的次数
# interval_between_repeats = 0.2 # 每次重复之间的间隔时间(秒)
#
# # 创建 MQTT 客户端实例-
# mqtt_client = Mqtt(broker_address, port)
#
# try:
# # 连接到 MQTT 服务器
# mqtt_client.connect()
#
# for repeat in range(num_repeats):
# logging.info(f"开始第 {repeat + 1} 次上报")
#
# # 遍历配置文件中的每一行数据
# for config in configs:
# # 构建消息内容
# topic = config["topic"]
# current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# message = Mqtt.build_message(config, current_time, topic)
#
# # 发送消息
# mqtt_client.publish(topic, message)
#
# # 每次发送之间可以设置一个间隔时间
# time.sleep(interval_between_repeats)
#
# # 每次重复之间设置一个间隔时间
# time.sleep(interval_between_repeats)
#
# except Exception as e:
# logging.error(f"发送消息时发生错误: {e}")
#
# finally:
# # 断开与 MQTT 服务器的连接
# mqtt_client.disconnect()
from datetime import datetime
import logging
import time
import sys
import os
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径
预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..','..'))
# 添加路径
sys.path.append(预定系统_path)
# 导入模块
try:
from 预定系统.Base.Mqtt_Send import *
except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入")
from 预定系统.Base.Mqtt_Send import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../测试数据/MQTT毫米波上报数据.csv')
if __name__ == "__main__":
# 读取配置文件
configs = Mqtt.read_config_from_csv(csv_file_path)
broker_address = "192.168.5.218"
port = 1883
num_repeats = 100 # 重复执行的次数
interval_between_repeats = 0.2 # 每次重复之间的间隔时间(秒)
# 创建 MQTT 客户端实例-
mqtt_client = Mqtt(broker_address, port)
try:
# 连接到 MQTT 服务器
mqtt_client.connect()
for repeat in range(num_repeats):
logging.info(f"开始第 {repeat + 1} 次上报")
# 遍历配置文件中的每一行数据
for config in configs:
# 构建消息内容
topic = config["topic"]
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
message = Mqtt.build_message(config, current_time, topic)
# 发送消息
mqtt_client.publish(topic, message)
# 每次发送之间可以设置一个间隔时间
time.sleep(interval_between_repeats)
# 每次重复之间设置一个间隔时间
time.sleep(interval_between_repeats)
except Exception as e:
logging.error(f"发送消息时发生错误: {e}")
finally:
# 断开与 MQTT 服务器的连接
mqtt_client.disconnect()
......@@ -4,7 +4,7 @@ import os
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径
预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..','..'))
预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..'))
# 添加路径
sys.path.append(预定系统_path)
# 导入模块
......@@ -14,5 +14,6 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入")
from 预定系统.Base.base import *
def suite_setup():
admin_login()
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -6,33 +6,83 @@
== cases\__st__.py
== cases\__init__.py
== cases\登录模块\账号密码登录测试.py
** no cases in this file, skip it.
** no cases in this file , skip it.
== cases\设备管理\安卓信息上报.py
== cases\会议室管理\__init__.py
== cases\设备管理\毫米波雷达上报.py
** no cases in this file, skip it.
== cases\授权码管理\__init__.py
== cases\账号管理\__st__.py
== cases\账号管理\用户管理.py
** no cases in this file, skip it.
== cases\登录模块\__init__.py
=== [ 执行测试用例 ] ===
** no cases in this file, skip it.
预备执行用例数量 : 1
== cases\登录模块\账号密码登录测试.py
== cases\设备管理\__init__.py
========= 测试开始 : 20241102_162659 =========
** no cases in this file, skip it.
== cases\设备管理\安卓信息上报.py
>>> cases\
[ suite setup ] cases\
'----------' 正在初始化浏览器 '----------'
'----------' 正在处理SSL证书警告 '----------'
'----------' SSL证书警告处理完成 '----------'
>>> cases\设备管理\安卓信息上报.py
* 设备上报_0001 - 2024-11-02 16:27:04
[ case execution steps ]
-- 第 1 步 -- 连接MQTT
-- 第 2 步 -- MQTT发送消息
PASS
[ suite teardown ] cases\
清除浏览器
========= 测试结束 : 20241102_162728 =========
耗时 : 28.932 秒
预备执行用例数量 : 1
实际执行用例数量 : 1
通过 : 1
失败 : 0
异常 : 0
套件初始化失败 : 0
套件清除 失败 : 0
用例初始化失败 : 0
用例清除 失败 : 0
此差异已折叠。
topic,clientId,appToken,companyNumber,cnum,conferenceId,macAddress,authCode
rebootResponseTopic,48134e6047a19a01,AND-2CT-0101,CN-2CT-UBAINS,4b521415d42650a0da515114aa36ab88,220,20:59:20:00:28:01,AND-2CT-0101
rebootResponseTopic,48134e6047a19a02,AND-2CT-0102,CN-2CT-UBAINS,6828f107eddcd6c80537e554f1ba6393,221,20:59:20:00:28:02,AND-2CT-0102
rebootResponseTopic,48134e6047a19a03,AND-2CT-0103,CN-2CT-UBAINS,694eba1b6f1995d4f7c085c77788ca68,222,20:59:20:00:28:03,AND-2CT-0103
rebootResponseTopic,48134e6047a19a04,AND-2CT-0104,CN-2CT-UBAINS,acab665450c5bb91e11881e749934b63,223,20:59:20:00:28:04,AND-2CT-0104
rebootResponseTopic,48134e6047a19a05,AND-2CT-0105,CN-2CT-UBAINS,842380cf2573785aa3e74f61c3921e1b,224,20:59:20:00:28:05,AND-2CT-0105
rebootResponseTopic,48134e6047a19a06,AND-2CT-0106,CN-2CT-UBAINS,4c02ca0fc3f0947ab2658b6d6b98bbfc,225,20:59:20:00:28:06,AND-2CT-0106
rebootResponseTopic,48134e6047a19a07,AND-2CT-0107,CN-2CT-UBAINS,24d712de79b9907304874c1ab158cbab,226,20:59:20:00:28:07,AND-2CT-0107
rebootResponseTopic,48134e6047a19a08,AND-2CT-0108,CN-2CT-UBAINS,ef89042cce57dab36475a32f86d515b1,227,20:59:20:00:28:08,AND-2CT-0108
\ No newline at end of file
此差异已折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论