Files
zhuangang/topics/frontend/fe-testing-perf/examples/search-box/e2e/search.spec.ts
T

14 lines
746 B
TypeScript

// 不自动运行:Playwright 端到端测试示意(需要 npx playwright install 并启动被测站点;本仓库未在浏览器中实际运行)
// 以官方文档为准:https://playwright.dev/docs/intro
import { expect, test } from "@playwright/test";
test("用户搜索订单并看到结果", async ({ page }) => {
// 拦截接口返回固定数据:端到端测试只验证前端流程,不依赖后端数据
await page.route("**/api/orders/search**", (route) =>
route.fulfill({ json: ["A001", "A002"] }),
);
await page.goto("http://localhost:5173/orders");
await page.getByLabel("搜索订单").fill("A00");
await expect(page.getByRole("list", { name: "搜索结果" }).getByRole("listitem")).toHaveCount(2);
});