import { Page, expect } from '@playwright/test'; export class DictionaryManagementPage { readonly page: Page; readonly table; readonly addButton; readonly editButton; readonly deleteButton; readonly saveButton; readonly cancelButton; readonly searchInput; readonly searchButton; readonly dictNameInput; readonly dictTypeInput; readonly dictStatusSelect; constructor(page: Page) { this.page = page; this.table = page.locator('.el-table'); this.addButton = page.getByRole('button', { name: '新增字典' }); this.editButton = page.getByRole('button', { name: '编辑' }); this.deleteButton = page.getByRole('button', { name: '删除' }); this.saveButton = page.getByRole('button', { name: '确定' }); this.cancelButton = page.getByRole('button', { name: '取消' }); this.searchInput = page.getByPlaceholder('搜索字典名称'); this.searchButton = page.getByRole('button', { name: '搜索' }); this.dictNameInput = page.getByPlaceholder('请输入字典名称'); this.dictTypeInput = page.getByPlaceholder('请输入字典类型'); this.dictStatusSelect = page.locator('.el-select'); } async goto() { await this.page.goto('/system/dict'); await this.page.waitForLoadState('networkidle'); } async addDictionary(dictName: string, dictType: string, status: string = '0') { await this.addButton.click(); await this.dictNameInput.fill(dictName); await this.dictTypeInput.fill(dictType); await this.saveButton.click(); await this.page.waitForLoadState('networkidle'); } async editDictionary(dictType: string, newName: string) { const row = this.table.locator('tr').filter({ hasText: dictType }).first(); await row.locator('.el-button--primary').click(); await this.dictNameInput.clear(); await this.dictNameInput.fill(newName); await this.saveButton.click(); await this.page.waitForLoadState('networkidle'); } async deleteDictionary(dictType: string) { const row = this.table.locator('tr').filter({ hasText: dictType }).first(); await row.locator('.el-button--danger').click(); await this.saveButton.click(); await this.page.waitForLoadState('networkidle'); } async searchDictionary(keyword: string) { await this.searchInput.fill(keyword); await this.searchButton.click(); await this.page.waitForLoadState('networkidle'); } async clearSearch() { await this.searchInput.clear(); await this.searchButton.click(); await this.page.waitForLoadState('networkidle'); } async verifyTableContains(text: string) { await expect(this.table).toContainText(text); } async verifyTableNotContains(text: string) { await expect(this.table).not.toContainText(text); } async getTableRowCount() { const rows = await this.table.locator('.el-table__row').count(); return rows; } }