51 lines
1.8 KiB
TypeScript
51 lines
1.8 KiB
TypeScript
import { Page, Locator, expect } from '@playwright/test';
|
|
|
|
export class MemberCardManagementPage {
|
|
readonly page: Page;
|
|
readonly table: Locator;
|
|
readonly searchInput: Locator;
|
|
readonly searchButton: Locator;
|
|
readonly successMessage: Locator;
|
|
readonly pagination: Locator;
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
this.table = page.locator('.el-table').first();
|
|
this.searchInput = page.locator('input[placeholder*="搜索"]').or(page.locator('input[name*="keyword"]'));
|
|
this.searchButton = page.getByRole('button', { name: '搜索' }).or(page.locator('button:has-text("搜索")'));
|
|
this.successMessage = page.locator('.el-message--success').or(page.locator('.success-message'));
|
|
this.pagination = page.locator('.el-pagination').or(page.locator('.pagination'));
|
|
}
|
|
|
|
async goto() {
|
|
console.log('导航到会员卡管理页面...');
|
|
await this.page.goto('/member-cards');
|
|
await this.page.waitForLoadState('networkidle');
|
|
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
|
await expect(this.page).toHaveURL(/.*member-cards/);
|
|
console.log('会员卡管理页面加载完成');
|
|
}
|
|
|
|
async waitForTableReady() {
|
|
await this.table.waitFor({ state: 'visible', timeout: 10000 });
|
|
await this.page.waitForFunction(
|
|
() => document.querySelectorAll('.el-table__body-wrapper tbody tr').length > 0,
|
|
{ timeout: 5000 }
|
|
).catch(() => console.log('表格没有数据,继续执行'));
|
|
}
|
|
|
|
async search(keyword: string) {
|
|
await this.searchInput.fill(keyword);
|
|
await this.searchButton.click();
|
|
await this.page.waitForTimeout(500);
|
|
}
|
|
|
|
async getRowCount(): Promise<number> {
|
|
return await this.table.locator('tbody tr').count();
|
|
}
|
|
|
|
async containsText(text: string): Promise<boolean> {
|
|
return await this.table.getByText(text).count() > 0;
|
|
}
|
|
}
|