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

调试测试用例JSON数据读取方式实现系统登录模块功能。

上级 d4ab0895
...@@ -463,8 +463,8 @@ def air_condition_control(app_drive,wd): ...@@ -463,8 +463,8 @@ def air_condition_control(app_drive,wd):
# 这是空调开启的状态显示 # 这是空调开启的状态显示
INFO("请检查空调开启的状态是否正常") INFO("请检查空调开启的状态是否正常")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_on") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_on")
app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\air_condition_on.png") # app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\air_condition_on.png")
# get_screenshot_with_retry(wd,app_drive, "Control_Manage", "air_condition_on") get_screenshot_with_retry(wd,app_drive, "Control_Manage", "air_condition_on")
sleep(2) sleep(2)
# 点击【关闭空调】按钮 # 点击【关闭空调】按钮
...@@ -476,8 +476,8 @@ def air_condition_control(app_drive,wd): ...@@ -476,8 +476,8 @@ def air_condition_control(app_drive,wd):
# 这是空调关闭的状态显示 # 这是空调关闭的状态显示
INFO("请检查空调关闭的状态是否正常") INFO("请检查空调关闭的状态是否正常")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_off") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "air_condition_off")
app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\air_condition_off.png") # app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\air_condition_off.png")
# get_screenshot_with_retry(wd,app_drive, "Control_Manage", "air_condition_off") get_screenshot_with_retry(wd,app_drive, "Control_Manage", "air_condition_off")
sleep(2) sleep(2)
def information_control(app_drive,wd): def information_control(app_drive,wd):
...@@ -558,8 +558,8 @@ def music_control(app_drive,wd): ...@@ -558,8 +558,8 @@ def music_control(app_drive,wd):
# 这是音乐开启播放后的界面显示 # 这是音乐开启播放后的界面显示
INFO("请检查中控屏软件打开音乐播放后的界面状态显示") INFO("请检查中控屏软件打开音乐播放后的界面状态显示")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_on") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_on")
app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\music_on.png") # app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\music_on.png")
# get_screenshot_with_retry(wd,app_drive, "Control_Manage", "music_on") get_screenshot_with_retry(wd,app_drive, "Control_Manage", "music_on")
# 点击【关闭播放音乐】 # 点击【关闭播放音乐】
logging.info("尝试定位【关闭播放音乐】按钮元素,并点击按钮") logging.info("尝试定位【关闭播放音乐】按钮元素,并点击按钮")
...@@ -570,8 +570,8 @@ def music_control(app_drive,wd): ...@@ -570,8 +570,8 @@ def music_control(app_drive,wd):
# 这是音乐关闭播放后的界面显示 # 这是音乐关闭播放后的界面显示
INFO("请检查中控屏软件关闭音乐播放后的界面状态显示") INFO("请检查中控屏软件关闭音乐播放后的界面状态显示")
SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_off") SELENIUM_LOG_SCREEN(wd, "50%", "Exhibit_Inspect", "Control_Manage", "music_off")
app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\music_off.png") # app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\music_off.png")
# get_screenshot_with_retry(wd,app_drive, "Control_Manage", "music_off") get_screenshot_with_retry(wd,app_drive, "Control_Manage", "music_off")
def command_centre_control(rtsp_url,app_drive,wd): def command_centre_control(rtsp_url,app_drive,wd):
open_center_button = app_drive.find_element(AppiumBy.XPATH, open_center_button = app_drive.find_element(AppiumBy.XPATH,
......
...@@ -451,32 +451,43 @@ def read_xlsx_data(xlsx_file_path): ...@@ -451,32 +451,43 @@ def read_xlsx_data(xlsx_file_path):
sheet = workbook.active sheet = workbook.active
# 读取表头,从第三行开始 # 读取表头,从第三行开始
headers = [cell.value for cell in sheet[2]] headers = [cell.value for cell in sheet[3]]
# 打印表头列名
# print(f"表头列名: {headers}")
# 找到表头中名为 'JSON' 的列索引 # 找到表头中名为 'JSON' 的列索引
try: try:
json_index = headers.index('JSON') json_index = headers.index('JSON')
except ValueError: except ValueError as e:
raise ValueError("表头中没有找到名为 'JSON' 的列") raise ValueError(f"表头中没有找到所需的列: {e}")
ddt_cases = [] ddt_cases = []
# 遍历XLSX文件中的每一行数据,从第四行开始 # 遍历XLSX文件中的每一行数据,从第四行开始
for row in sheet.iter_rows(min_row=3, values_only=True): for row in sheet.iter_rows(min_row=4, values_only=True):
# 获取 'JSON' 列的数据 # 获取 JSON 列的数据
json_data = row[json_index] json_data = row[json_index]
# 将每一行数据转换为字典,其中包含测试用例的名称和参数
case = { # 打印 JSON 数据以进行调试
'name': row[0], # print(f"JSON 数据: {json_data}")
'para': json_data
} # 解析 JSON 字符串
# 将转换后的测试用例数据添加到列表中 try:
ddt_cases.append(case) if json_data:
parsed_json = json.loads(json_data)
else:
raise ValueError("JSON 数据为空")
except json.JSONDecodeError:
raise ValueError(f"无法解析 JSON 数据: {json_data}")
# 将解析后的 JSON 数据添加到列表中
ddt_cases.append(parsed_json)
# 日志记录:XLSX文件已读取 # 日志记录:XLSX文件已读取
INFO("XLSX文件已读取") INFO("XLSX文件已读取")
# 返回包含所有测试用例数据的列表 # 返回包含所有测试用例数据的列表
return ddt_cases return ddt_cases
def get_cpu_usage(interval=1): def get_cpu_usage(interval=1):
""" """
获取当前进程的 CPU 占用率。 获取当前进程的 CPU 占用率。
...@@ -1286,67 +1297,32 @@ def read_xlsx_data(xlsx_file_path): ...@@ -1286,67 +1297,32 @@ def read_xlsx_data(xlsx_file_path):
# 打印表头列名 # 打印表头列名
# print(f"表头列名: {headers}") # print(f"表头列名: {headers}")
# 找到表头中名为 'function'、'Locator_JSON' 和 'Data_JSON' 的列索引 # 找到表头中名为 'JSON' 的列索引
try: try:
function_index = headers.index('function') json_index = headers.index('JSON')
locator_json_index = headers.index('Locator_JSON')
data_json_index = headers.index('Data_JSON')
except ValueError as e: except ValueError as e:
raise ValueError(f"表头中没有找到所需的列: {e}") raise ValueError(f"表头中没有找到所需的列: {e}")
ddt_cases = [] ddt_cases = []
# 遍历XLSX文件中的每一行数据,从第四行开始 # 遍历XLSX文件中的每一行数据,从第四行开始
for row in sheet.iter_rows(min_row=4, values_only=True): for row in sheet.iter_rows(min_row=4, values_only=True):
# 获取每一列的数据 # 获取 JSON 列的数据
function_name = row[function_index] json_data = row[json_index]
locator_json_data = row[locator_json_index]
data_json_data = row[data_json_index]
# 打印 Locator_JSON 和 Data_JSON 数据以进行调试 # 打印 JSON 数据以进行调试
# print(f"Locator_JSON 数据: {locator_json_data}") # print(f"JSON 数据: {json_data}")
# print(f"Data_JSON 数据: {data_json_data}")
# 解析 JSON 字符串 # 解析 JSON 字符串
try: try:
if locator_json_data: if json_data:
parsed_locator_json = json.loads(locator_json_data) parsed_json = json.loads(json_data)
else: else:
raise ValueError("Locator_JSON 数据为空") raise ValueError("JSON 数据为空")
except json.JSONDecodeError: except json.JSONDecodeError:
raise ValueError(f"无法解析 Locator_JSON 数据: {locator_json_data}") raise ValueError(f"无法解析 JSON 数据: {json_data}")
try: # 将解析后的 JSON 数据添加到列表中
if data_json_data: ddt_cases.append(parsed_json)
parsed_data_json = json.loads(data_json_data)
print(f"这是我想看的{parsed_data_json}")
else:
raise ValueError("Data_JSON 数据为空")
except json.JSONDecodeError:
raise ValueError(f"无法解析 Data_JSON 数据: {data_json_data}")
# 将每一行数据转换为字典,其中包含测试用例的名称、函数名和解析后的 JSON 数据
case = {
'name': row[0],
'function': function_name,
'locator_json': parsed_locator_json,
'data_json': parsed_data_json
}
# 将转换后的测试用例数据添加到列表中
ddt_cases.append(case)
# 打印解析后的数据
for case in ddt_cases:
# print(f"测试用例名称: {case['name']}")
# print(f"函数名: {case['function']}")
# print(f"Locator JSON: {case['locator_json']}")
# print(f"Data JSON: {case['data_json']}")
# 访问 Locator JSON 中的特定字段
locator_json = case['locator_json']
type_value = locator_json.get('PageData', {}).get('type')
username_locator_value = locator_json.get('PageData', {}).get('username_locator_value')
# print(f"Type: {type_value}")
# print(f"Username Locator Value: {username_locator_value}")
# 日志记录:XLSX文件已读取 # 日志记录:XLSX文件已读取
INFO("XLSX文件已读取") INFO("XLSX文件已读取")
......
...@@ -229,4 +229,6 @@ ...@@ -229,4 +229,6 @@
59. 2025-02-26 59. 2025-02-26
- 优化MQTT模块增加账号密码输入,输出通过读取测试用例的JSON数据格式进行自动化测试的demo程序。 - 优化MQTT模块增加账号密码输入,输出通过读取测试用例的JSON数据格式进行自动化测试的demo程序。
60. 2025-02-28 60. 2025-02-28
- 处理展厅中控屏图片过大问题,优化处理。初步调试测试用例JSON数据读取。 - 处理展厅中控屏图片过大问题,优化处理。初步调试测试用例JSON数据读取。
\ No newline at end of file 61. 2025-03-03
- 调试测试用例JSON数据读取方式实现系统登录模块功能。
\ No newline at end of file
...@@ -67,18 +67,6 @@ def read_xlsx_data(xlsx_file_path): ...@@ -67,18 +67,6 @@ def read_xlsx_data(xlsx_file_path):
# 将解析后的 JSON 数据添加到列表中 # 将解析后的 JSON 数据添加到列表中
ddt_cases.append(parsed_json) ddt_cases.append(parsed_json)
# 打印解析后的数据
for case in ddt_cases:
for step in case:
print(f"页面: {step['page']}")
print(f"按钮XPath: {step['btnXpath']}")
if 'input' in step:
print(f"输入值: {step['input']}")
if 'receive' in step:
print(f"预期接收: {step['receive']}")
if 'success' in step:
print(f"成功标志: {step['success']}")
# 日志记录:XLSX文件已读取 # 日志记录:XLSX文件已读取
INFO("XLSX文件已读取") INFO("XLSX文件已读取")
# 返回包含所有测试用例数据的列表 # 返回包含所有测试用例数据的列表
...@@ -87,7 +75,9 @@ def read_xlsx_data(xlsx_file_path): ...@@ -87,7 +75,9 @@ def read_xlsx_data(xlsx_file_path):
if __name__ == '__main__': if __name__ == '__main__':
ddt_cases = read_xlsx_data(csv_file_path) ddt_cases = read_xlsx_data(csv_file_path)
print(ddt_cases) # print(ddt_cases)
browser_init("标准版预定系统")
wd = GSTORE['wd']
# 遍历 ddt_cases 并获取每一个 JSON 对象 # 遍历 ddt_cases 并获取每一个 JSON 对象
for case in ddt_cases: for case in ddt_cases:
...@@ -95,14 +85,18 @@ if __name__ == '__main__': ...@@ -95,14 +85,18 @@ if __name__ == '__main__':
print(f"当前步骤: {step}") print(f"当前步骤: {step}")
# 你可以在这里对 step 进行进一步处理 # 你可以在这里对 step 进行进一步处理
# 例如:访问特定字段 # 例如:访问特定字段
page = step.get('page') # page = step.get('page')
btn_xpath = step.get('btnXpath') # 调用get_by_enum将定位类型转为枚举
input_value = step.get('input') locator_type = get_by_enum(step.get('locator_type'))
receive = step.get('receive') locator_value = step.get('locator_value')
success = step.get('success') element_type = step.get('element_type')
element_value = step.get('element_value')
print(f"页面: {page}") #
print(f"按钮XPath: {btn_xpath}") # print(f"页面: {page}")
print(f"输入值: {input_value}") # print(f"元素定位类型: {locator_type}")
print(f"预期接收: {receive}") # print(f"元素定位值: {locator_value}")
print(f"成功标志: {success}") # print(f"元素类型: {element_type}")
# print(f"输入值: {element_value}")
safe_send_keys((locator_type, locator_value), element_value, wd)
sleep(5)
\ No newline at end of file
...@@ -62,18 +62,18 @@ class Exhibition_hall_Control_000x: ...@@ -62,18 +62,18 @@ class Exhibition_hall_Control_000x:
# 这是全部灯光关闭后在软件界面上的状态显示 # 这是全部灯光关闭后在软件界面上的状态显示
INFO("请检查中控屏软件的灯光关闭状态显示是否正常") INFO("请检查中控屏软件的灯光关闭状态显示是否正常")
SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_off") SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_off")
app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\light_all_off.png") # app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\light_all_off.png")
# 截图获取当前软件的灯光控制界面 # 截图获取当前软件的灯光控制界面
# get_screenshot_with_retry(wd,app_drive,"Control_Manage", "light_all_off") get_screenshot_with_retry(wd,app_drive,"Control_Manage", "light_all_off")
# 调用灯光控制函数 # 调用灯光控制函数
light_control(app_drive) light_control(app_drive)
# 这是全部灯光开启后在软件界面上的状态显示 # 这是全部灯光开启后在软件界面上的状态显示
INFO("请检查中控屏软件的灯光开启状态显示是否正常") INFO("请检查中控屏软件的灯光开启状态显示是否正常")
SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_on") SELENIUM_LOG_SCREEN(wd, "75%", "Exhibit_Inspect", "Control_Manage", "light_all_on")
app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\light_all_on.png") # app_drive.get_screenshot_as_file(r"D:\GithubData\自动化\ubains-module-test\预定系统\reports\imgs\Exhibit_Inspect\Control_Manage\light_all_on.png")
# 截图获取当前软件的灯光控制界面 # 截图获取当前软件的灯光控制界面
# get_screenshot_with_retry(wd,app_drive,"Control_Manage", "light_all_on") get_screenshot_with_retry(wd,app_drive,"Control_Manage", "light_all_on")
# 这是灯光开启后的截图 # 这是灯光开启后的截图
INFO("请检查灯光开启后的监控视频状态是否正常") INFO("请检查灯光开启后的监控视频状态是否正常")
......
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__))
# 构建CSV文件的绝对路径
csv_file_path = os.path.join(current_dir, '../../测试数据/登录模块/会议预定测试用例.xlsx')
class Login_00x:
tags = ['新-登录测试']
"""
执行指令是:
1.cd 预定系统
2.hytest --report_title 账号密码登录测试报告 --report_url_prefix http://nat.ubainsyun.com:31133 --tag 新-登录测试
"""
def teststeps(self):
"""
执行测试步骤以验证登录功能。
本函数根据参数输入账号、密码和验证码,并检查登录后的提示信息是否与预期相符。
"""
wd = GSTORE['wd']
ddt_cases = read_xlsx_data(csv_file_path)
# 遍历 ddt_cases 并获取每一个 JSON 对象
for case in ddt_cases:
for step in case:
print(f"当前步骤: {step}")
# 你可以在这里对 step 进行进一步处理
# 例如:访问特定字段
# page = step.get('page')
# 调用get_by_enum将定位类型转为枚举
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 element_type == 'input':
INFO(f"输入值: {element_value}")
safe_send_keys((locator_type, locator_value), element_value, wd)
sleep(1)
elif element_type == 'click':
INFO("点击【登录】按钮")
safe_click((locator_type, locator_value), wd)
if "成功" in expented_result:
notify_text = elment_get_text((By.CSS_SELECTOR, "div[class='meeting_t'] span:nth-child(1)"), wd)
SELENIUM_LOG_SCREEN(wd, '50%', 'Login', 'Login_Pwd', "检查登录成功提示信息")
INFO(f"Alert text: {notify_text}")
CHECK_POINT('检查是否出现提示弹窗', "欢迎" in notify_text)
safe_click((By.XPATH, "//img[@title='退出登录']"), wd)
sleep(2)
elif "错误" in expented_result:
notify_text = get_notify_text(wd, (By.XPATH, "//p[@class='el-message__content']"), 'Login',
'Login_Pwd', "检查登录的提示信息")
INFO(f"获取到的结果:{notify_text}")
CHECK_POINT('检查是否出现提示弹窗', expented_result in notify_text)
sleep(2)
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论