test(e2e): 回款统计改按本次业务编号下钻断言

历史 e2e 数据会累计到同一回款区间桶,断言桶聚合值在重复运行时必然失败;改为展开目标桶后按本次业务编号定位下钻行并校验金额,脚本可无副作用重跑。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
liuwenxin 2026-10-20 10:04:42 +08:00
parent c8131588bf
commit 980628bb8f

View File

@ -23,7 +23,6 @@ import os
import time
import urllib.error
import urllib.request
from decimal import Decimal
from playwright.sync_api import Page, sync_playwright
@ -75,15 +74,6 @@ def step_setup_via_api(page: Page) -> dict:
if not token:
fail("API 预置", "localStorage 中未取到 ys_token")
# 回款统计断言取增量:脚本可重复运行(上次失败/历史 e2e 数据会累计到桶)
baseline = _api(
"GET", f"/api/v1/reports/payment-stats?settlement_month={MONTH}", token
)
baseline_bucket = next(b for b in baseline["buckets"] if b["code"] == "61-90")
expected_receipt_amount = (
Decimal(str(baseline_bucket["receipt_amount"])) + Decimal("10000.00")
)
roles = _api("GET", "/api/v1/system/business-roles?pageNum=1&pageSize=50", token)["list"]
salesperson_role = next((r["id"] for r in roles if r["role_code"] == "salesperson"), None)
manager_role = next((r["id"] for r in roles if r["role_code"] == "sales_manager"), None)
@ -172,7 +162,6 @@ def step_setup_via_api(page: Page) -> dict:
"personnel_id": person["id"],
"personnel_name": person["personnel_name"],
"manager_name": manager["personnel_name"],
"expected_receipt_amount": f"{expected_receipt_amount:.2f}",
}
@ -246,11 +235,18 @@ def step_payment_stats(page: Page, ctx: dict) -> None:
).first
if bucket.count() == 0:
fail("回款统计", "未找到 61-90 天区间行")
bucket_text = bucket.inner_text()
expected = ctx["expected_receipt_amount"]
if expected not in bucket_text:
fail("回款统计", f"61-90 天桶回款金额不符(期望含 {expected}):{bucket_text[:120]}")
print("✓ 8. 回款统计 8 档区间与目标桶金额正确")
# 按本次业务编号在下钻明细中定位,不依赖桶聚合值(历史 e2e 数据会累计到同桶)
bucket.locator(".el-table__expand-icon").click()
page.wait_for_timeout(1000)
drill_row = page.locator(
".drill-wrap .el-table__row", has_text=ctx["business_no"]
).first
if drill_row.count() == 0:
fail("回款统计", f"61-90 天桶下钻未找到本次业务 {ctx['business_no']}")
drill_text = drill_row.inner_text()
if "10000.00" not in drill_text:
fail("回款统计", f"本次业务下钻行金额不符:{drill_text[:120]}")
print("✓ 8. 回款统计 8 档区间与本次业务下钻金额正确")
def step_payment_multi_expand(page: Page, ctx: dict) -> None: