๐ŸŽญ ngx-playwright-schematics

August 17, 2026 ยท View on GitHub

npm version License Angular Playwright

An enterprise-grade Angular Schematics package that automates setting up and scaffolding a production-ready Playwright E2E testing architecture into any Angular application.


โšก Quick Start

In any Angular project root directory, simply run:

ng add ngx-playwright-schematics

Or run via generator:

ng g ngx-playwright-schematics:ng-add

CLI Options

OptionTypeDefaultDescription
--projectstring(default project)Specific project name in angular.json
--installBrowsersbooleanfalseAutomatically install Playwright browser binaries
--overwritebooleantrueSafely resolve conflicts and update existing configuration

Example with options:

ng add ngx-playwright-schematics --project=my-app --installBrowsers=true --overwrite=true

๐Ÿ”„ Schematic Execution Lifecycle

When you run ng add ngx-playwright-schematics, the schematic executes an idempotent, conflict-resilient pipeline:

flowchart TD
    START(["๐Ÿš€ ng add ngx-playwright-schematics"]) --> INSPECT["๐Ÿ” Inspect Workspace Environment<br/>(angular.json, package.json, eslint, .gitignore)"]

    INSPECT --> ANGULAR["1๏ธโƒฃ Configure angular.json<br/>- Add architect.e2e builder<br/>- Register schematic collections"]
    INSPECT --> PKG["2๏ธโƒฃ Merge package.json<br/>- Inject 19 E2E scripts<br/>- Add zod, @playwright/test, allure, tsx"]
    INSPECT --> ESLINT["3๏ธโƒฃ Update eslint.config.mjs<br/>- Inject strict boundary rule<br/>(blocks src/ imports in e2e/)"]
    INSPECT --> GIT["4๏ธโƒฃ Update .gitignore<br/>- Ignore test-results, reports, artifacts"]

    ANGULAR & PKG & ESLINT & GIT --> SCAFFOLD["5๏ธโƒฃ Deploy Blueprint Files (39 Files)<br/>- Component Objects & Page Objects<br/>- Modular Fixtures (mergeTests)<br/>- Zod Data Factory & Interceptors<br/>- GitHub Actions CI Matrix<br/>- Observability Scripts"]

    SCAFFOLD --> CONFLICT{"Conflict Detected?"}
    CONFLICT -- Yes --> RESOLVE["๐Ÿ›ก๏ธ Auto-Resolve with MergeStrategy.Overwrite<br/>(Gracefully update without halting)"]
    CONFLICT -- No --> TASKS
    RESOLVE --> TASKS["6๏ธโƒฃ Schedule Post-Tasks<br/>- NodePackageInstallTask (npm install)<br/>- Optional Browser Binaries Download"]

    TASKS --> DONE(["โœ… Setup Complete: npm run e2e"])

๐Ÿ›๏ธ Scaffolded Enterprise Architecture

The blueprint implements industry best practices for enterprise testing at scale:

graph TD
    subgraph "1. Playwright Test Runner & Configuration"
        CONFIG["playwright.config.ts<br/>- Cross-Platform Snapshot Templates<br/>- Session Caching (storageState: default.json)<br/>- Multi-Browser Projects (Chrome, Firefox)<br/>- Automated webServer Lifecycle<br/>- Multi-Reporters: HTML, Allure, JUnit, JSON, Blob"]
    end

    subgraph "2. Fixture Composition Layer (@fixtures/index)"
        MERGE["mergeTests() Composition Engine"]
        F_COM["componentFixtures<br/>(ToastComponent, LoaderComponent,<br/>ModalComponent, HeaderComponent)"]
        F_PAGE["pageFixtures<br/>(HomePage, LoginPage, Routes)"]
        F_API["apiFixtures<br/>(APIClient Helper)"]
        F_DATA["dataFactoryFixture<br/>(Zod Schemas, Synthetic Entity Lifecycle,<br/>Network Fault & Latency Simulation)"]
        F_A11Y["a11yFixture<br/>(AxeBuilder WCAG 2.2 AA Auditing)"]
        F_TEL["telemetryFixture<br/>(W3C Traceparent Header Injection)"]
        F_CONST["customFixtures<br/>(Application Constants)"]

        MERGE --> F_COM & F_PAGE & F_API & F_DATA & F_A11Y & F_TEL & F_CONST
    end

    subgraph "3. Application Runtime (Decoupled)"
        APP["Angular Application (src/)"]
        INTERCEPTOR["apiContractInterceptor<br/>(HTTP Interceptor + Zod safeParse<br/>Live Drift Telemetry)"]
        APP --> INTERCEPTOR
    end

    subgraph "4. CI/CD Matrix & Observability"
        CI_MATRIX["GitHub Actions Sharding<br/>(4 Shards Matrix Execution)"]
        BLOB_MERGE["Blob Report Aggregation"]
        DASHBOARD["Interactive HTML Dashboard<br/>+ P95 Metrics Recorder"]

        CI_MATRIX --> BLOB_MERGE --> DASHBOARD
    end

    CONFIG --> MERGE
    F_DATA -.->|"Validates Contracts"| INTERCEPTOR
    CONFIG --> CI_MATRIX

