first commit
This commit is contained in:
58
pages/BasePage.ts
Normal file
58
pages/BasePage.ts
Normal file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 页面基类
|
||||
* 提供所有页面共享的方法和属性
|
||||
*/
|
||||
|
||||
import { Page, expect } from '@playwright/test';
|
||||
import { TestConfig } from '../config/test.config';
|
||||
|
||||
export class BasePage {
|
||||
protected page: Page;
|
||||
protected config = TestConfig;
|
||||
|
||||
constructor(page: Page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待页面稳定
|
||||
*/
|
||||
async waitForPageStable(timeout: number = this.config.waits.pageStable): Promise<void> {
|
||||
console.log(`等待 ${timeout / 1000} 秒让页面稳定...`);
|
||||
await this.page.waitForTimeout(timeout);
|
||||
console.log('页面已稳定,继续下一步');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导航到指定URL
|
||||
*/
|
||||
async goto(url: string): Promise<void> {
|
||||
await this.page.goto(url, { timeout: this.config.timeouts.navigation });
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击元素
|
||||
*/
|
||||
async click(selector: string): Promise<void> {
|
||||
await this.page.click(selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充输入框
|
||||
*/
|
||||
async fill(selector: string, text: string): Promise<void> {
|
||||
await this.page.fill(selector, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查元素是否可见
|
||||
*/
|
||||
async isVisible(selector: string, timeout?: number): Promise<boolean> {
|
||||
try {
|
||||
await expect(this.page.locator(selector)).toBeVisible({ timeout });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user