Przeglądaj źródła

♻️ refactor(e2e): 优化残疾人个人管理页面对象定位器

- 将页面标题定位器从 `getByRole('heading')` 更改为更稳定的 `getByText`
- 将新增按钮定位器从 `getByTestId` 更改为语义化的 `getByRole('button', { name: '新增残疾人' })`
- 将搜索输入框定位器从 `getByTestId` 更改为更具描述性的 `getByPlaceholder`
- 在 `goto` 方法中,使用已定义的 `pageTitle` 定位器等待标题,提高代码可读性和可维护性
yourname 1 tydzień temu
rodzic
commit
ad4b04de75

+ 6 - 4
web/tests/e2e/pages/admin/disability-person.page.ts

@@ -10,9 +10,9 @@ export class DisabilityPersonManagementPage {
 
   constructor(page: Page) {
     this.page = page;
-    this.pageTitle = page.getByRole('heading', { name: '残疾人个人管理' });
-    this.addPersonButton = page.getByTestId('add-disabled-person-button');
-    this.keywordSearchInput = page.getByTestId('keyword-search-input');
+    this.pageTitle = page.getByText('残疾人个人管理');
+    this.addPersonButton = page.getByRole('button', { name: '新增残疾人' });
+    this.keywordSearchInput = page.getByPlaceholder('搜索姓名或身份证号');
     this.searchButton = page.getByRole('button', { name: '搜索' });
     this.personTable = page.locator('table');
   }
@@ -20,7 +20,9 @@ export class DisabilityPersonManagementPage {
   async goto() {
     await this.page.goto('/admin/disabilities');
     await this.page.waitForLoadState('domcontentloaded');
-    await this.page.waitForSelector('h1:has-text("残疾人个人管理")', { state: 'visible', timeout: 15000 });
+    // 等待页面标题出现
+    await this.pageTitle.waitFor({ state: 'visible', timeout: 15000 });
+    // 等待表格数据加载
     await this.page.waitForSelector('table tbody tr', { state: 'visible', timeout: 20000 });
     await this.expectToBeVisible();
   }