Add cross-flow automation test and tone down log/comment wording
- main_router: add run_automation_test that runs each site's download flows in a cross sequence (expected/actual) plus a pass/fail report with timings; expose it as menu [8] - Site download functions now return False on their exception paths so the test harness can record failures (baishi also flags config-read failure) - Replace overblown log/comment phrasing across all modules with plain statements; trim docstrings Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -39,7 +39,7 @@ def shunxin_expected_download(page):
|
||||
download_dir = DOWNLOAD_DIR
|
||||
if not os.path.exists(download_dir):
|
||||
os.makedirs(download_dir)
|
||||
print(f">> 已创建专属下载文件夹: {download_dir}")
|
||||
print(f">> 已创建下载目录: {download_dir}")
|
||||
|
||||
export_times = []
|
||||
target_task_timestamps = []
|
||||
@@ -124,7 +124,7 @@ def shunxin_expected_download(page):
|
||||
page.wait_for_timeout(2000)
|
||||
|
||||
# 7. 轮询任务状态
|
||||
print(">> 列表中已渲染,开始匹配并检查后端处理状态...")
|
||||
print(">> 列表已加载,开始匹配并检查任务状态...")
|
||||
while True:
|
||||
rows = page.locator(".ant-table-tbody > tr.ant-table-row")
|
||||
row_count = rows.count()
|
||||
@@ -173,7 +173,7 @@ def shunxin_expected_download(page):
|
||||
else:
|
||||
target_task_timestamps = current_ready_timestamps
|
||||
if len(target_task_timestamps) > 0:
|
||||
print(">> ✅ 所有目标任务已就绪!开始并行下载...")
|
||||
print(">> 所有目标任务已就绪,开始下载...")
|
||||
break
|
||||
|
||||
# 8. 下载逻辑
|
||||
@@ -183,7 +183,7 @@ def shunxin_expected_download(page):
|
||||
target_row = page.locator(".ant-table-tbody > tr.ant-table-row").filter(
|
||||
has=page.locator(f"td:nth-child(3):has-text('{time_str}')")
|
||||
)
|
||||
print(f" 🎯 触发下载 -> 任务 [{time_str}] ...")
|
||||
print(f" 开始下载任务 [{time_str}] ...")
|
||||
|
||||
with page.expect_download() as download_info:
|
||||
target_row.locator("td").nth(8).locator(
|
||||
@@ -197,13 +197,13 @@ def shunxin_expected_download(page):
|
||||
save_path = os.path.join(download_dir, custom_filename)
|
||||
download.save_as(save_path)
|
||||
downloaded_files.append(save_path)
|
||||
print(f" ⬇️ 文件已落盘: downloads/{custom_filename}")
|
||||
print(f" 已下载: downloads/{custom_filename}")
|
||||
except Exception as e:
|
||||
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
|
||||
|
||||
# 9. 合并数据 (修改了文件名前缀)
|
||||
if downloaded_files:
|
||||
print("\n>> 🧪 正在开始执行扁平数据高能合并流程...")
|
||||
print("\n>> 正在合并下载的数据...")
|
||||
all_data_frames = []
|
||||
for file_path in downloaded_files:
|
||||
try:
|
||||
@@ -218,20 +218,21 @@ def shunxin_expected_download(page):
|
||||
final_output_path = os.path.join(download_dir, "顺心-应到货物数据.xlsx")
|
||||
combined_df.to_excel(final_output_path, index=False)
|
||||
print(f"====================================================")
|
||||
print(f" 🎉 恭喜!合并成功!最终输出路径: {final_output_path}")
|
||||
print(f" 合并完成,输出文件: {final_output_path}")
|
||||
print(f"====================================================")
|
||||
|
||||
for file_path in downloaded_files:
|
||||
os.remove(file_path)
|
||||
print("✅ 临时数据清理完毕。")
|
||||
print("✅ 临时文件已清理。")
|
||||
|
||||
# 10. 关闭【数据导出】标签页(该页面工作已完成)
|
||||
_close_tab(page, "数据导出")
|
||||
|
||||
print("\n🎉 【顺心 - 应到货物数据下载】全流程测试完毕!")
|
||||
print("\n【顺心 - 应到货物数据下载】流程结束。")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ 任务执行过程中发生异常: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def shunxin_actual_download(page):
|
||||
@@ -296,7 +297,7 @@ def shunxin_actual_download(page):
|
||||
page.wait_for_timeout(2000)
|
||||
|
||||
# 6. 轮询任务状态
|
||||
print(">> 列表中已渲染,开始匹配并检查后端处理状态...")
|
||||
print(">> 列表已加载,开始匹配并检查任务状态...")
|
||||
while True:
|
||||
rows = page.locator(".ant-table-tbody > tr.ant-table-row")
|
||||
row_count = rows.count()
|
||||
@@ -345,7 +346,7 @@ def shunxin_actual_download(page):
|
||||
else:
|
||||
target_task_timestamps = current_ready_timestamps
|
||||
if len(target_task_timestamps) > 0:
|
||||
print(">> ✅ 目标任务已就绪!开始下载...")
|
||||
print(">> 目标任务已就绪,开始下载...")
|
||||
break
|
||||
|
||||
# 7. 下载逻辑
|
||||
@@ -355,7 +356,7 @@ def shunxin_actual_download(page):
|
||||
target_row = page.locator(".ant-table-tbody > tr.ant-table-row").filter(
|
||||
has=page.locator(f"td:nth-child(3):has-text('{time_str}')")
|
||||
)
|
||||
print(f" 🎯 触发下载 -> 任务 [{time_str}] ...")
|
||||
print(f" 开始下载任务 [{time_str}] ...")
|
||||
|
||||
with page.expect_download() as download_info:
|
||||
target_row.locator("td").nth(8).locator(
|
||||
@@ -369,13 +370,13 @@ def shunxin_actual_download(page):
|
||||
save_path = os.path.join(download_dir, custom_filename)
|
||||
download.save_as(save_path)
|
||||
downloaded_files.append(save_path)
|
||||
print(f" ⬇️ 文件已落盘: downloads/{custom_filename}")
|
||||
print(f" 已下载: downloads/{custom_filename}")
|
||||
except Exception as e:
|
||||
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
|
||||
|
||||
# 8. 合并数据 (修改了文件名前缀)
|
||||
if downloaded_files:
|
||||
print("\n>> 🧪 正在开始执行数据归档整理...")
|
||||
print("\n>> 正在合并下载的数据...")
|
||||
all_data_frames = []
|
||||
for file_path in downloaded_files:
|
||||
try:
|
||||
@@ -390,17 +391,18 @@ def shunxin_actual_download(page):
|
||||
final_output_path = os.path.join(download_dir, "顺心-实到货物数据.xlsx")
|
||||
combined_df.to_excel(final_output_path, index=False)
|
||||
print(f"====================================================")
|
||||
print(f" 🎉 恭喜!处理成功!最终输出路径: {final_output_path}")
|
||||
print(f" 合并完成,输出文件: {final_output_path}")
|
||||
print(f"====================================================")
|
||||
|
||||
for file_path in downloaded_files:
|
||||
os.remove(file_path)
|
||||
print("✅ 临时数据清理完毕。")
|
||||
print("✅ 临时文件已清理。")
|
||||
|
||||
# 9. 关闭【数据导出】标签页(该页面工作已完成)
|
||||
_close_tab(page, "数据导出")
|
||||
|
||||
print("\n🎉 【顺心 - 实到货物数据下载】全流程测试完毕!")
|
||||
print("\n【顺心 - 实到货物数据下载】流程结束。")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ 任务执行过程中发生异常: {e}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user