๐Ÿงฉ Architectural Pillars

1. Strict Source Decoupling (Rule 1)

E2E test suites (e2e/) remain completely isolated from application source code (src/). An ESLint no-restricted-imports rule is automatically injected to prevent leaking internal Angular implementations into test suites.

2. Component Object Model over BasePage Inheritance (Rule 2)

Avoid monolithic inheritance chains. UI widgets are encapsulated as standalone Component Objects and composed directly into fixtures:

import { test, expect } from '@fixtures/index';

test('verify user dashboard', { tag: ['@smoke', '@ui'] }, async ({ homePage, toastComponent }) => {
  await homePage.visit();
  await toastComponent.verifyNoFatalErrors();
});

3. Modular Fixture Slicing via mergeTests() (Rule 3)

Fixtures are sliced into focused domain concerns (componentFixtures, pageFixtures, apiFixtures, a11yFixture, dataFactoryFixture, telemetryFixture) and combined in @fixtures/index.

import { mergeTests } from '@playwright/test';
export const test = mergeTests(
  componentFixtures,
  pageFixtures,
  apiFixtures,
  a11yFixture,
  dataFactoryFixture,
  telemetryFixture
);

4. Pre-Cached Authentication (storageState) (Rule 4)

User authentication is executed once during global setup (auth.setup.ts) and cached to e2e/auth/default.json. Browser workers reuse this cached session instantly. Unauthenticated flows opt out with:

test.use({ storageState: { cookies: [], origins: [] } });

5. Cross-Platform Snapshot Consistency (Rule 5)

snapshotPathTemplate formats screenshots deterministically ({snapshotDir}/{arg}-{projectName}-{platform}{ext}), preventing visual mismatch failures across macOS local dev and Linux CI runners.

6. Angular HTTP Contract Interceptor (Rule 8)

An Angular HttpInterceptorFn validates all live HTTP responses against Zod schemas in real-time. Contract drifts are reported to browser console / telemetry without breaking the UI.


๐Ÿ› ๏ธ Command Reference

After running ng add ngx-playwright-schematics, your package.json includes:

ScriptCommandPurpose
npm run e2eng e2eFull E2E suite headless with auto-started dev server
npm run e2e:smokeplaywright test --grep @smokeP0 fast smoke suite for quick PR feedback
npm run e2e:regressionplaywright test --grep @regressionComplete regression test suite
npm run e2e:a11yplaywright test --grep @a11yAutomated WCAG 2.2 AA accessibility audit scans
npm run e2e:visualplaywright test --grep @visualVisual snapshot regression tests
npm run e2e:apiplaywright test --grep @apiZod API contract and fault resilience specs
npm run e2e:uiplaywright test --uiInteractive UI Mode with time-travel & DOM snapshots
npm run e2e:headedplaywright test --headedRun tests in a visible browser window
npm run e2e:debugplaywright test --debugStep-by-step Playwright Inspector debugging
npm run e2e:reportplaywright show-report artifacts/playwright-reportOpen Playwright HTML report
npm run allure:reportnpm run allure:generate && allure open ...Generate and view Allure report
npm run insights:alltsx scripts/...Record execution metrics, P95 duration, and build HTML dashboard
npm run lint:e2enpx eslint e2eEnforce E2E source decoupling guardrails

๐Ÿ“ Scaffolded File Tree

