An enterprise-grade Angular Schematics package that automates setting up and scaffolding a production-ready Playwright E2E testing architecture into any Angular application.
In any Angular project root directory, simply run:
ng add ngx-playwright-schematicsOr run via generator:
ng g ngx-playwright-schematics:ng-add| Option | Type | Default | Description |
|---|---|---|---|
--project |
string |
(default project) | Specific project name in angular.json |
--installBrowsers |
boolean |
false |
Automatically install Playwright browser binaries |
--overwrite |
boolean |
true |
Safely resolve conflicts and update existing configuration |
Example with options:
ng add ngx-playwright-schematics --project=my-app --installBrowsers=true --overwrite=trueWhen 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"])
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
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.
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();
});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
);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: [] } });snapshotPathTemplate formats screenshots deterministically ({snapshotDir}/{arg}-{projectName}-{platform}{ext}), preventing visual mismatch failures across macOS local dev and Linux CI runners.
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.
After running ng add ngx-playwright-schematics, your package.json includes:
| Script | Command | Purpose |
|---|---|---|
npm run e2e |
ng e2e |
Full E2E suite headless with auto-started dev server |
npm run e2e:smoke |
playwright test --grep @smoke |
P0 fast smoke suite for quick PR feedback |
npm run e2e:regression |
playwright test --grep @regression |
Complete regression test suite |
npm run e2e:a11y |
playwright test --grep @a11y |
Automated WCAG 2.2 AA accessibility audit scans |
npm run e2e:visual |
playwright test --grep @visual |
Visual snapshot regression tests |
npm run e2e:api |
playwright test --grep @api |
Zod API contract and fault resilience specs |
npm run e2e:ui |
playwright test --ui |
Interactive UI Mode with time-travel & DOM snapshots |
npm run e2e:headed |
playwright test --headed |
Run tests in a visible browser window |
npm run e2e:debug |
playwright test --debug |
Step-by-step Playwright Inspector debugging |
npm run e2e:report |
playwright show-report artifacts/playwright-report |
Open Playwright HTML report |
npm run allure:report |
npm run allure:generate && allure open ... |
Generate and view Allure report |
npm run insights:all |
tsx scripts/... |
Record execution metrics, P95 duration, and build HTML dashboard |
npm run lint:e2e |
npx eslint e2e |
Enforce E2E source decoupling guardrails |
.
βββ .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
Apache-2.0