71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { Page, Locator, expect } from "@playwright/test";
|
||
|
||
export class HealthScorePage {
|
||
readonly page: Page;
|
||
readonly brandInput: Locator;
|
||
readonly checkButton: Locator;
|
||
readonly scoreDisplay: Locator;
|
||
readonly healthLevelBadge: Locator;
|
||
readonly dimensionHeading: Locator;
|
||
readonly registerButton: Locator;
|
||
readonly errorState: Locator;
|
||
readonly loadingSpinner: Locator;
|
||
|
||
constructor(page: Page) {
|
||
this.page = page;
|
||
// placeholder="输入品牌名称,如:华为"
|
||
this.brandInput = page.locator('input[placeholder*="品牌"]');
|
||
// 按钮文字是 "开始检测"
|
||
this.checkButton = page.getByRole("button", { name: /开始检测/ });
|
||
// 分数显示在 span.text-7xl 中
|
||
this.scoreDisplay = page.locator("span.text-7xl").first();
|
||
// 健康等级 Badge — shadcn Badge 没有 data-slot,用 variant+class 定位
|
||
this.healthLevelBadge = page.locator("span.text-base.px-4.py-1, [class*='badge']").first();
|
||
// 维度评分标题
|
||
this.dimensionHeading = page.getByText("维度评分");
|
||
// 查看详细修复建议按钮
|
||
this.registerButton = page.getByRole("button", { name: /查看详细修复建议/ });
|
||
// 错误状态
|
||
this.errorState = page.getByText("检测失败");
|
||
// 加载动画
|
||
this.loadingSpinner = page.locator(".animate-spin");
|
||
}
|
||
|
||
async goto() {
|
||
await this.page.goto("/health-score");
|
||
await this.page.waitForLoadState("domcontentloaded");
|
||
}
|
||
|
||
async gotoWithBrand(brand: string) {
|
||
await this.page.goto(`/health-score?brand=${encodeURIComponent(brand)}`);
|
||
await this.page.waitForLoadState("domcontentloaded");
|
||
}
|
||
|
||
async checkBrand(brandName: string) {
|
||
await this.brandInput.fill(brandName);
|
||
await this.checkButton.click();
|
||
}
|
||
|
||
async waitForResults(timeout = 30000) {
|
||
await expect(this.scoreDisplay).toBeVisible({ timeout });
|
||
}
|
||
|
||
async hasResults(timeout = 10000): Promise<boolean> {
|
||
try {
|
||
await expect(this.scoreDisplay).toBeVisible({ timeout });
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
async hasError(timeout = 10000): Promise<boolean> {
|
||
try {
|
||
await expect(this.errorState).toBeVisible({ timeout });
|
||
return true;
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
}
|