diff --git a/tests/content.spec.ts b/tests/content.spec.ts index 6751b392..7f9b3bf5 100644 --- a/tests/content.spec.ts +++ b/tests/content.spec.ts @@ -315,10 +315,10 @@ test('測試导航', async ({ room, content, serviceWorker }) => { logger.info('正在測試導航前向...') - const next = content.getByRole('button', { name: '下一步' }) - const previous = content.getByRole('button', { name: '上一步' }) - const skip = content.getByRole('button', { name: '跳过' }) - const finish = content.getByRole('button', { name: '完成' }) + const next = content.locator('[data-test-id=button-primary]').filter({ hasText: '下一步' }) + const previous = content.locator('[data-test-id=button-back]') + const skip = content.locator('[data-test-id=button-skip]') + const finish = content.locator('[data-test-id=button-primary]').filter({ hasText: '完成' }) while (await next.isVisible()) { await next.click() diff --git a/tests/features/jimaku.spec.ts b/tests/features/jimaku.spec.ts index 75cb302f..37e4dcc4 100644 --- a/tests/features/jimaku.spec.ts +++ b/tests/features/jimaku.spec.ts @@ -173,11 +173,11 @@ test('測試離線記錄彈幕', async ({ room, content: p, context, tabUrl, pag expect(subtitleList.length).toBe(0) }) -test('測試房間名單列表(黑名單/白名單)', +test('測試房間名單列表(黑名單/白名單)', { tag: "@scoped"}, testFeatureRoomList( 'jimaku', expect, - (content) => content.getByTestId('subtitle-list') + (content) => content.locator('#subtitle-list') ) ) diff --git a/tests/pages/settings.spec.ts b/tests/pages/settings.spec.ts index 2df58f61..8c024eb4 100644 --- a/tests/pages/settings.spec.ts +++ b/tests/pages/settings.spec.ts @@ -423,7 +423,7 @@ test('測試設定數據從MV2遷移', async ({ serviceWorker, page }) => { }) -test('測試导航', async ({ page, serviceWorker }) => { +test('測試导航', { tag: "@scoped" }, async ({ page, serviceWorker }) => { const overlay = page.locator('.react-joyride__overlay') @@ -435,10 +435,10 @@ test('測試导航', async ({ page, serviceWorker }) => { logger.info('正在測試導航前向...') - const next = page.getByText('下一步') - const previous = page.getByText('上一步') - const skip = page.getByText('跳过') - const finish = page.getByText('完成') + const next = page.locator('[data-test-id=button-primary]').filter({ hasText: '下一步' }) + const previous = page.locator('[data-test-id=button-back]') + const skip = page.locator('[data-test-id=button-skip]') + const finish = page.locator('[data-test-id=button-primary]').filter({ hasText: '完成' }) while (await next.isVisible()) { await next.click() diff --git a/tests/utils/playwright.ts b/tests/utils/playwright.ts index 4ff1193f..98a25ee2 100644 --- a/tests/utils/playwright.ts +++ b/tests/utils/playwright.ts @@ -37,6 +37,26 @@ export async function getSuperChatList(section: Locator, options?: { return section.getByRole('menu').locator('section.bjf-scrollbar > div').filter(options).all() } +/** + * A utility function that tests a feature in a room list. + * + * @param feature - The feature to test. + * @param expect - The expect function from the testing framework. + * @param locate - A function that locates the content on the page. + * @returns A pre-configured test function that tests the feature in a room list. + * + * @example + * + * ```ts + * test('測試房間名單列表(黑名單/白名單)', + * testFeatureRoomList( + * 'jimaku', + * expect, + * (content) => content.locator('#subtitle-list') + * ) + * ) + * ``` + */ export function testFeatureRoomList(feature: string, expect: Expect, locate: (content: PageFrame) => Locator): (args: any) => Promise { return async ({ room, content, context, tabUrl }) => {