From e47171bf014227f8b7aa09f520d22d1474c51268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Fri, 6 Mar 2026 12:13:01 +0800 Subject: [PATCH] feat: add shared fixtures for testing --- .../shared/fixtures/accessibility.fixture.ts | 15 +++++ .../shared/fixtures/base.fixture.ts | 65 +++++++++++++++++++ .../shared/fixtures/performance.fixture.ts | 29 +++++++++ 3 files changed, 109 insertions(+) create mode 100644 test-framework/shared/fixtures/accessibility.fixture.ts create mode 100644 test-framework/shared/fixtures/base.fixture.ts create mode 100644 test-framework/shared/fixtures/performance.fixture.ts diff --git a/test-framework/shared/fixtures/accessibility.fixture.ts b/test-framework/shared/fixtures/accessibility.fixture.ts new file mode 100644 index 0000000..b7b5d26 --- /dev/null +++ b/test-framework/shared/fixtures/accessibility.fixture.ts @@ -0,0 +1,15 @@ +import { test as base } from '@playwright/test'; +import { AccessibilityTester } from '../utils/accessibility/AccessibilityTester'; + +type MyFixtures = { + accessibilityTester: AccessibilityTester; +}; + +export const test = base.extend({ + accessibilityTester: async ({ page }, use) => { + const tester = new AccessibilityTester(page); + await use(tester); + } +}); + +export { expect } from '@playwright/test'; diff --git a/test-framework/shared/fixtures/base.fixture.ts b/test-framework/shared/fixtures/base.fixture.ts new file mode 100644 index 0000000..7ca5fe4 --- /dev/null +++ b/test-framework/shared/fixtures/base.fixture.ts @@ -0,0 +1,65 @@ +import { test as base } from '@playwright/test'; +import { BasePage, HomePage, AboutPage, ContactPage, ProductsPage, ServicesPage, CasesPage, NewsPage } from '../pages'; +import { getEnvironmentConfig } from '../config/environments'; + +type MyFixtures = { + basePage: BasePage; + homePage: HomePage; + aboutPage: AboutPage; + contactPage: ContactPage; + productsPage: ProductsPage; + servicesPage: ServicesPage; + casesPage: CasesPage; + newsPage: NewsPage; + config: any; +}; + +export const test = base.extend({ + config: async ({}, use) => { + const env = process.env.TEST_ENV || 'development'; + const config = getEnvironmentConfig(env); + await use(config); + }, + + basePage: async ({ page }, use) => { + const basePage = new BasePage(page, '/'); + await use(basePage); + }, + + homePage: async ({ page, config }, use) => { + const homePage = new HomePage(page, config); + await use(homePage); + }, + + aboutPage: async ({ page, config }, use) => { + const aboutPage = new AboutPage(page, config); + await use(aboutPage); + }, + + contactPage: async ({ page, config }, use) => { + const contactPage = new ContactPage(page, config); + await use(contactPage); + }, + + productsPage: async ({ page, config }, use) => { + const productsPage = new ProductsPage(page, config); + await use(productsPage); + }, + + servicesPage: async ({ page, config }, use) => { + const servicesPage = new ServicesPage(page, config); + await use(servicesPage); + }, + + casesPage: async ({ page, config }, use) => { + const casesPage = new CasesPage(page, config); + await use(casesPage); + }, + + newsPage: async ({ page, config }, use) => { + const newsPage = new NewsPage(page, config); + await use(newsPage); + } +}); + +export { expect } from '@playwright/test'; diff --git a/test-framework/shared/fixtures/performance.fixture.ts b/test-framework/shared/fixtures/performance.fixture.ts new file mode 100644 index 0000000..a811245 --- /dev/null +++ b/test-framework/shared/fixtures/performance.fixture.ts @@ -0,0 +1,29 @@ +import { test as base } from '@playwright/test'; +import { PerformanceMonitor } from '../utils/performance/PerformanceMonitor'; +import { LighthouseRunner } from '../utils/performance/LighthouseRunner'; +import { CoreWebVitals } from '../utils/performance/CoreWebVitals'; + +type MyFixtures = { + performanceMonitor: PerformanceMonitor; + lighthouseRunner: LighthouseRunner; + coreWebVitals: CoreWebVitals; +}; + +export const test = base.extend({ + performanceMonitor: async ({ page }, use) => { + const monitor = new PerformanceMonitor(page); + await use(monitor); + }, + + lighthouseRunner: async ({ page }, use) => { + const runner = new LighthouseRunner(page); + await use(runner); + }, + + coreWebVitals: async ({ page }, use) => { + const vitals = new CoreWebVitals(page); + await use(vitals); + } +}); + +export { expect } from '@playwright/test';