refactor(tests): restructure into layered POM architecture with Allure reporting
- Split framework into core/ (config, logger, db, driver factories, screenshot, allure integration) and pages/ (PO layer: base/admin/driver); flatten test files per platform (web/admin, app/driver_android, cross_end) - Slim root conftest.py 656 -> ~100 lines: drop inline CN HTML report, add Allure severity mapping (p0/p1/p2 -> blocker/normal/minor) and environment.properties; support both tests.*-prefixed and bare imports - Preserve TC-D2S-001/002 cross-end E2E cases with business logic unchanged, add allure epic/feature/story/step annotations - Deduplicate: single makereport hook, shared failure-screenshot helpers, single SCREENSHOTS_DIR constant; deterministic auth-state role loading - Move DB credentials from db_helper.py into test_config.yaml (database section) - Move pytest.ini to repo root; switch reporting to allure-pytest (drop pytest-html/junitxml); update requirements.txt accordingly - Delete deprecated scaffolding: test_freight_full_flow + 6 stale page objects, iOS/shipper empty shells, dead utils - Fix flaky vxe-table action-row wait: wait for a visible td instead of hidden placeholder rows (fixed shipper-payment timeouts) - Verified end-to-end against live env: both E2E cases pass (2 passed 3m12s); run artifacts (logs/screenshots/allure) included per repo convention
This commit is contained in:
@@ -0,0 +1,355 @@
|
||||
"""管理端 Page Object — 运费核算 + 运单审核 + 垫资打款 完整流程。
|
||||
|
||||
基于 resources/selectors/正常流程-web端.md 中的元素定位。
|
||||
使用直接 hash URL 导航(比菜单点击更可靠),按钮选择器带 fallback 兜底。
|
||||
|
||||
URL 路由:
|
||||
运费核算: #/tms/Carrier/freight
|
||||
运单审核: #/tms/Carrier/OrderDetailAudit
|
||||
垫资-财务打款: #/tms/Carrier/dzFinancialapproval
|
||||
垫资-货主打款: #/tms/Carrier/dzApplicationForPayment
|
||||
"""
|
||||
|
||||
from playwright.sync_api import Page
|
||||
|
||||
from tests.pages.base.web_base_page import BasePage
|
||||
|
||||
|
||||
class FreightAccountingPage(BasePage):
|
||||
"""管理端 - 运费核算 / 运单审核 / 垫资打款。"""
|
||||
|
||||
def __init__(self, page: Page, admin_base_url: str = ""):
|
||||
super().__init__(page)
|
||||
self.admin_base_url = admin_base_url
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# URL 导航
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
def _go(self, hash_route: str):
|
||||
"""直接 hash URL 跳转,比菜单点击稳定。"""
|
||||
url = f"{self.admin_base_url}/#/{hash_route.lstrip('#').lstrip('/')}"
|
||||
self.page.goto(url, wait_until="domcontentloaded")
|
||||
self.page.wait_for_timeout(2000)
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 通用操作
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
def _fill_order_no(self, order_no: str):
|
||||
"""搜索栏输入运输单号(多个同名 input 时取第一个)。"""
|
||||
input_el = self.page.locator('input[placeholder="请输入运输单号"]').first
|
||||
self.wait_visible(input_el)
|
||||
input_el.clear()
|
||||
input_el.fill(order_no)
|
||||
|
||||
def _click_search(self):
|
||||
"""点击查询按钮。"""
|
||||
btn = self.page.locator("button:has-text('查询')").first
|
||||
self.wait_visible(btn)
|
||||
btn.click()
|
||||
self.page.wait_for_timeout(1000)
|
||||
|
||||
def _table_has_data(self) -> bool:
|
||||
"""检查查询结果是否有数据。"""
|
||||
try:
|
||||
self.page.wait_for_selector("table tbody tr", timeout=3_000)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _click_table_action(self, button_index: int):
|
||||
"""点击表格固定列操作按钮(纯图标 <i> 按钮,selector 文档路径 + fallback)。
|
||||
|
||||
vxe-table 操作列按钮结构: td > div > button:nth-child(N) > span > i
|
||||
"""
|
||||
# 精确路径(selector 文档原始定位)
|
||||
sel = (
|
||||
".vxe-table--fixed-right-wrapper.scrolling--middle "
|
||||
".vxe-table--body-wrapper.fixed-right--wrapper "
|
||||
"table > tbody > tr:nth-child(1) > td > div "
|
||||
f"> button:nth-child({button_index}) > span > i"
|
||||
)
|
||||
# 宽松路径(当 DOM 结构略有变化时兜底)
|
||||
sel_fallback = (
|
||||
".vxe-table--fixed-right-wrapper "
|
||||
"table > tbody > tr:nth-child(1) "
|
||||
f"> td:last-child > div > button:nth-child({button_index})"
|
||||
)
|
||||
|
||||
for attempt in range(3):
|
||||
try:
|
||||
# 等待可见的数据单元格出现。vxe-table 固定列会渲染多个隐藏的重复
|
||||
# 单元格 (class="...fixed--hidden"),必须用 :visible 钉住真正可见的
|
||||
# 数据行,否则 wait_for_selector 会卡在第一个隐藏单元格上超时。
|
||||
self.page.wait_for_selector("table tbody tr td:visible", timeout=8_000)
|
||||
self.page.wait_for_timeout(300)
|
||||
btn = self.page.locator(sel).first
|
||||
if btn.count() == 0:
|
||||
btn = self.page.locator(sel_fallback).first
|
||||
self.wait_visible(btn, timeout_ms=5_000)
|
||||
btn.click()
|
||||
self.page.wait_for_timeout(800)
|
||||
return
|
||||
except Exception:
|
||||
if attempt == 2:
|
||||
raise
|
||||
self.page.wait_for_timeout(1_000)
|
||||
|
||||
def _modal(self):
|
||||
"""返回当前可见弹窗内容容器(.first 避免 strict mode)。"""
|
||||
return self.page.locator(
|
||||
".vxe-modal--wrapper.is--visible .vxe-modal--body .vxe-modal--content"
|
||||
).first
|
||||
|
||||
def _scroll_modal(self):
|
||||
"""滚动弹窗到底部。"""
|
||||
modal = self._modal()
|
||||
self.wait_visible(modal)
|
||||
modal.evaluate("el => el.scrollTop = el.scrollHeight")
|
||||
self.page.wait_for_timeout(500)
|
||||
|
||||
def _retry_click_modal_btn(self, locator, timeout_ms: int = 5_000,
|
||||
retries: int = 3, wait_after: int = 1500):
|
||||
"""弹窗内按钮带重试点击(每次重试重新获取元素,防 DOM 置换)。"""
|
||||
for attempt in range(retries):
|
||||
el = locator() if callable(locator) else locator
|
||||
try:
|
||||
self.wait_visible(el, timeout_ms=timeout_ms)
|
||||
el.click()
|
||||
self.page.wait_for_timeout(wait_after)
|
||||
return
|
||||
except Exception:
|
||||
if attempt == retries - 1:
|
||||
raise
|
||||
self.page.wait_for_timeout(1_000)
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 运费核算
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
def do_freight_accounting(self, order_no: str, retry_sql=None, team_leader_payment: bool = False):
|
||||
"""运费核算:导航→搜索→(无数据时 SQL 重试)→编辑→[可选:选择车队长+收款模式]→核算。
|
||||
|
||||
Args:
|
||||
order_no: 运输单号
|
||||
retry_sql: 可调用对象,首次查询无数据时调用
|
||||
team_leader_payment: True=车队长全额收款模式(核算前额外选择车队长和收款模式)
|
||||
"""
|
||||
self._go("tms/Carrier/freight")
|
||||
self._fill_order_no(order_no)
|
||||
self._click_search()
|
||||
|
||||
# 无数据 → 执行 SQL 重试
|
||||
if not self._table_has_data():
|
||||
if retry_sql:
|
||||
try:
|
||||
retry_sql()
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"运费核算 SQL 重试失败!单号: {order_no}, 错误: {e}")
|
||||
self._fill_order_no(order_no)
|
||||
self._click_search()
|
||||
|
||||
if not self._table_has_data():
|
||||
raise RuntimeError(f"运费核算查询无数据!单号: {order_no}")
|
||||
|
||||
# 点击编辑 (button_index=4, 来自 selector 文档 Step 3)
|
||||
self._click_table_action(button_index=4)
|
||||
|
||||
# ── 车队长全额收款模式:核算前选择车队长 + 收款模式 ──
|
||||
if team_leader_payment:
|
||||
self._select_team_leader_payment()
|
||||
|
||||
# 核算按钮 (selector 文档 Step 4)
|
||||
btn = self._modal().locator(
|
||||
"form > div:nth-child(4) button:nth-child(4) span"
|
||||
).first
|
||||
self._retry_click_modal_btn(btn, wait_after=1500)
|
||||
self.screenshot("freight_accounting_done")
|
||||
|
||||
def _select_team_leader_payment(self):
|
||||
"""在核算编辑弹窗中选择"车队长"+车队长"全额收款"模式。
|
||||
|
||||
前置条件:已经在运费核算编辑弹窗中(点击了编辑按钮之后)。
|
||||
步骤:
|
||||
1. 点击选择车队长下拉框,选中车队长
|
||||
2. 点击选择收款模式下拉框,选择车队长全额收款
|
||||
|
||||
注意: Element UI 的 el-select-dropdown popper 在 DOM 中可能有多个残留
|
||||
(旧的 hidden),需要用 nth(-1) 取最晚渲染的那个。
|
||||
"""
|
||||
# Step 1: 点击选择车队长下拉框
|
||||
selector_input = self.page.locator(
|
||||
"#app > div > div.main-container.hasTagsView > section > div > div > div "
|
||||
"> div.vxe-modal--wrapper.type--modal.is--animat.lock--view.is--mask.is--visible.is--active "
|
||||
"> div > div.vxe-modal--body > div.vxe-modal--content > div > form "
|
||||
"> div:nth-child(2) > div:nth-child(4) > div > div > div > div > input"
|
||||
).first
|
||||
self.wait_visible(selector_input, timeout_ms=5_000)
|
||||
selector_input.click()
|
||||
self.page.wait_for_timeout(800)
|
||||
|
||||
# Step 2: 在下拉列表中点击车队长选项(取最后一个下拉弹窗,它是最新渲染的)
|
||||
team_leader_option = self.page.locator(
|
||||
"body > div.el-select-dropdown.el-popper "
|
||||
"> div.el-scrollbar > div.el-select-dropdown__wrap.el-scrollbar__wrap "
|
||||
"> ul > li"
|
||||
).nth(-1)
|
||||
self.wait_visible(team_leader_option, timeout_ms=5_000)
|
||||
team_leader_option.click()
|
||||
# 等待车队长选择完成后,收款模式下拉框解除 disabled
|
||||
self.page.wait_for_timeout(1200)
|
||||
|
||||
# Step 3: 等待收款模式 el-select 解除 disabled 后再点击
|
||||
# Element UI 的 disabled 加在 el-select 外层的 div 上,不是 input 本身
|
||||
# 所以需要等包含 is-disabled class 的上层 div 消失
|
||||
payment_select_wrapper = self.page.locator(
|
||||
".vxe-modal--wrapper.is--visible "
|
||||
"form > div:nth-child(2) > div:nth-child(5) > div > div > div"
|
||||
).first
|
||||
payment_input = self.page.locator(
|
||||
".vxe-modal--wrapper.is--visible "
|
||||
"form > div:nth-child(2) > div:nth-child(5) input"
|
||||
).first
|
||||
self.wait_visible(payment_input, timeout_ms=5_000)
|
||||
for _ in range(30):
|
||||
cls = payment_select_wrapper.get_attribute("class") or ""
|
||||
if "is-disabled" not in cls:
|
||||
break
|
||||
self.page.wait_for_timeout(200)
|
||||
else:
|
||||
raise RuntimeError("收款模式下拉框始终未解除 disabled,可能车队长选择未生效")
|
||||
payment_input.click()
|
||||
self.page.wait_for_timeout(800)
|
||||
|
||||
# Step 4: 在下拉列表中点击"车队长全额收款"
|
||||
full_payment_option = self.page.locator(
|
||||
"body > div.el-select-dropdown.el-popper "
|
||||
"> div.el-scrollbar > div.el-select-dropdown__wrap.el-scrollbar__wrap "
|
||||
"> ul > li.el-select-dropdown__item.selected"
|
||||
).nth(-1)
|
||||
self.wait_visible(full_payment_option, timeout_ms=5_000)
|
||||
full_payment_option.click()
|
||||
self.page.wait_for_timeout(800)
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 运单审核
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
def do_waybill_audit(self, order_no: str):
|
||||
"""运单审核:导航→搜索→审核→滚动弹窗→审核通过。"""
|
||||
self._go("tms/Carrier/OrderDetailAudit")
|
||||
self._fill_order_no(order_no)
|
||||
self._click_search()
|
||||
|
||||
# 点击审核 (button_index=2, selector 文档 Step 10)
|
||||
self._click_table_action(button_index=2)
|
||||
|
||||
# 滚动弹窗 (selector 文档 Step 11)
|
||||
self._scroll_modal()
|
||||
|
||||
# 审核通过 (selector 文档 Step 12)
|
||||
btn = self._modal().locator(
|
||||
"._btns > button.el-button.el-button--primary.el-button--medium > span"
|
||||
).first
|
||||
self._retry_click_modal_btn(btn, wait_after=1500)
|
||||
self.screenshot("waybill_audit_done")
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 垫资-财务打款
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
def do_finance_payment(self, order_no: str, verify_code: str = "1234"):
|
||||
"""垫资-财务打款:导航→搜索→在线支付→滚动→勾选光大/手机→验证码→确认。"""
|
||||
self._go("tms/Carrier/dzFinancialapproval")
|
||||
self._fill_order_no(order_no)
|
||||
self._click_search()
|
||||
|
||||
# 在线支付 (button_index=2, selector 文档 Step 18)
|
||||
self._click_table_action(button_index=2)
|
||||
self._scroll_modal()
|
||||
|
||||
# 勾选光大银行 (selector 文档 Step 20)
|
||||
try:
|
||||
radio = self._modal().locator(
|
||||
"form > div:nth-child(9) > div > div:nth-child(2) "
|
||||
"> label > span.el-radio__input > span"
|
||||
).first
|
||||
self._retry_click_modal_btn(radio, timeout_ms=3_000, wait_after=300)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 勾选手机号 (selector 文档 Step 21)
|
||||
try:
|
||||
radio = self.page.locator(
|
||||
"[id^='el-collapse-content-'] > div > div:nth-child(3) "
|
||||
"> label > span.el-radio__input > span"
|
||||
).first
|
||||
self._retry_click_modal_btn(radio, timeout_ms=3_000, wait_after=300)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 获取验证码 (selector 文档 Step 22)
|
||||
try:
|
||||
btn = self._modal().locator(
|
||||
"form > div.el-row > div.el-col.el-col-4 button span"
|
||||
).first
|
||||
self._retry_click_modal_btn(btn, timeout_ms=3_000, wait_after=500)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 输入验证码 (selector 文档 Step 23)
|
||||
try:
|
||||
inp = self._modal().locator(
|
||||
"form > div.el-row > div.el-col.el-col-20 input"
|
||||
).first
|
||||
self.wait_visible(inp)
|
||||
inp.clear()
|
||||
inp.fill(verify_code)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 确认打款 (selector 文档 Step 24)
|
||||
btn = self._modal().locator(
|
||||
"form > div:nth-child(12) > div > button span"
|
||||
).first
|
||||
self._retry_click_modal_btn(btn, wait_after=1500)
|
||||
self.screenshot("finance_payment_done")
|
||||
|
||||
# ════════════════════════════════════════════════════════════
|
||||
# 垫资-货主打款
|
||||
# ════════════════════════════════════════════════════════════
|
||||
|
||||
def do_shipper_payment(self, order_no: str):
|
||||
"""垫资-货主打款:导航→搜索→打款→勾选光大→确认打款→确认弹窗。"""
|
||||
self._go("tms/Carrier/dzApplicationForPayment")
|
||||
self._fill_order_no(order_no)
|
||||
self._click_search()
|
||||
|
||||
# 打款 (button_index=2, selector 文档 Step 30)
|
||||
self._click_table_action(button_index=2)
|
||||
|
||||
# 勾选光大 (selector 文档 Step 31)
|
||||
try:
|
||||
radio = self._modal().locator(
|
||||
"form > div > div:nth-child(3) > div > div > div:nth-child(3) "
|
||||
"> label > span.el-radio__label"
|
||||
).first
|
||||
self._retry_click_modal_btn(radio, timeout_ms=3_000, wait_after=300)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 确认打款 (selector 文档 Step 31-2)
|
||||
btn = self._modal().locator("> div > div > button > span").first
|
||||
self._retry_click_modal_btn(btn, wait_after=1000)
|
||||
|
||||
# message-box 确认 (selector 文档 Step 32)
|
||||
try:
|
||||
msg = self.page.locator(
|
||||
"body > div.el-message-box__wrapper .el-message-box__btns "
|
||||
"> button.el-button.el-button--default.el-button--small.el-button--primary > span"
|
||||
)
|
||||
self._retry_click_modal_btn(msg, timeout_ms=5_000, wait_after=1500)
|
||||
except Exception:
|
||||
pass
|
||||
self.screenshot("shipper_payment_done")
|
||||
Reference in New Issue
Block a user