Close Shunxin tabs after each stage via shared _close_tab helper
- Add _close_tab(page, tab_name) for closing Ant Design Tabs by label - Close 运单列表 / 车辆点到 in the expected-arrival flow after export submission, and 数据导出 after download/merge - Close 卸车扫描记录 and 数据导出 likewise in the actual-arrival flow - Renumber step comments Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,29 @@ from datetime import datetime
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
|
def _close_tab(page, tab_name):
|
||||||
|
"""关闭指定名称的标签页(Ant Design Tabs)。
|
||||||
|
|
||||||
|
通过标签文字定位标签容器,点击其右侧的关闭(×)按钮。
|
||||||
|
- tab_name 采用包含匹配,对“ 运单列表”这类带空格的标签同样有效。
|
||||||
|
- 关闭失败不会影响主流程,仅打印提示信息。
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
tab = page.locator(".ant-tabs-tab").filter(
|
||||||
|
has=page.get_by_role("tab", name=tab_name)
|
||||||
|
)
|
||||||
|
if tab.count() == 0:
|
||||||
|
print(
|
||||||
|
f" ℹ️ 未找到标签页【{tab_name.strip()}】(可能尚未打开或已关闭),跳过。"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
tab.first.locator(".ant-tabs-tab-remove").click()
|
||||||
|
print(f" 🗙 已关闭标签页【{tab_name.strip()}】")
|
||||||
|
page.wait_for_timeout(300)
|
||||||
|
except Exception as e:
|
||||||
|
print(f" ⚠️ 关闭标签页【{tab_name.strip()}】时出错: {e}")
|
||||||
|
|
||||||
|
|
||||||
def shunxin_expected_download(page):
|
def shunxin_expected_download(page):
|
||||||
"""顺心:应到货物数据下载"""
|
"""顺心:应到货物数据下载"""
|
||||||
print("\n▶ 开始执行【顺心 - 应到货物数据下载】任务...")
|
print("\n▶ 开始执行【顺心 - 应到货物数据下载】任务...")
|
||||||
@@ -83,6 +106,11 @@ def shunxin_expected_download(page):
|
|||||||
else:
|
else:
|
||||||
print("⚠️ 未发现任何运单列表,直接跳转至下载环节。")
|
print("⚠️ 未发现任何运单列表,直接跳转至下载环节。")
|
||||||
|
|
||||||
|
# 5. 关闭【运单列表】与【车辆点到】标签页(这两个页面的工作均已完成)
|
||||||
|
# 运单列表为单一复用标签,所有班次导出完成后统一关闭即可。
|
||||||
|
_close_tab(page, "运单列表")
|
||||||
|
_close_tab(page, "车辆点到")
|
||||||
|
|
||||||
# 6. 前往数据导出页面去下载
|
# 6. 前往数据导出页面去下载
|
||||||
print(">> 正在前往【数据导出】界面...")
|
print(">> 正在前往【数据导出】界面...")
|
||||||
page.locator("a[href='/dataExport']").click()
|
page.locator("a[href='/dataExport']").click()
|
||||||
@@ -191,6 +219,10 @@ def shunxin_expected_download(page):
|
|||||||
for file_path in downloaded_files:
|
for file_path in downloaded_files:
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
print("✅ 临时数据清理完毕。")
|
print("✅ 临时数据清理完毕。")
|
||||||
|
|
||||||
|
# 10. 关闭【数据导出】标签页(该页面工作已完成)
|
||||||
|
_close_tab(page, "数据导出")
|
||||||
|
|
||||||
print("\n🎉 【顺心 - 应到货物数据下载】全流程测试完毕!")
|
print("\n🎉 【顺心 - 应到货物数据下载】全流程测试完毕!")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -245,7 +277,10 @@ def shunxin_actual_download(page):
|
|||||||
page.get_by_role("button", name="知道了").click()
|
page.get_by_role("button", name="知道了").click()
|
||||||
print("✅ 卸车扫描记录导出任务已成功提交!")
|
print("✅ 卸车扫描记录导出任务已成功提交!")
|
||||||
|
|
||||||
# 4. 前往数据导出页面去下载
|
# 4. 关闭【卸车扫描记录】标签页(该页面工作已完成)
|
||||||
|
_close_tab(page, "卸车扫描记录")
|
||||||
|
|
||||||
|
# 5. 前往数据导出页面去下载
|
||||||
print(">> 正在前往【数据导出】界面...")
|
print(">> 正在前往【数据导出】界面...")
|
||||||
page.locator("a[href='/dataExport']").click()
|
page.locator("a[href='/dataExport']").click()
|
||||||
|
|
||||||
@@ -255,7 +290,7 @@ def shunxin_actual_download(page):
|
|||||||
page.get_by_role("button", name="search 查询").click()
|
page.get_by_role("button", name="search 查询").click()
|
||||||
page.wait_for_timeout(2000)
|
page.wait_for_timeout(2000)
|
||||||
|
|
||||||
# 5. 轮询任务状态
|
# 6. 轮询任务状态
|
||||||
print(">> 列表中已渲染,开始匹配并检查后端处理状态...")
|
print(">> 列表中已渲染,开始匹配并检查后端处理状态...")
|
||||||
while True:
|
while True:
|
||||||
rows = page.locator(".ant-table-tbody > tr.ant-table-row")
|
rows = page.locator(".ant-table-tbody > tr.ant-table-row")
|
||||||
@@ -308,7 +343,7 @@ def shunxin_actual_download(page):
|
|||||||
print(">> ✅ 目标任务已就绪!开始下载...")
|
print(">> ✅ 目标任务已就绪!开始下载...")
|
||||||
break
|
break
|
||||||
|
|
||||||
# 6. 下载逻辑
|
# 7. 下载逻辑
|
||||||
downloaded_files = []
|
downloaded_files = []
|
||||||
for time_str in target_task_timestamps:
|
for time_str in target_task_timestamps:
|
||||||
try:
|
try:
|
||||||
@@ -330,7 +365,7 @@ def shunxin_actual_download(page):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
|
print(f" ❌ 下载任务 [{time_str}] 失败: {e}")
|
||||||
|
|
||||||
# 7. 合并数据 (修改了文件名前缀)
|
# 8. 合并数据 (修改了文件名前缀)
|
||||||
if downloaded_files:
|
if downloaded_files:
|
||||||
print("\n>> 🧪 正在开始执行数据归档整理...")
|
print("\n>> 🧪 正在开始执行数据归档整理...")
|
||||||
all_data_frames = []
|
all_data_frames = []
|
||||||
@@ -353,6 +388,10 @@ def shunxin_actual_download(page):
|
|||||||
for file_path in downloaded_files:
|
for file_path in downloaded_files:
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
print("✅ 临时数据清理完毕。")
|
print("✅ 临时数据清理完毕。")
|
||||||
|
|
||||||
|
# 9. 关闭【数据导出】标签页(该页面工作已完成)
|
||||||
|
_close_tab(page, "数据导出")
|
||||||
|
|
||||||
print("\n🎉 【顺心 - 实到货物数据下载】全流程测试完毕!")
|
print("\n🎉 【顺心 - 实到货物数据下载】全流程测试完毕!")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user