How eswarr11/playwright-ui-api works
Purpose and Entry Points
This is a TypeScript Playwright automation repository for two external systems: SauceDemo UI and FakeStoreAPI cart endpoints. Primary local entry points are npm scripts backed by Playwright configuration: playwright.config.ts and playwright.merge.config.ts. CI orchestration is centralized in .github/workflows/ci.yml.
Test Execution Architecture
Playwright Test is the common runner for UI and API suites, enabling shared tagging, sharding, results, and reporting. UI specs begin under ui/tests/; API specs begin under api/tests/carts/. The suite is split by Playwright projects/configuration rather than a deployed application runtime.
Key boundaries:
• Browser-driven SauceDemo workflows: ui/tests/, ui/pages/
• HTTP-driven FakeStoreAPI validation: api/tests/carts/, api/services/
• Cross-cutting runner fixtures and helpers: fixtures/ui.fixture.ts, helpers/
UI Page-Object Layer
SauceDemo interaction is encapsulated in page objects and reusable components. ui/pages/po-manager.ts provides test-facing page-object access; pages inherit common navigation/action behavior from ui/pages/base.page.ts. Domain pages model login, inventory, cart, product detail, and checkout stages, including ui/pages/inventory.page.ts, ui/pages/cart.page.ts, and ui/pages/checkout/step-one.page.ts.
Tests should consume page objects through the UI fixture rather than instantiate browser logic directly: fixtures/ui.fixture.ts.
UI Interaction and Workflow Boundary
helpers/pw-actions.ts is the enforced UI action abstraction: page objects store selector DSL strings and route clicks, fills, and assertions through this layer. This separates stable SauceDemo locator conventions from test intent. Shared multistep cart/checkout workflows are composed in ui/helpers/flow.helper.ts; reusable shell behavior is isolated in ui/components/header.component.ts and ui/components/burger-menu.component.ts.
The external UI dependency is SauceDemo/Swag Labs, executed in Chromium locally and in Playwright container infrastructure in CI.
API Client, Auth, and Contracts
The API layer wraps FakeStoreAPI through service classes: api/services/base.service.ts establishes common HTTP behavior, api/services/auth.service.ts obtains JWTs, and api/services/carts.service.ts performs cart CRUD. Shared Axios client/auth plumbing resides in helpers/api.client.ts and helpers/api-auth.util.ts.
Runtime response contracts are defined with Zod in api/schemas/cart.schema.ts. API tests validate endpoint behavior, authorization boundaries, input validation, and contract snapshots; committed baseline shape is at api/tests/carts/contract-snapshots/cart.snapshot.json.
Authentication and State Lifecycle
Before UI execution, global-setup.ts creates reusable Playwright storage-state sessions for SauceDemo user types; global-teardown.ts handles suite cleanup. This is a deliberate lifecycle boundary: authenticated UI tests reuse persisted browser state rather than each performing login. API authentication is per test/client path through JWT attachment.
Known third-party product defects are intentionally represented as expected failures via helpers/known-defects.helper.ts; this preserves correct assertions while preventing accepted upstream defects from failing CI.
Reporting and CI Pipeline
CI runs quality gates, authentication setup, then independently sharded API and UI test jobs. Report aggregation is a final stage in .github/workflows/ci.yml. Blob reports are merged by scripts/merge-playwright-report.js; Allure generation is handled by scripts/generate-allure-report.js.
Material infrastructure is GitHub Actions, Node 24 for non-browser stages, Java 17 for Allure aggregation, and mcr.microsoft.com/playwright:v1.61.1-noble for browser jobs. The pipeline produces combined Playwright HTML and Allure artifacts rather than deploying a service.
Main entry points: ci.yml GitHub Actions pipeline · playwright.config.ts Playwright configs · base.page.ts UI pages · carts.service.ts Cart service
Components 21
Execution & CI
- GitHub Actions pipeline · Runs gates, setup, sharded suites, and report aggregation.
.github/workflows/ci.yml - Playwright configs
playwright.config.ts - Report merge config
playwright.merge.config.ts - UI session setup · Creates reusable SauceDemo storage states.
global-setup.ts - Suite teardown
global-teardown.ts
UI Automation
- UI specs
- UI fixture · Supplies tests with page-object access.
fixtures/ui.fixture.ts - Page-object manager
ui/pages/po-manager.ts - UI pages · Base, inventory, cart, and checkout page models.
ui/pages/base.page.ts - Cart checkout flows
ui/helpers/flow.helper.ts - SauceDemo · Browser-driven Swag Labs dependency.
API Automation
- Cart API specs
- Cart service · Performs FakeStoreAPI cart CRUD.
api/services/carts.service.ts - Auth service · Obtains JWTs for API requests.
api/services/auth.service.ts - Cart Zod contract
api/schemas/cart.schema.ts - Cart contract baseline
api/tests/carts/contract-snapshots/cart.snapshot.json - FakeStoreAPI
Shared Runtime
- UI action DSL · Routes locator-based clicks, fills, and assertions.
helpers/pw-actions.ts - Axios auth client · Shared request and JWT attachment plumbing.
helpers/api.client.ts
Reports
- Blob report merge
scripts/merge-playwright-report.js - Allure generation
scripts/generate-allure-report.js
Connections 21
- GitHub Actions pipeline → Playwright configs: runs suites with
- GitHub Actions pipeline → UI session setup: runs before UI
- GitHub Actions pipeline → Suite teardown: runs after suites
- Playwright configs → UI specs: selects projects
- Playwright configs → Cart API specs: selects projects
- UI session setup → SauceDemo: creates storage state from
- UI specs → UI fixture: uses
- UI fixture → Page-object manager: provides
- Page-object manager → UI pages: accesses
- UI pages → UI action DSL: uses
- Cart checkout flows → Page-object manager: composes
- UI pages → SauceDemo: drives browser workflows
- Cart API specs → Cart service: exercises
- Cart service → Auth service: uses authentication
- Cart service → Axios auth client: sends requests through
- Axios auth client → FakeStoreAPI: calls
- Cart API specs → Cart Zod contract: validates responses with
- Cart API specs → Cart contract baseline: compares against
- GitHub Actions pipeline → Blob report merge: aggregates shard reports
- Report merge config → Blob report merge: configures
- Blob report merge → Allure generation: feeds combined results