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

封装获取当前会议时间转换格式函数,用于所有的会议预定功能测试使用。实现测试用例中会控-SMC的部分功能。

上级 c7001c0e
...@@ -493,7 +493,7 @@ def read_xlsx_data(xlsx_file_path, sheet_name=None): ...@@ -493,7 +493,7 @@ def read_xlsx_data(xlsx_file_path, sheet_name=None):
headers = [cell.value for cell in sheet[3]] headers = [cell.value for cell in sheet[3]]
# 打印表头列名 # 打印表头列名
INFO(f"表头列名: {headers}") # INFO(f"表头列名: {headers}")
# 找到表头中名为 'JSON' 的列索引 # 找到表头中名为 'JSON' 的列索引
try: try:
...@@ -508,11 +508,11 @@ def read_xlsx_data(xlsx_file_path, sheet_name=None): ...@@ -508,11 +508,11 @@ def read_xlsx_data(xlsx_file_path, sheet_name=None):
json_data = row[json_index] json_data = row[json_index]
# 打印 JSON 数据以进行调试 # 打印 JSON 数据以进行调试
INFO(f"行 {row_num} 的 JSON 数据: {json_data}") # INFO(f"行 {row_num} 的 JSON 数据: {json_data}")
# 检查 JSON 数据是否为空 # 检查 JSON 数据是否为空
if json_data is None or json_data.strip() == "": if json_data is None or json_data.strip() == "":
INFO(f"跳过行 {row_num},JSON 数据为空") # INFO(f"跳过行 {row_num},JSON 数据为空")
continue continue
# 解析 JSON 字符串 # 解析 JSON 字符串
...@@ -529,7 +529,6 @@ def read_xlsx_data(xlsx_file_path, sheet_name=None): ...@@ -529,7 +529,6 @@ def read_xlsx_data(xlsx_file_path, sheet_name=None):
# 返回包含所有测试用例数据的列表 # 返回包含所有测试用例数据的列表
return ddt_cases return ddt_cases
# 获取当前进程的 CPU 占用率函数 # 获取当前进程的 CPU 占用率函数
def get_cpu_usage(interval=1): def get_cpu_usage(interval=1):
""" """
...@@ -1399,3 +1398,68 @@ def get_by_enum(type_str): ...@@ -1399,3 +1398,68 @@ def get_by_enum(type_str):
else: else:
# 如果输入的定位器类型字符串不匹配任何已知的 By 枚举类型,抛出 ValueError 异常 # 如果输入的定位器类型字符串不匹配任何已知的 By 枚举类型,抛出 ValueError 异常
raise ValueError(f"未知的定位器类型: {type_str}") raise ValueError(f"未知的定位器类型: {type_str}")
# 获取当前时间并格式化为 'HH:MM' 格式的函数,用于会议预定使用
import datetime
def get_current_time_formatted():
"""
获取当前时间并格式化为 'HH:MM' 格式,并选择最近的未来时间点(如 00:00, 00:15, 00:30, 00:45 等)。
返回:
str: 最近的未来时间点字符串,例如 '17:00'。
"""
# 获取当前时间
current_time = datetime.datetime.now()
current_time_formatted = current_time.strftime("%H:%M")
# 定义时间点列表
time_points = [
"00:00", "00:15", "00:30", "00:45",
"01:00", "01:15", "01:30", "01:45",
"02:00", "02:15", "02:30", "02:45",
"03:00", "03:15", "03:30", "03:45",
"04:00", "04:15", "04:30", "04:45",
"05:00", "05:15", "05:30", "05:45",
"06:00", "06:15", "06:30", "06:45",
"07:00", "07:15", "07:30", "07:45",
"08:00", "08:15", "08:30", "08:45",
"09:00", "09:15", "09:30", "09:45",
"10:00", "10:15", "10:30", "10:45",
"11:00", "11:15", "11:30", "11:45",
"12:00", "12:15", "12:30", "12:45",
"13:00", "13:15", "13:30", "13:45",
"14:00", "14:15", "14:30", "14:45",
"15:00", "15:15", "15:30", "15:45",
"16:00", "16:15", "16:30", "16:45",
"17:00", "17:15", "17:30", "17:45",
"18:00", "18:15", "18:30", "18:45",
"19:00", "19:15", "19:30", "19:45",
"20:00", "20:15", "20:30", "20:45",
"21:00", "21:15", "21:30", "21:45",
"22:00", "22:15", "22:30", "22:45",
"23:00", "23:15", "23:30", "23:45"
]
# 将当前时间转换为 datetime 对象
current_time_dt = datetime.datetime.strptime(current_time_formatted, "%H:%M")
# 初始化最近时间点和最小时间差
closest_time_point = None
min_time_diff = float('inf')
# 遍历时间点列表,找到最近的未来时间点
for time_point in time_points:
time_point_dt = datetime.datetime.strptime(time_point, "%H:%M")
# 如果时间点在当前时间之后
if time_point_dt > current_time_dt:
time_diff = (time_point_dt - current_time_dt).total_seconds()
if time_diff < min_time_diff:
min_time_diff = time_diff
closest_time_point = time_point
# 如果没有找到未来的时间点(即当前时间已经是最后一个时间点),则选择下一个天的最早时间点
if closest_time_point is None:
closest_time_point = time_points[0]
return closest_time_point
...@@ -245,3 +245,4 @@ ...@@ -245,3 +245,4 @@
- 删除中控屏操作的多余截屏函数调用。处理get_screenshot_with_retry函数的目录构建传参问题。 - 删除中控屏操作的多余截屏函数调用。处理get_screenshot_with_retry函数的目录构建传参问题。
65. 2025-03-1- 65. 2025-03-1-
- 处理read_xlsx_data函数增加sheet传参,实现测试用例中会议室列表的部分功能。 - 处理read_xlsx_data函数增加sheet传参,实现测试用例中会议室列表的部分功能。
- 封装获取当前会议时间转换格式函数,用于所有的会议预定功能测试使用。实现测试用例中会控-SMC的部分功能。
\ No newline at end of file
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)
# 导入模块
from 预定系统.Base.base import *
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(current_dir, '..', '..', '测试数据', '会议预定测试用例.xlsx')
class Login_00x:
tags = ['新-会控SMC测试']
"""
执行指令是:
1.cd 预定系统
2.hytest --report_title 账号密码登录测试报告 --report_url_prefix http://nat.ubainsyun.com:31133 --tag 新-会控SMC测试
"""
def teststeps(self):
wd = GSTORE['wd']
ddt_cases = read_xlsx_data(xlsx_file_path, "会控-SMC")
# 遍历 ddt_cases 并获取每一个 JSON 对象
for case in ddt_cases:
for step in case:
print(f"当前步骤: {step}")
# 先赋值
locator_type = get_by_enum(step.get('locator_type'))
locator_value = step.get('locator_value')
element_type = step.get('element_type')
element_value = step.get('element_value')
expented_result = step.get('expented_result')
# 判断页面功能类型
if step.get("page") == "MeetingControl_SMC":
if element_type == "input":
# 查询会议
safe_send_keys((locator_type, locator_value), element_value, wd)
send_keyboard((locator_type, locator_value), wd)
sleep(2)
# 提前开始会议
safe_click((By.XPATH, "//span[contains(text(),'更多操作')]"), wd)
sleep(1)
safe_click((By.XPATH, "//li[contains(text(),'会议状态')]"), wd)
sleep(1)
safe_click((By.XPATH, "//div[@slot='footer']//span[contains(text(),'确定')]"), wd)
sleep(2)
elif element_type == "click":
safe_click((locator_type, locator_value), wd)
sleep(2)
# 切换到新窗口
wd.switch_to.window(wd.window_handles[1])
notify_text = elment_get_text((By.XPATH, "//div[@id='tab-smcList']"), wd)
INFO(f"当前页面标题为:{notify_text}")
CHECK_POINT(f"当前页面标题为:{notify_text}", expented_result in notify_text)
SELENIUM_LOG_SCREEN(wd, "SMC会控")
\ No newline at end of file
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)
# 导入模块
from 预定系统.Base.base import *
def suite_setup():
STEP(1, "初始化浏览器")
# 初始化浏览器与系统地址
browser_init("标准版预定系统")
admin_login("admin@Test", "Ubains@4321")
wd = GSTORE['wd']
sleep(2)
# 先创建SMC会议
STEP(1, "搜索会议室")
safe_click((By.XPATH, "//i[@class='el-collapse-item__arrow el-icon-arrow-right']"), wd)
sleep(1)
# 搜索SMC会议室
safe_send_keys((By.XPATH, "//input[@placeholder='请输入会议室名称']"), "SMC会议室", wd)
send_keyboard((By.XPATH, "//input[@placeholder='请输入会议室名称']"), wd)
sleep(2)
# 点击【查询】按钮
safe_click((By.XPATH, "//span[contains(text(),'查询')]"), wd)
# 点击【会议预定】按钮
safe_click((By.XPATH, "//span[@class='MeetingCityList_t_btn']"), wd)
sleep(2)
# 输入会议名称并勾选SMC会议类型
safe_send_keys((By.XPATH, "//input[@placeholder='请输入会议名称']"), "SMC会议", wd)
safe_click(
(By.XPATH, "//div[@class='reserve_input']//span[@class='el-checkbox__label'][normalize-space()='SMC3.0']"), wd)
sleep(1)
# 选择会议时间,点击【快速预定】按钮
current_time = get_current_time_formatted()
print(f"获取当前的时间{current_time}")
safe_click((By.XPATH, f"//div[normalize-space()='{current_time}']"), wd)
sleep(1)
safe_click((By.XPATH, "//div[@class='header_Quick']"), wd)
safe_click((By.XPATH, "//div[@class='header_Quick']"), wd)
sleep(2)
# 点击【确定】按钮
safe_click((By.XPATH, "//button[@type='button']//span[contains(text(),'预定')]"), wd)
sleep(2)
def suite_teardown():
wd = GSTORE['wd']
# 切换窗口
wd.switch_to.window(wd.window_handles[0])
wd.refresh()
safe_send_keys((By.XPATH, "//input[@placeholder='输入关键字搜索']"), "SMC会议", wd)
send_keyboard((By.XPATH, "//input[@placeholder='输入关键字搜索']"), wd)
sleep(2)
# 点击【更多操作】结束会议数据
# 提前开始会议
safe_click((By.XPATH, "//span[contains(text(),'更多操作')]"), wd)
sleep(1)
safe_click((By.XPATH, "//li[contains(text(),'会议状态')]"), wd)
sleep(1)
# 选择提前结束
safe_click((By.XPATH, "//span[contains(text(),'提前结束')]"), wd)
sleep(1)
safe_click((By.XPATH, "//div[@slot='footer']//span[contains(text(),'确定')]"), wd)
sleep(2)
safe_click((By.XPATH, "//button[@class='el-button el-button--default el-button--small el-button--primary ']//span[contains(text(),'确定')]"), wd)
sleep(1)
wd.quit()
\ No newline at end of file
...@@ -14,7 +14,8 @@ from 预定系统.Base.base import * ...@@ -14,7 +14,8 @@ from 预定系统.Base.base import *
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建XLSX文件的绝对路径 # 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(current_dir, '../../测试数据/会议室列表/会议预定测试用例.xlsx') xlsx_file_path = os.path.join(current_dir, '..', '..', '测试数据', '会议预定测试用例.xlsx')
class MeetingList_000x: class MeetingList_000x:
tags = ['新-会议室列表'] tags = ['新-会议室列表']
......
# import pandas as pd
# import json
# from time import sleep
# 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.base import *
# except ModuleNotFoundError as e:
# print(f"ModuleNotFoundError: {e}")
# print("尝试使用绝对路径导入")
# from 预定系统.Base.base import *
#
# def Get_JSON():
# DEFAULT_WAIT_TIME = 20
# # 默认等待时间(秒),用于元素加载或操作之间的等待
#
# # 获取当前脚本所在的目录
# current_dir = os.path.dirname(os.path.abspath(__file__))
#
# # 构建Excel文件的绝对路径
# xlsx_file_path = os.path.join(current_dir, '../../测试数据/登录模块/新账号密码登录.xlsx')
#
# # 读取Excel文件,从第四行开始(索引为3),并提取第11列(索引为10)的JSON数据,确保内容为字符串
# df = pd.read_excel(xlsx_file_path, sheet_name='Sheet1', skiprows=3, usecols=[10], dtype=str)
#
# # 打印 DataFrame 查看数据
# print("DataFrame:")
# print(df)
#
# # 将DataFrame转换为字典列表,并处理空值
# ddt_cases = []
# for index, row in df.iterrows():
# json_str = row.iloc[0]
# if pd.notna(json_str):
# # 清理 JSON 字符串,去除多余的换行符和空格
# cleaned_json_str = json_str.replace('\n', '').replace(' ', '')
# try:
# parsed_json = json.loads(cleaned_json_str)
# ddt_cases.append(parsed_json)
# except json.JSONDecodeError as e:
# print(f"Error parsing JSON at row {index}: {e}")
# ddt_cases.append({})
# else:
# ddt_cases.append({})
#
# # 打印解析后的 JSON 数据
# print("Parsed JSON Data:")
# print(ddt_cases)
#
# if __name__ == '__main__':
# Get_JSON()
...@@ -4,7 +4,7 @@ import os ...@@ -4,7 +4,7 @@ import os
# 获取当前脚本的绝对路径 # 获取当前脚本的绝对路径
current_dir = os.path.dirname(os.path.abspath(__file__)) 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) sys.path.append(预定系统_path)
# 导入模块 # 导入模块
...@@ -13,8 +13,8 @@ from 预定系统.Base.base import * ...@@ -13,8 +13,8 @@ from 预定系统.Base.base import *
# 获取当前脚本所在的目录 # 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建xlsx文件的绝对路径 # 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(current_dir, '../../测试数据/登录模块/会议预定测试用例.xlsx') xlsx_file_path = os.path.join(current_dir, '..', '..', '测试数据', '会议预定测试用例.xlsx')
class Login_00x: class Login_00x:
tags = ['新-登录测试'] tags = ['新-登录测试']
...@@ -30,7 +30,7 @@ class Login_00x: ...@@ -30,7 +30,7 @@ class Login_00x:
本函数根据参数输入账号、密码和验证码,并检查登录后的提示信息是否与预期相符。 本函数根据参数输入账号、密码和验证码,并检查登录后的提示信息是否与预期相符。
""" """
wd = GSTORE['wd'] wd = GSTORE['wd']
ddt_cases = read_xlsx_data(xlsx_file_path,"登录页面") ddt_cases = read_xlsx_data(xlsx_file_path, "登录页面")
# 遍历 ddt_cases 并获取每一个 JSON 对象 # 遍历 ddt_cases 并获取每一个 JSON 对象
for case in ddt_cases: for case in ddt_cases:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论