08ea5fbe98
添加用户管理视图、API和状态管理文件
76 lines
1.8 KiB
TypeScript
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();
|
|
}
|
|
}
|