.
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ”œโ”€โ”€ e2e.yml                       # Pull request CI workflow
โ”‚       โ””โ”€โ”€ e2e-matrix.yml                # 4-shard matrix execution & report merger
โ”œโ”€โ”€ e2e/
โ”‚   โ”œโ”€โ”€ auth/
โ”‚   โ”‚   โ””โ”€โ”€ default.json                  # Pre-cached session storageState
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ header.component.ts           # Header / navbar widget
โ”‚   โ”‚   โ”œโ”€โ”€ loader.component.ts           # Loading spinners & progress bars
โ”‚   โ”‚   โ”œโ”€โ”€ modal.component.ts            # Dialog modals (role="dialog")
โ”‚   โ”‚   โ””โ”€โ”€ toast.component.ts            # Status toasts & alerts
โ”‚   โ”œโ”€โ”€ fixtures/
โ”‚   โ”‚   โ”œโ”€โ”€ a11yFixture.ts                # AxeBuilder accessibility fixture
โ”‚   โ”‚   โ”œโ”€โ”€ apiFixtures.ts                # API client fixture
โ”‚   โ”‚   โ”œโ”€โ”€ componentFixtures.ts          # COM widget fixtures
โ”‚   โ”‚   โ”œโ”€โ”€ constants.ts                  # App titles & timeouts
โ”‚   โ”‚   โ”œโ”€โ”€ creds.ts                      # Credentials manager
โ”‚   โ”‚   โ”œโ”€โ”€ dataFactoryFixture.ts         # Zod schemas, synthetic lifecycle, network faults
โ”‚   โ”‚   โ”œโ”€โ”€ fixtures.ts                   # Custom test data fixtures
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts                      # Unified mergeTests export
โ”‚   โ”‚   โ”œโ”€โ”€ pageFixtures.ts               # Page Object fixtures
โ”‚   โ”‚   โ””โ”€โ”€ telemetryFixture.ts           # W3C traceparent header injection
โ”‚   โ”œโ”€โ”€ global/
โ”‚   โ”‚   โ”œโ”€โ”€ global-setup.ts               # Global setup hook
โ”‚   โ”‚   โ””โ”€โ”€ global-teardown.ts            # Global teardown hook
โ”‚   โ”œโ”€โ”€ helpers/
โ”‚   โ”‚   โ”œโ”€โ”€ apiClient.ts                  # Isolated API client
โ”‚   โ”‚   โ””โ”€โ”€ utils.ts                      # Playwright helper utilities
โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”œโ”€โ”€ homePage.ts                   # Home Page Object
โ”‚   โ”‚   โ”œโ”€โ”€ loginPage.ts                  # Login Page Object
โ”‚   โ”‚   โ”œโ”€โ”€ routes.ts                     # Central route dictionary
โ”‚   โ”‚   โ””โ”€โ”€ testExtender.ts               # Test extender re-export
โ”‚   โ”œโ”€โ”€ specs/
โ”‚   โ”‚   โ”œโ”€โ”€ a11y.spec.ts                  # WCAG 2.2 AA accessibility spec
โ”‚   โ”‚   โ”œโ”€โ”€ api-contract.spec.ts          # Zod contract validation & fault specs
โ”‚   โ”‚   โ”œโ”€โ”€ app.spec.ts                   # Core application specs
โ”‚   โ”‚   โ”œโ”€โ”€ auth.setup.ts                 # Pre-cached authentication setup
โ”‚   โ”‚   โ””โ”€โ”€ visual.spec.ts                # Visual snapshot regression specs
โ”‚   โ””โ”€โ”€ tsconfig.json                     # E2E TypeScript paths configuration
โ”œโ”€โ”€ scripts/
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ””โ”€โ”€ parseResults.ts               # Playwright JSON report parser
โ”‚   โ”œโ”€โ”€ html-reporter.ts                  # Interactive HTML execution dashboard
โ”‚   โ”œโ”€โ”€ markdown-summary.ts               # GitHub step summary markdown report
โ”‚   โ”œโ”€โ”€ metrics-recorder.ts               # Daily test metrics & P95 duration recorder
โ”‚   โ””โ”€โ”€ tsconfig.json                     # Scripts TypeScript configuration
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ app/
โ”‚       โ””โ”€โ”€ core/
โ”‚           โ””โ”€โ”€ interceptors/
โ”‚               โ””โ”€โ”€ api-contract.interceptor.ts  # Angular HTTP Zod Contract Interceptor
โ”œโ”€โ”€ eslint.config.mjs                     # Decoupled ESLint configuration
โ””โ”€โ”€ playwright.config.ts                  # Enterprise Playwright configuration

๐Ÿ“„ License

Apache-2.0