Files
everything-is-suitable/everything-is-suitable-test/e2e/uniapp/pages/base-page.ts
T
张翔 08ea5fbe98 feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
2026-03-28 14:37:29 +08:00

76 lines
1.8 KiB
TypeScript

import { Page, Locator } from '@playwright/test';
export class BasePage {
protected page: Page;
protected baseURL: string;
constructor(page: Page, baseURL: string = 'http://localhost:5173') {
this.page = page;
this.baseURL = baseURL;
}
async navigate(path: string = '') {
await this.page.goto(`${this.baseURL}${path}`);
await this.waitForLoad();
}
async waitForLoad() {
await this.page.waitForLoadState('networkidle');
}
async waitForSelector(selector: string, timeout: number = 10000) {
await this.page.waitForSelector(selector, { timeout });
}
async clickElement(selector: string) {
await this.page.click(selector);
}
async fillInput(selector: string, value: string) {
await this.page.fill(selector, value);
}
async getText(selector: string): Promise<string> {
return await this.page.textContent(selector) || '';
}
async isVisible(selector: string): Promise<boolean> {
return await this.page.isVisible(selector);
}
async isHidden(selector: string): Promise<boolean> {
return await this.page.isHidden(selector);
}
async waitForElementVisible(selector: string, timeout: number = 10000) {
await this.page.waitForSelector(selector, { state: 'visible', timeout });
}
async takeScreenshot(name: string) {
await this.page.screenshot({ path: `test-results/screenshots/${name}.png` });
}
async reload() {
await this.page.reload();
await this.waitForLoad();
}
async goBack() {
await this.page.goBack();
await this.waitForLoad();
}
async goForward() {
await this.page.goForward();
await this.waitForLoad();
}
async getURL(): Promise<string> {
return this.page.url();
}
async getTitle(): Promise<string> {
return await this.page.title();
}
}