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

调整封装get_reportfile_send_dingding函数用来获取测试报告文件并拼接IP地址,并发送钉钉群消息。优化定时任务run_automat...

调整封装get_reportfile_send_dingding函数用来获取测试报告文件并拼接IP地址,并发送钉钉群消息。优化定时任务run_automation_test函数的调用处理,并增加对于的日志输出。补充定时任务执行的注解。调整元素定位的显示等待时间,避免因服务器的网络波动导致元素获取异常。
上级 88762ce2
此差异已折叠。
......@@ -72,3 +72,9 @@
- 调试定时任务的问题,还需再进一步调试。
- 补充运维集控的MQTT底层方法与消息体构建。
- 调试定时任务执行后钉钉消息没有发送的问题。将定时任务与测试报告文件获取封装成函数进行调用,方便后续维护管理。目前调试发现定时任务执行别的脚本时会出现异常问题,需要进一步排查。
21. 2024-11-27
- 调试定时任务执行完成后没有发送钉钉群消息的问题,并优化SSL处理方式。
22. 2024-11-28
- 封装get_reportfile_send_dingding函数用来获取测试报告文件并拼接IP地址,并发送钉钉群消息。优化定时任务run_automation_test函数的调用处理,并增加对于的日志输出。
- 补充定时任务执行的注解。
- 调整元素定位的显示等待时间,避免因服务器的网络波动导致元素获取异常。
\ No newline at end of file
......@@ -18,8 +18,8 @@ except ModuleNotFoundError as e:
def suite_setup():
STEP(1, "初始化浏览器")
browser_init()
STEP(2, "处理SSL认证")
handle_ssl_warning()
# STEP(2, "处理SSL认证")
# handle_ssl_warning()
def suite_teardown():
browser_quit()
\ No newline at end of file
from time import sleep
from hytest import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径
......@@ -8,25 +9,42 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(预定系统_path)
# 导入模块
from 预定系统.Base.base import *
account = 'admin@Test'
username = 'admin@Test'
password = 'Ubains@54321'
new_password = 'Ubains@4321'
phone = '17319004611'
email = '2919407801@qq.com'
class Main_User_Manage_0001:
tags = ['用户管理功能']
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户管理主流程.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Main_User_Manage_000x:
# tags = ['用户管理功能']
"""
执行指令:
1.cd 预定系统
2.hytest --report_title 用户主流程测试报告 --test Main_User_Manage_0001
2.hytest --report_title 用户主流程测试报告 --report_url_prefix http://192.168.1.166 --test 用户管理主流程_001
"""
def teststeps(self):
"""
执行测试步骤以用户管理的主流程功能。
本函数根据参数添加用户,并使用新增的用户进行登录的提示信息是否与预期相符。
"""
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串
notify_text = ""
# 从全局存储中获取webdriver实例
wd = GSTORE['wd']
# 从self.para中解构出用户名、密码、验证码和检查文本
name = self.name
account, username, password, new_password, phone, email = self.para
STEP(1, "点击【新增】按钮")
safe_click((By.XPATH, "//span[contains(text(),'添 加')]"), wd)
......@@ -105,12 +123,28 @@ class Main_User_Manage_0001:
safe_send_keys((By.XPATH, "//input[@placeholder='请输入账号或手机号或邮箱号']"),account,wd)
safe_send_keys((By.XPATH, "//input[@placeholder='请输入密码']"),new_password,wd)
safe_send_keys((By.XPATH, "//input[@placeholder='请输入图形验证码']"),'csba',wd)
INFO("点击登录按钮")
sleep(1)
safe_click((By.XPATH, "//input[@value='登 录']"),wd)
sleep(2)
INFO("获取登录信息")
notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'欢迎 自动化测试公司')]"),wd)
# 检查点:验证提示信息是否与预期相符
INFO(f"登录系统提示:{notify_text}")
CHECK_POINT('登录成功校验', notify_text == "欢迎 自动化测试公司")
SELENIUM_LOG_SCREEN(wd,"50%","User_Manage","User_Main","用户管理主流程-用户登录")
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
......@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入")
from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -20,6 +21,16 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户修改密码.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class User_Chanage_Pwd_000x:
tags = ['用户管理功能']
"""
......@@ -34,6 +45,7 @@ class User_Chanage_Pwd_000x:
执行测试步骤以用户新增功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。
"""
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串
notify_text = ""
# 从全局存储中获取webdriver实例
......@@ -73,7 +85,7 @@ class User_Chanage_Pwd_000x:
STEP(4, '点击确定按钮')
INFO('点击确定按钮')
safe_click((By.XPATH,
"//body/div[@class='el-dialog__wrapper']/div[@aria-label='修改密码']/div[@class='el-dialog__footer']/span[@class='dialog-footer']/button[@type='button']/span[1]"),
"//body/div[@class='el-dialog__wrapper']/div[@aria-label='修改密码']/div[@class='el-dialog__footer']/span[@class='dialog-footer']/button[1]"),
wd)
sleep(2)
STEP(5, '检查提示信息')
......@@ -102,3 +114,17 @@ class User_Chanage_Pwd_000x:
f'{name}检查提示信息')
INFO(f'校验修改密码提示信息:{notify_text}')
CHECK_POINT('校验修改密码提示信息', notify_text == check_text)
if name == '用户修改密码_022':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
......@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入")
from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户新增.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Add_User_000x:
tags = ['用户管理功能']
"""
......@@ -34,6 +44,7 @@ class Add_User_000x:
执行测试步骤以用户新增功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。
"""
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串
notify_text = ""
# 从全局存储中获取webdriver实例
......@@ -95,3 +106,17 @@ class Add_User_000x:
if check_text == '添加成功':
safe_click((By.XPATH, "//span[contains(text(),'添 加')]"), wd)
sleep(1)
if name == '用户新增_048':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
import csv
from time import sleep
from hytest import *
# 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径
......@@ -10,6 +9,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(预定系统_path)
# 导入模块
from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -17,6 +17,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户查询.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Query_User_000x:
tags = ['用户管理功能']
"""
......@@ -33,6 +42,7 @@ class Query_User_000x:
query_text:查询文本
query_type:查询类型
"""
login_url = 'https://192.168.5.218/#/login/logindf'
# 从全局存储中获取webdriver实例
wd = GSTORE['wd']
# 从self.para中解构出查询文本以及查询类型
......@@ -94,3 +104,17 @@ class Query_User_000x:
# 截屏显示
SELENIUM_LOG_SCREEN(wd, "50%", "User_Manage", "User_Query", f"{name}_检查搜索结果")
CHECK_POINT("检查搜索结果", query_text in check_text)
if name == '用户查询_044':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
......@@ -9,6 +9,7 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(预定系统_path)
# 导入模块
from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -16,6 +17,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户删除.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class Delete_User_000x:
tags = ['用户管理功能']
"""
......@@ -30,6 +40,7 @@ class Delete_User_000x:
执行测试步骤以用户删除功能。
本函数根据参数输入账号,并检查删除后的数据是否减少。
"""
login_url = 'https://192.168.5.218/#/login/logindf'
notify_text = ""
# 从全局存储中获取webdriver实例
wd = GSTORE['wd']
......@@ -79,3 +90,17 @@ class Delete_User_000x:
sleep(2)
#屏幕截图
SELENIUM_LOG_SCREEN(wd,"50%","User_Manage","User_Delete",f"{name}_查看删除结果")
if name == "用户删除_012":
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
......@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入")
from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户状态设置.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class User_Status_000x:
tags = ['用户管理功能']
"""
......@@ -31,9 +41,10 @@ class User_Status_000x:
def teststeps(self):
"""
执行测试步骤以用户新增功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。
执行测试步骤以用户状态设置功能。
本函数根据参数选择用户进行【启用】与【停用】操作,并检查停用、启用后登录系统的提示信息是否与预期相符。
"""
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串
notify_text = ""
# 从全局存储中获取webdriver实例
......@@ -114,7 +125,23 @@ class User_Status_000x:
safe_send_keys((By.XPATH, "//input[@placeholder='请输入密码']"), 'Ubains@4321', wd)
safe_send_keys((By.XPATH, "//input[@placeholder='请输入图形验证码']"), 'csba', wd)
safe_click((By.XPATH, "//input[@value='登 录']"), wd)
sleep(2)
notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'欢迎 自动化测试公司')]"), wd)
sleep(4)
notify_text = elment_get_text((By.XPATH, f"//span[normalize-space()='{username}']"), wd)
INFO(f'校验登录提示信息:{notify_text}')
CHECK_POINT('校验登录提示信息', notify_text == '欢迎 自动化测试公司')
\ No newline at end of file
CHECK_POINT('校验登录提示信息', username in notify_text)
sleep(2)
if name == '用户状态设置_004':
# 清除浏览器,再重新打开浏览器
wd.get(login_url)
# 最大化浏览器窗口
wd.maximize_window()
admin_login()
enter_the_backend()
wd.refresh()
INFO("打开账号管理下拉菜单")
safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
INFO("进入用户管理模块")
safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
......@@ -13,6 +13,7 @@ except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
print("尝试使用绝对路径导入")
from 预定系统.Base.base import *
from 预定系统.cases.账号管理.用户管理.__st__ import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
......@@ -20,6 +21,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../../测试数据/账号管理/用户管理模块/用户编辑.csv')
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
class User_Edit_000x:
tags = ['用户管理功能']
"""
......@@ -34,6 +44,7 @@ class User_Edit_000x:
执行测试步骤以用户新增功能。
本函数根据参数输入账号、用户名、密码、确认密码、部门、性别、手机号和邮箱,并检查新增后的提示信息是否与预期相符。
"""
login_url = 'https://192.168.5.218/#/login/logindf'
# 初始化通知文本为空字符串
notify_text = ""
# 从全局存储中获取webdriver实例
......@@ -55,7 +66,7 @@ class User_Edit_000x:
notify_text = elment_get_text((By.XPATH, "//span[contains(text(),'编辑用户')]"), wd)
INFO(f'校验编辑界面UI:{notify_text}')
CHECK_POINT('校验编辑界面', "编辑用户" in notify_text)
sleep(1)
sleep(2)
# 执行输入用户信息的步骤
STEP(2, f'输入用户名:{new_username}')
......@@ -64,11 +75,12 @@ class User_Edit_000x:
safe_send_keys((By.XPATH, "//input[@placeholder='用户名']"), new_username, wd)
# 清除下拉框数据
if name != '用户编辑_001':
# if name != '用户编辑_001':
safe_click((By.XPATH, "//i[@class='el-tag__close el-icon-close']"), wd)
sleep(2)
# 点击部门下拉框
safe_click((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请选择']"), wd)
sleep(2)
# 选择部门
safe_click((By.XPATH, "/html[1]/body[1]/div[4]/div[1]/div[1]/div[1]/ul[1]/li[1]/label[1]/span[1]/span[1]"), wd)
......@@ -86,7 +98,22 @@ class User_Edit_000x:
safe_click((By.XPATH, "//div[@aria-label='编辑用户']//span[contains(text(),'确定')]"), wd)
# 检查操作后的提示信息
sleep(2)
STEP(4, '检查提示信息')
notify_text = get_notify_text(wd, (By.XPATH,"//p[@class='el-message__content']"), 'User_Manage', 'User_Chanage_Pwd',
f'{name}检查提示信息')
CHECK_POINT('校验编辑用户提示信息', notify_text == check_text)
# if name == '用户编辑_018':
# # 清除浏览器,再重新打开浏览器
# wd.get(login_url)
# # 最大化浏览器窗口
# wd.maximize_window()
# admin_login()
# enter_the_backend()
#
# INFO("打开账号管理下拉菜单")
# safe_click((By.XPATH, "//span[@class='aside_menu menu_account']"), wd)
#
# INFO("进入用户管理模块")
# safe_click((By.XPATH, "//li[contains(text(),'用户管理')]"), wd)
\ No newline at end of file
此差异已折叠。
import schedule
from Base.base import *
# 配置日志记录器,仅输出到控制台
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
"""
执行指令:
打开终端1:
1.cd 预定系统
2.python ./定时执行功能测试.py
打开终端2:
1.python -m http.server 80 --directory reports (可以让同网段下的电脑通过使用测试主机的IP地址+测试报告文件进行访问查看)
"""
# 每天凌晨 0 点执行任务
schedule.every().day.at("21:18").do(run_automation_test, report_title="账号密码登录模块_测试报告", report_url_prefix="http://192.168.1.166", test_case="登录_0**")
# schedule.every().day.at("21:14").do(run_automation_test, report_title="用户管理模块_主流程_测试报告", report_url_prefix="http://192.168.1.166", test_case="Main_User_Manage_0001")
schedule.every().day.at("09:30").do(run_automation_test, report_title="用户管理模块_测试报告", report_url_prefix="http://192.168.1.166", test_case="用户管理功能")
try:
# 无限循环,持续检查并执行计划任务
while True:
schedule.run_pending()
time.sleep(5)
schedule.run_pending() # 检查并执行所有待处理的任务
time.sleep(1) # 每秒检查一次
except KeyboardInterrupt:
# 捕获用户中断信号 (Ctrl+C)
logging.info("Scheduler interrupted by user.")
except Exception as e:
# 捕获其他未预期的异常
logging.error(f"Unexpected error: {e}")
#
# if __name__ == "__main__":
# get_reportfile_send_dingding("用户管理模块_测试报告", "http://192.168.1.166")
\ No newline at end of file
......@@ -9,4 +9,5 @@ name,account,expected
用户删除_008,admin@37,删除成功
用户删除_009,admin@38,删除成功
用户删除_010,admin@44,删除成功
用户删除_011,admin@51,删除成功
\ No newline at end of file
用户删除_011,admin@48,删除成功
用户删除_012,admin@51,删除成功
\ No newline at end of file
name,account,username,password,new_password,phone,email
用户管理主流程_001,admin@Test,admin@Test,Ubains@54321,Ubains@4321,17319004611,2919407801@qq.com
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论