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

base增加read_xlsx_data_auto函数,支持sheet_name为None时,默认遍历整个测试用例所有模块从第一个sheet到最后的shee...

base增加read_xlsx_data_auto函数,支持sheet_name为None时,默认遍历整个测试用例所有模块从第一个sheet到最后的sheet执行,若sheet_name传参时,则为单独执行某个模块测试。
上级 5f8924b2
......@@ -573,6 +573,60 @@ def read_xlsx_data(xlsx_file_path, sheet_name=None, case_type=None):
# ddt_cases = read_xlsx_data(xlsx_file_path, sheet_name="AI创会", case_type="标准版")
# print(ddt_cases)
def read_xlsx_data_auto(xlsx_file_path, sheet_name=None, case_type=None):
try:
INFO(f"尝试打开文件路径: {xlsx_file_path}")
if not os.path.exists(xlsx_file_path):
raise FileNotFoundError(f"文件未找到: {xlsx_file_path}")
workbook = openpyxl.load_workbook(xlsx_file_path, read_only=True)
INFO("XLSX文件成功打开")
# === 修改后的工作表选择逻辑 ===
if sheet_name:
sheets_to_process = [workbook[sheet_name]] # 处理指定工作表
else:
sheets_to_process = workbook.worksheets # 处理所有工作表
# ==========================
ddt_cases = []
for sheet in sheets_to_process:
INFO(f"正在处理工作表: {sheet.title}")
headers = [cell.value for cell in sheet[3]]
INFO(f"表头列名: {headers}")
try:
json_index = headers.index('JSON')
category_index = headers.index('功能类别')
except ValueError as e:
INFO(f"工作表 {sheet.title} 缺少必要列,跳过: {e}")
continue # 跳过不符合格式的工作表
for row_num, row in enumerate(sheet.iter_rows(min_row=4, values_only=True), start=4):
json_data = row[json_index]
if not json_data or not json_data.strip():
continue
try:
parsed_json = json.loads(json_data)
category = row[category_index]
if case_type and category != case_type:
continue
ddt_cases.append(parsed_json)
except json.JSONDecodeError:
INFO(f"行 {row_num} 的 JSON 数据解析失败")
INFO("XLSX文件处理完成")
return ddt_cases
except Exception as e:
raise Exception(f"处理文件时出错: {e}")
import openpyxl
def clear_columns_in_xlsx(xlsx_file_path, sheet_name=None, columns_to_clear=None):
"""
......
......@@ -322,4 +322,6 @@
94. 2025-06-13:
- 兰州中石化项目模块增加tag标签。
95. 2025-06-16:
- 标准版注释clear_columns_in_xlsx和write_xlsx_data方法调用。定时任务补充兰州。
\ No newline at end of file
- 标准版注释clear_columns_in_xlsx和write_xlsx_data方法调用。定时任务补充兰州。
96. 2025-06-18:
- base增加read_xlsx_data_auto函数,支持sheet_name为None时,默认遍历整个测试用例所有模块从第一个sheet到最后的sheet执行,若sheet_name传参时,则为单独执行某个模块测试。
\ 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("兰州中石化项目测试环境")
user_login("admin", "Ubains@4321")
sleep(2)
wd = GSTORE['wd']
sleep(1)
def suite_teardown():
wd = GSTORE['wd']
wd.quit()
\ 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("兰州中石化项目测试环境")
user_login("admin", "Ubains@4321")
sleep(2)
wd = GSTORE['wd']
sleep(1)
# 点击【议题申报】按钮进入模块
INFO("点击【会议信息】按钮")
safe_click((By.XPATH, "//div[@id='MeetingInfo']"), wd)
sleep(1)
def suite_teardown():
wd = GSTORE['wd']
wd.quit()
\ 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 *
# 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(预定系统_path, '测试数据', '兰州中石化项目测试用例.xlsx')
class TopicInformation:
tags = ['兰州中石化项目会议信息','兰州中石化项目']
"""
执行指令是:
1.cd 预定系统
2.hytest --report_title 兰州中石化项目会议信息测试报告 --report_url_prefix http://nat.ubainsyun.com:31135 --tag 兰州中石化项目会议信息
"""
ddt_cases = read_xlsx_data(xlsx_file_path, sheet_name='会议信息',case_type="兰州中石化项目25-05-24")
# 测试开始前调用clear_columns_in_xlsx函数,将测试用例中的测试结果和日志截图置空
# clear_columns_in_xlsx(xlsx_file_path, sheet_name='会议创建', columns_to_clear=['测试结果', '测试频次', '日志截图'])
def teststeps(self):
"""
执行测试步骤函数,主要用于执行读取的测试用例并进行信息统计模块功能测试操作
"""
# 从全局存储中获取webdriver对象
wd = GSTORE['wd']
name = self.name
# 刷新页面
wd.refresh()
wd.refresh()
for step in self.para:
# 赋值页面类型page
page_type = step.get('page')
# 赋值元素定位类型,并将字符串转为Enum类型
locator_type = get_by_enum(step.get('locator_type'))
# 赋值元素值
locator_value = step.get('locator_value')
# 赋值元素类型,例如:click点击、input输入框等
element_type = step.get('element_type')
# 赋值元素值,例如输入框的输入值
element_value = step.get('element_value')
# 赋值预期结果
expented_result = step.get('expented_result')
# 赋值等待时间
# sleep_time = step.get('sleep_time')
INFO(f"页面: {page_type}、元素定位类型: {locator_type}、元素定位值: {locator_value}、元素类型: {element_type}、元素值: {element_value}、预期结果: {expented_result}")
if element_type == "click":
safe_click((locator_type, locator_value), wd)
sleep(2)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "input":
safe_send_keys((locator_type, locator_value), element_value, wd)
sleep(2)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "login":
safe_click((By.XPATH, "//div[contains(@class,'quit')]"), wd)
sleep(2)
user_login(element_value[0],element_value[1])
sleep(2)
elif element_type == "getTips":
notify_text = get_notify_text(wd, (locator_type, locator_value))
INFO(f"获取到的提示信息为:{notify_text}")
sleep(2)
CHECK_POINT(f"获取到的提示信息为:{notify_text}", expented_result in notify_text)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "getText":
text = elment_get_text((locator_type, locator_value), wd)
INFO(f"获取到的文本信息为:{text}")
CHECK_POINT(f"获取到的文本信息为:{text}", expented_result in text)
SELENIUM_LOG_SCREEN(wd, "75")
\ 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 *
# 构建XLSX文件的绝对路径 (修正路径)
xlsx_file_path = os.path.join(预定系统_path, '测试数据', '兰州中石化项目测试用例全局测试.xlsx')
class LanzhouSinopecProject:
tags = ['合并测试']
"""
执行指令是:
1.cd 预定系统
2.hytest --report_title 兰州中石化项目测试报告 --report_url_prefix http://nat.ubainsyun.com:31135 --tag 合并测试
"""
ddt_cases = read_xlsx_data_auto(xlsx_file_path, case_type="兰州中石化项目25-05-24")
# 测试开始前调用clear_columns_in_xlsx函数,将测试用例中的测试结果和日志截图置空
# clear_columns_in_xlsx(xlsx_file_path, sheet_name='会议创建', columns_to_clear=['测试结果', '测试频次', '日志截图'])
def teststeps(self):
"""
执行测试步骤函数,主要用于执行读取的测试用例并进行信息统计模块功能测试操作
"""
# 从全局存储中获取webdriver对象
wd = GSTORE['wd']
name = self.name
# 刷新页面
wd.refresh()
wd.refresh()
for step in self.para:
# 赋值页面类型page
page_type = step.get('page')
# 赋值元素定位类型,并将字符串转为Enum类型
locator_type = get_by_enum(step.get('locator_type'))
# 赋值元素值
locator_value = step.get('locator_value')
# 赋值元素类型,例如:click点击、input输入框等
element_type = step.get('element_type')
# 赋值元素值,例如输入框的输入值
element_value = step.get('element_value')
# 赋值预期结果
expented_result = step.get('expented_result')
# 赋值等待时间
# sleep_time = step.get('sleep_time')
INFO(f"页面: {page_type}、元素定位类型: {locator_type}、元素定位值: {locator_value}、元素类型: {element_type}、元素值: {element_value}、预期结果: {expented_result}")
if element_type == "click":
safe_click((locator_type, locator_value), wd)
sleep(2)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "input":
safe_send_keys((locator_type, locator_value), element_value, wd)
sleep(2)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "login":
safe_click((By.XPATH, "//div[contains(@class,'quit')]"), wd)
sleep(2)
user_login(element_value[0],element_value[1])
sleep(2)
elif element_type == "getTips":
notify_text = get_notify_text(wd, (locator_type, locator_value))
INFO(f"获取到的提示信息为:{notify_text}")
sleep(2)
CHECK_POINT(f"获取到的提示信息为:{notify_text}", expented_result in notify_text)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "getText":
text = elment_get_text((locator_type, locator_value), wd)
INFO(f"获取到的文本信息为:{text}")
CHECK_POINT(f"获取到的文本信息为:{text}", expented_result in text)
SELENIUM_LOG_SCREEN(wd, "75")
\ 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("兰州中石化项目测试环境")
user_login("admin", "Ubains@4321")
sleep(2)
wd = GSTORE['wd']
sleep(1)
# 点击【议题申报】按钮进入模块
INFO("点击【议题信息】按钮")
safe_click((By.XPATH, "/div[@id='TopicList']"), wd)
sleep(1)
def suite_teardown():
wd = GSTORE['wd']
wd.quit()
\ 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 *
# 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(预定系统_path, '测试数据', '兰州中石化项目测试用例.xlsx')
class TopicInformation:
tags = ['兰州中石化项目议题信息','兰州中石化项目']
"""
执行指令是:
1.cd 预定系统
2.hytest --report_title 兰州中石化项目议题信息测试报告 --report_url_prefix http://nat.ubainsyun.com:31135 --tag 兰州中石化项目议题信息
"""
ddt_cases = read_xlsx_data(xlsx_file_path, sheet_name='议题信息',case_type="兰州中石化项目25-05-24")
# 测试开始前调用clear_columns_in_xlsx函数,将测试用例中的测试结果和日志截图置空
# clear_columns_in_xlsx(xlsx_file_path, sheet_name='会议创建', columns_to_clear=['测试结果', '测试频次', '日志截图'])
def teststeps(self):
"""
执行测试步骤函数,主要用于执行读取的测试用例并进行信息统计模块功能测试操作
"""
# 从全局存储中获取webdriver对象
wd = GSTORE['wd']
name = self.name
# 刷新页面
wd.refresh()
wd.refresh()
for step in self.para:
# 赋值页面类型page
page_type = step.get('page')
# 赋值元素定位类型,并将字符串转为Enum类型
locator_type = get_by_enum(step.get('locator_type'))
# 赋值元素值
locator_value = step.get('locator_value')
# 赋值元素类型,例如:click点击、input输入框等
element_type = step.get('element_type')
# 赋值元素值,例如输入框的输入值
element_value = step.get('element_value')
# 赋值预期结果
expented_result = step.get('expented_result')
# 赋值等待时间
# sleep_time = step.get('sleep_time')
INFO(f"页面: {page_type}、元素定位类型: {locator_type}、元素定位值: {locator_value}、元素类型: {element_type}、元素值: {element_value}、预期结果: {expented_result}")
if element_type == "click":
safe_click((locator_type, locator_value), wd)
sleep(2)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "input":
safe_send_keys((locator_type, locator_value), element_value, wd)
sleep(2)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "login":
safe_click((By.XPATH, "//div[contains(@class,'quit')]"), wd)
sleep(2)
user_login(element_value[0],element_value[1])
sleep(2)
elif element_type == "getTips":
notify_text = get_notify_text(wd, (locator_type, locator_value))
INFO(f"获取到的提示信息为:{notify_text}")
sleep(2)
CHECK_POINT(f"获取到的提示信息为:{notify_text}", expented_result in notify_text)
SELENIUM_LOG_SCREEN(wd, "75")
elif element_type == "getText":
text = elment_get_text((locator_type, locator_value), wd)
INFO(f"获取到的文本信息为:{text}")
CHECK_POINT(f"获取到的文本信息为:{text}", expented_result in text)
SELENIUM_LOG_SCREEN(wd, "75")
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -75,11 +75,11 @@ schedule.every().day.at("10:00").do(run_task, run_automation_test, report_title=
# 定时执行展厅巡检任务
# schedule.every().day.at("07:45").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().monday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().thursday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().wednesday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().tuesday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().friday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().monday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().thursday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().wednesday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().tuesday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
schedule.every().friday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31133", test_case="展厅巡检", ding_type="展厅巡检")
# schedule.every().saturday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
# schedule.every().sunday.at("07:42").do(run_task, run_automation_test, report_title="展厅巡检测试报告", report_url_prefix="http://nat.ubainsyun.com:31136", test_case="展厅巡检", ding_type="展厅巡检")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论