From b150ad346b97d78f7ccc716106f1754c91b21ec4 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Sun, 12 Apr 2026 09:17:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(content):=20=E4=BF=AE=E5=A4=8D=E5=86=85?= =?UTF-8?q?=E5=AE=B9ID=E6=8F=90=E5=8F=96=E5=92=8C=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E6=89=BE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - contentId包含下划线和连字符,但正则表达式只匹配字母和数字 - 搜索后列表为空,没有清空搜索框 修复: 1. 正则表达式:增加下划线和连字符匹配 2. 搜索逻辑:搜索无结果时清空搜索框重新显示所有内容 3. 等待时间:增加更长的等待时间确保列表加载完成 测试结果: - Chromium: ✓ 编辑内容测试通过 --- e2e/pages/AdminContentPage.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/e2e/pages/AdminContentPage.ts b/e2e/pages/AdminContentPage.ts index 8dfccc7..3d3b362 100644 --- a/e2e/pages/AdminContentPage.ts +++ b/e2e/pages/AdminContentPage.ts @@ -66,7 +66,7 @@ export class AdminContentPage { await this.page.click('button:has-text("发布")'); try { - await this.page.waitForURL(/\/admin\/content\/[a-zA-Z0-9]+/, { timeout: 15000 }); + await this.page.waitForURL(/\/admin\/content\/[a-zA-Z0-9_-]+/, { timeout: 15000 }); } catch { console.log('等待URL跳转失败,当前URL:', this.page.url()); @@ -86,7 +86,7 @@ export class AdminContentPage { const url = this.page.url(); console.log('最终URL:', url); - const match = url.match(/\/admin\/content\/([a-zA-Z0-9]+)/); + const match = url.match(/\/admin\/content\/([a-zA-Z0-9_-]+)/); const contentId = match ? match[1] : null; if (!contentId) { @@ -152,7 +152,7 @@ export class AdminContentPage { await this.goto(); await this.page.waitForLoadState('domcontentloaded'); - await this.page.waitForTimeout(2000); + await this.page.waitForTimeout(3000); let row = this.page.locator(`tr:has-text("${title}")`); let isVisible = await row.count() > 0; @@ -164,10 +164,20 @@ export class AdminContentPage { if (await searchInput.count() > 0) { await searchInput.fill(title); await this.page.keyboard.press('Enter'); - await this.page.waitForTimeout(2000); + await this.page.waitForTimeout(3000); row = this.page.locator(`tr:has-text("${title}")`); isVisible = await row.count() > 0; + + if (!isVisible) { + console.log('搜索无结果,清空搜索框'); + await searchInput.fill(''); + await this.page.keyboard.press('Enter'); + await this.page.waitForTimeout(2000); + + row = this.page.locator(`tr:has-text("${title}")`); + isVisible = await row.count() > 0; + } } } @@ -175,7 +185,7 @@ export class AdminContentPage { console.log('搜索后仍未找到,尝试刷新页面'); await this.page.reload({ waitUntil: 'domcontentloaded' }); await this.page.waitForSelector('table', { timeout: 10000, state: 'visible' }); - await this.page.waitForTimeout(2000); + await this.page.waitForTimeout(3000); row = this.page.locator(`tr:has-text("${title}")`); isVisible = await row.count() > 0; @@ -192,7 +202,7 @@ export class AdminContentPage { } } - await expect(row.first()).toBeVisible({ timeout: 15000 }); + await expect(row.first()).toBeVisible({ timeout: 20000 }); console.log(`✅ 找到内容: ${title}`); }