This project is a Playwright + TypeScript automation framework designed for OrangeHRM UI coverage and enterprise-style API automation. It uses the Page Object Model with layered UI fixtures, a dedicated API client layer for Restful Booker, environment-aware configuration through dotenv, and Playwright project boundaries so UI and API suites can evolve independently.
- Node.js
- TypeScript
- Playwright Test (
@playwright/test) dotenvcrypto-jscross-env
tests/: UI and API test specspages/: Page Object Model classesfixtures/: Custom fixture layers and reusable test contextapi/: API clients, config, models, factories, and assertion helpersdata/: JSON test data filesenv-files/: Environment-specific.envfilesutils/: Shared utility classes
Fixture chain used in UI specs:
pom-fixtures->common-fixtures->hooks-fixture
Fixture chain used in API specs:
api-fixtures-> domain clients / domain contracts / workflows / shared HTTP assertions
Scalable API layout:
api/core/: cross-domain config, HTTP primitives, and generic assertionsapi/domains/<domain>/clients: endpoint clients for one domainapi/domains/<domain>/contracts: response shape and business contract assertionsapi/domains/<domain>/data: factories/builders for domain payloadsapi/domains/<domain>/services: reusable multi-step workflowstests/api/<domain>/...: specs grouped by business capability, not HTTP verb
This framework uses a project-dependency pattern for UI authentication:
SetupAuthproject runstests/ui/global-setup.spec.tschromiumproject depends onSetupAuth- Auth state is stored in
.auth/user.json
API auth for Restful Booker is handled by the API client layer using /auth token generation or centralized Basic Auth headers.
- Node.js LTS
- npm
- Playwright browser binaries
npm install
npx playwright installplaywright.config.ts loads env files based on ENV_NAME:
- If
ENV_NAMEis set, it loads./env-files/.env.<ENV_NAME> - If
ENV_NAMEis not set, it falls back to./env-files/.env.demo
Safe environment variable contract example:
BASE_URL=https://example-app-url
USERNAME=<encrypted-or-placeholder-username>
PASSWORD=<encrypted-or-placeholder-password>
API_BASE_URL=https://restful-booker.herokuapp.com
API_USERNAME=admin
API_PASSWORD=password123
API_REQUEST_TIMEOUT_MS=30000
SECRET_KEY=<secret-key>Run with environment selection:
ENV_NAME=demo npx playwright test --project=chromium
ENV_NAME=dev npx playwright testAvailable package scripts:
npm run test_dev
npm run test_demo_cr_hl
npm run test_demo_cr_hd
npm run test_last_failed
npm run test:api
npm run test:api:bookerUseful targeted runs:
npx playwright test tests/api/restful-booker --project=api
npx playwright test tests/api/restful-booker/auth/auth.spec.ts --project=api
npx playwright test tests/api/restful-booker/booking/booking.spec.ts --project=api
npx playwright test --grep "<tag>"Headed vs headless:
- Headed mode (
--headed) is useful for local debugging and observing UI behavior. - Headless mode is faster and better suited for CI and regular regression runs.
Current behavior from playwright.config.ts:
- List reporter in terminal and HTML report on disk
- Screenshot capture:
only-on-failure - Video capture:
retain-on-failure - Trace:
retain-on-failure
Useful rerun pattern for failed tests:
npm run test_last_failedThe API framework now centers on reusable abstractions instead of direct request calls inside specs.
Key components:
api/core/config/api-config.ts: central API environment contractapi/core/http/base-api-client.ts: typed request wrapper with shared timeout handlingapi/domains/restful-booker/clients/*.ts: Booker endpoint clientsapi/domains/restful-booker/contracts/*.ts: Booker response and contract validationapi/domains/restful-booker/data/*.ts: Booker payload buildersapi/domains/restful-booker/services/*.ts: Booker business workflowsapi/core/assertions/api-expect.ts: reusable HTTP-level assertionsfixtures/api-fixtures.ts: Playwright fixtures exposing the API layer to tests
Current API coverage includes:
- Fetch all bookings
- Fetch a booking by ID
- Create a booking
- Update a booking with token auth
- Update a booking with basic auth
- Negative auth validation
- Never commit real credentials, tokens, or decrypted secret values.
- Treat
.auth/user.jsonas sensitive session state and keep it local-only when possible. - Prefer environment variables over hardcoded credentials in test files.
- Avoid logging decrypted credentials in test output.
- Add deletion and cleanup flows if the target API starts enforcing test data quotas.
- Introduce schema validation tooling if you want full response contract enforcement against OpenAPI or JSON Schema.
- Add CI pipelines that split
@smoke,@regression, and@negativeAPI suites into separate jobs.