How shamapar/playwright-api-test-framework works
Project type and purpose
• This is an API Automation Test Framework built on Playwright. Its sole purpose is to define, execute, and report API tests against any HTTP-based service. It is not a user-facing frontend or a backend service—it’s a test automation tool.
File structure
• Top level
• package.json / package-lock.json / eslint.config.mjs – node project metadata, lint rules
• playwright.config.ts – Playwright test runner configuration
• readme.md – usage instructions
• tests folder
• config/env.ts – environment and global settings (base URLs, auth tokens)
• helper/utility.ts – shared helper functions (request builders, response parsers)
• interface/page.ts – TypeScript interfaces or request payload schemas (e.g., User objects)
• pages/*.json – sample payloads or fixture data
• specs/*.spec.ts – individual test suites for GET, POST, PUT, PATCH, DELETE operations
• testData/userData.ts – structured test data (valid/invalid users)
README for additional insights
• Shows prerequisites (NodeJS, VS Code) and commands to install (npm install) and run tests (npx playwright test)
• References external JWT/OAuth token tutorials—framework likely supports secured endpoints
Main components and their relationships
a. Test Runner (Playwright CLI)
• Entry point: playwright.config.ts → loads global settings and test project definitions
b. Configuration Module
• env.ts provides baseURL, headers, authentication token logic
c. Test Spec Suites
• One suite per HTTP verb (get.spec.ts, post.spec.ts, etc.)
• Each imports testData, interfaces, utilities, and calls utility.request(…)
d. Helper/Utility Layer
• Builds HTTP requests, injects headers/payloads, parses responses, centralizes common assertions
e. Interface/Schema Definitions
• Type-safe definitions of request/response objects to ensure consistency
f. Test Data Module
• Houses reusable payloads and parameter sets for positive/negative tests
g. Reporting & CI Integration
• Playwright’s built-in HTML reporter, can be wired into pipelines (not shown in file tree)
h. External Service Under Test
Data flow:
1. Runner reads playwright.config.ts → loads env.ts
2. For each spec file
• Loads testData & interface definitions
• Calls helper.utility to construct and send HTTP requests to the API under test
• Receives responses → asserts against expected schema/values
3. Aggregated results → Playwright reporter → console/HTML output
Architectural patterns & design principles
• Separation of concerns: config vs. data vs. test logic vs. utilities
• Page-Object/Interface pattern repurposed for API payloads and responses
• DRY: shared utilities abstract common HTTP operations
• Type safety: interfaces ensure payload correctness