import { Page, Locator, expect } from '@playwright/test'; export class CourseLabelManagementPage { readonly page: Page; readonly table: Locator; readonly createButton: Locator; readonly searchInput: Locator; readonly searchButton: Locator; readonly successMessage: Locator; constructor(page: Page) { this.page = page; this.table = page.locator('.el-table').first(); this.createButton = page.getByRole('button', { name: '新增标签' }).or(page.locator('button:has-text("新增标签")')); 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')); } async goto() { console.log('导航到团课标签页面...'); await this.page.goto('/courses/labels'); await this.page.waitForLoadState('networkidle'); await this.table.waitFor({ state: 'visible', timeout: 10000 }); await expect(this.page).toHaveURL(/.*courses\/labels/); 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 clickCreate() { await this.createButton.click(); await this.page.waitForTimeout(500); } async search(keyword: string) { await this.searchInput.fill(keyword); await this.searchButton.click(); await this.page.waitForTimeout(500); } async getRowCount(): Promise { return await this.table.locator('tbody tr').count(); } async containsText(text: string): Promise { return await this.table.getByText(text).count() > 0; } }