From 8b8a27d0ac8b04d1e377c5860c6d4e3240649c05 Mon Sep 17 00:00:00 2001 From: shunli Date: Wed, 6 May 2026 20:44:57 +0800 Subject: [PATCH] =?UTF-8?q?R98=20A5=20=E6=94=AF=E6=8C=81=20smoke=20?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=A4=8D=E6=A0=B8=E7=9C=9F=E5=AE=9E=20OCR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/tests/e2e/helpers/liveInvoiceOcr.ts | 27 +++++++++++++++++++ .../e2e/manual/live-invoice-ocr-batch.spec.ts | 9 ++++--- .../tests/e2e/manual/live-invoice-ocr.spec.ts | 10 ++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/client/tests/e2e/helpers/liveInvoiceOcr.ts b/client/tests/e2e/helpers/liveInvoiceOcr.ts index 048be9c5..7785e9f0 100644 --- a/client/tests/e2e/helpers/liveInvoiceOcr.ts +++ b/client/tests/e2e/helpers/liveInvoiceOcr.ts @@ -1,5 +1,7 @@ import { expect, type Page } from "@playwright/test"; +import type { E2EUser } from "./auth"; + export type LiveInvoiceOcrStatus = "available" | "ocr_failed"; export type LiveInvoiceOcrResult = { @@ -21,6 +23,31 @@ function extractField(detailText: string, label: string) { return match?.[1]?.trim() || null; } +export function resolveLiveOcrUser(fallback: E2EUser): E2EUser { + const identifier = + process.env.PLAYWRIGHT_OCR_LIVE_IDENTIFIER?.trim() || + process.env.LIVE_SMOKE_EMPLOYEE_IDENTIFIER?.trim() || + ""; + const password = + process.env.PLAYWRIGHT_OCR_LIVE_PASSWORD?.trim() || + process.env.LIVE_SMOKE_EMPLOYEE_PASSWORD?.trim() || + ""; + + if (!identifier && !password) { + return fallback; + } + + if (!identifier || !password) { + throw new Error("PLAYWRIGHT_OCR_LIVE_IDENTIFIER/PASSWORD 或 LIVE_SMOKE_EMPLOYEE_* 必须成对提供"); + } + + return { + identifier, + password, + name: process.env.PLAYWRIGHT_OCR_LIVE_NAME?.trim() || "Smoke Employee", + }; +} + export async function openInvoicePool(page: Page) { await page.goto("/invoice-pool"); await expect(page.getByTestId("invoice-pool-table")).toBeVisible(); diff --git a/client/tests/e2e/manual/live-invoice-ocr-batch.spec.ts b/client/tests/e2e/manual/live-invoice-ocr-batch.spec.ts index 5c1bbd89..03754584 100644 --- a/client/tests/e2e/manual/live-invoice-ocr-batch.spec.ts +++ b/client/tests/e2e/manual/live-invoice-ocr-batch.spec.ts @@ -2,8 +2,8 @@ import { existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from "nod import path from "node:path"; import { expect, test } from "../helpers/fixtures"; -import { EMPLOYEE, login, logout } from "../helpers/auth"; -import { openInvoicePool, uploadLiveInvoiceAndWait, type LiveInvoiceOcrResult } from "../helpers/liveInvoiceOcr"; +import { EMPLOYEE, login } from "../helpers/auth"; +import { openInvoicePool, resolveLiveOcrUser, uploadLiveInvoiceAndWait, type LiveInvoiceOcrResult } from "../helpers/liveInvoiceOcr"; type BatchResult = LiveInvoiceOcrResult & { filePath: string; @@ -79,7 +79,8 @@ test("手工 live 腾讯 OCR 批量辅助复核:真实票样逐张上传并输 test.skip(!invoiceFiles.length, "需要提供 PLAYWRIGHT_OCR_LIVE_FILE / PLAYWRIGHT_OCR_LIVE_FILES / PLAYWRIGHT_OCR_LIVE_DIR"); const results: BatchResult[] = []; - await login(page, EMPLOYEE); + const liveOcrUser = resolveLiveOcrUser(EMPLOYEE); + await login(page, liveOcrUser); try { await openInvoicePool(page); @@ -95,7 +96,7 @@ test("手工 live 腾讯 OCR 批量辅助复核:真实票样逐张上传并输 } } finally { writeReport(results); - await logout(page, EMPLOYEE.name).catch(() => undefined); + await page.context().clearCookies().catch(() => undefined); } const failures = results.filter((item) => item.status === "ocr_failed"); diff --git a/client/tests/e2e/manual/live-invoice-ocr.spec.ts b/client/tests/e2e/manual/live-invoice-ocr.spec.ts index d704ca12..137bbeb7 100644 --- a/client/tests/e2e/manual/live-invoice-ocr.spec.ts +++ b/client/tests/e2e/manual/live-invoice-ocr.spec.ts @@ -1,8 +1,8 @@ import { existsSync } from "node:fs"; import { test, expect } from "../helpers/fixtures"; -import { EMPLOYEE, login, logout } from "../helpers/auth"; -import { openInvoicePool, uploadLiveInvoiceAndWait } from "../helpers/liveInvoiceOcr"; +import { EMPLOYEE, login } from "../helpers/auth"; +import { openInvoicePool, resolveLiveOcrUser, uploadLiveInvoiceAndWait } from "../helpers/liveInvoiceOcr"; test("手工 live 腾讯 OCR 辅助复核:真实 VAT 发票上传后进入可处理状态", async ({ page }) => { test.skip(process.env.PLAYWRIGHT_MANUAL !== "1", "仅在显式手工 Playwright 模式下执行"); @@ -11,7 +11,9 @@ test("手工 live 腾讯 OCR 辅助复核:真实 VAT 发票上传后进入可 const invoiceFilePath = process.env.PLAYWRIGHT_OCR_LIVE_FILE?.trim() ?? ""; test.skip(!invoiceFilePath || !existsSync(invoiceFilePath), "需要提供存在的 PLAYWRIGHT_OCR_LIVE_FILE"); - await login(page, EMPLOYEE); + const liveOcrUser = resolveLiveOcrUser(EMPLOYEE); + + await login(page, liveOcrUser); await openInvoicePool(page); const result = await uploadLiveInvoiceAndWait(page, invoiceFilePath); @@ -23,5 +25,5 @@ test("手工 live 腾讯 OCR 辅助复核:真实 VAT 发票上传后进入可 expect(result.totalAmount, JSON.stringify(result)).toBeTruthy(); expect(result.totalAmount, JSON.stringify(result)).not.toBe("-"); - await logout(page, EMPLOYEE.name); + await page.context().clearCookies().catch(() => undefined); });