geo/frontend/e2e/tests/health-score-smoke.spec.ts

57 lines
1.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, expect } from "@playwright/test";
import { HealthScorePage } from "../pages/health-score.page";
test.describe("获客路径烟雾测试", () => {
test("未登录用户访问健康分页面,输入品牌名后看到报告", async ({ page }) => {
const healthScorePage = new HealthScorePage(page);
await healthScorePage.goto();
// 验证输入表单可见
await expect(healthScorePage.brandInput).toBeVisible();
await expect(healthScorePage.checkButton).toBeVisible();
// 填入品牌名并点击检测
await healthScorePage.checkBrand("华为");
// 等待结果或错误API 可能不可用)
const hasResults = await healthScorePage.hasResults(15000);
if (!hasResults) {
const hasError = await healthScorePage.hasError(5000);
if (hasError) {
test.skip(true, "API 返回错误,跳过结果验证");
return;
}
// 既没有结果也没有错误,可能是超时
test.skip(true, "API 响应超时,跳过结果验证");
return;
}
// 验证分数显示
await expect(healthScorePage.scoreDisplay).toBeVisible();
const scoreText = await healthScorePage.scoreDisplay.textContent();
expect(scoreText).toMatch(/^\d+(\.\d+)?$/);
// 验证 /100 标记
await expect(page.getByText("/100")).toBeVisible();
// 验证维度评分
await expect(healthScorePage.dimensionHeading).toBeVisible();
// 验证查看详细修复建议按钮
await expect(healthScorePage.registerButton).toBeVisible();
});
test("健康分页面支持URL参数预填品牌名", async ({ page }) => {
const healthScorePage = new HealthScorePage(page);
await healthScorePage.gotoWithBrand("小米");
// 验证品牌名已预填
const brandInput = healthScorePage.brandInput;
await expect(brandInput).toBeVisible();
await expect(brandInput).toHaveValue("小米");
});
});