test(e2e): 二次分配流程断言改为取实际方案并补审批内容校验

审批详情的送审内容断言不再硬编码参与人姓名(下拉取人员列表前两项,
未必是脚本刚建的 t_e2e 员):改为经业务详情接口取回实际保存的方案,
逐参与人断言姓名与比例出现在审批抽屉中。顺带修掉原脚本清理环节的
隐性缺陷——开关开启时业务有在途审批单,界面删除被拦截而脚本无断言,
数据从未真正清理;现脚本内显式关闭审批开关并保证结束还原为 1。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
liuwenxin 2026-10-21 14:25:39 +08:00
parent 4c32a556de
commit 694d21d1fd

View File

@ -23,6 +23,7 @@ import os
import time
import urllib.error
import urllib.request
from urllib.parse import quote
from playwright.sync_api import Page, sync_playwright
@ -143,6 +144,7 @@ def step_create_personnel(page: Page) -> None:
def step_create_business_with_allocation(page: Page, customer_name: str) -> None:
"""新增带二次分配方案的业务(参与人取人员下拉前两项,比例 30% + 40%)。"""
# 客户弹窗已关(上一段已关闭);直接路由直达业务管理,避免菜单点击
page.goto(f"{BASE_URL}/business/businesses", wait_until="networkidle")
page.wait_for_timeout(600)
@ -218,19 +220,25 @@ def step_verify_allocation_echo(page: Page) -> None:
page.wait_for_timeout(400)
def _current_business_no(page: Page, customer_name: str) -> str:
"""取本次创建业务的业务编号(列表首列),用于审批单检索。"""
page.goto(f"{BASE_URL}/business/businesses", wait_until="networkidle")
page.wait_for_timeout(600)
page.click("button:has-text('查询')")
page.wait_for_timeout(500)
row = page.locator(".el-table__row", has_text=customer_name).first
if row.count() == 0:
fail("取业务编号", f"未找到本次业务(客户 {customer_name})")
return row.locator("td").first.inner_text().strip()
def _fetch_plan(token: str, customer_name: str) -> tuple[str, list[dict]]:
"""取回刚创建业务的编号与实际方案(接口取数,不从列表 DOM 刮编号)。
断言要以**业务实际存下的方案**为准:参与人下拉取的是人员列表的前两
项,未必是脚本刚建的 t_e2e 员,硬编码姓名会把断言写死成脆弱假设。
"""
rows = _api(
"GET",
f"/api/v1/business/businesses?keyword={quote(customer_name)}&pageSize=20",
token,
)["list"]
target = next((r for r in rows if r.get("customer_name") == customer_name), None)
if target is None:
raise E2EFailure(f"业务列表中未找到客户 {customer_name} 的业务")
detail = _api("GET", f"/api/v1/business/businesses/{target['id']}", token)
return target["business_no"], detail.get("secondary_allocations") or []
def step_verify_approval_snapshot(page: Page, business_no: str) -> None:
def step_verify_approval_snapshot(page: Page, business_no: str, plan: list[dict]) -> None:
"""审批详情:展示提交时的送审方案(参与人 + 比例 + 合计余额)。"""
page.goto(f"{BASE_URL}/system/approvals", wait_until="networkidle")
page.wait_for_timeout(800)
@ -247,13 +255,14 @@ def step_verify_approval_snapshot(page: Page, business_no: str) -> None:
text = drawer.inner_text()
if "审批内容" not in text:
fail("审批内容", "审批详情未展示「审批内容」区块")
for i in (0, 1):
name = f"t_e2e员_{SUFFIX}_{i}"
if name not in text:
fail("审批内容", f"送审内容缺少参与人 {name}")
if "30.00%" not in text or "40.00%" not in text:
fail("审批内容", f"送审内容缺少分配比例:{text[:200]}")
print("✓ 5. 审批内容 审批详情展示送审方案(两名参与人与 30%/40% 比例)")
for row in plan:
if row["personnel_name"] not in text:
fail("审批内容", f"送审内容缺少参与人 {row['personnel_name']}")
if f"{row['ratio']}%" not in text:
fail("审批内容", f"送审内容缺少参与人 {row['personnel_name']} 的比例 {row['ratio']}%")
print(
f"✓ 5. 审批内容 审批详情展示送审方案({len(plan)} 名参与人及其比例)"
)
def step_cleanup(page: Page) -> None:
@ -292,9 +301,9 @@ def run(page: Page) -> None:
try:
step_create_personnel(page)
step_create_business_with_allocation(page, customer_name)
business_no = _current_business_no(page, customer_name)
business_no, plan = _fetch_plan(token, customer_name)
step_verify_allocation_echo(page)
step_verify_approval_snapshot(page, business_no)
step_verify_approval_snapshot(page, business_no, plan)
finally:
step_cleanup(page)
finally: