Below is a production-quality, well-structured README.md you can use directly in your repository. It’s written to be clear for newcomers, credible for senior engineers, and useful for CI / long-term maintenance.
Playwright + Cucumber + TypeScript
This project is a scalable and maintainable API test automation framework built using:
- Playwright – fast, reliable HTTP client & test runner
- Cucumber (BDD) – business-readable tests with Gherkin
- TypeScript – strong typing, better refactoring, fewer runtime errors
The framework is designed with clean architecture principles, focusing on:
- Separation of concerns
- Reusability
- Readability
- Easy onboarding for both technical and non-technical stakeholders
- BDD-first approach: Business scenarios are written in Gherkin
- Service-based API abstraction: API logic lives in service classes
- Centralized API client: Headers, auth, retries handled in one place
- Typed models: Request & response objects are strongly typed
- Environment-driven: Easy switching between Dev / Test / UAT
| Tool | Purpose |
|---|---|
| Playwright | API request handling & assertions |
| Cucumber | BDD / Gherkin test definitions |
| TypeScript | Type safety & maintainability |
| Node.js | Runtime |
| ts-node | TypeScript execution |
| AJV / Zod (optional) | Schema validation |
| CI/CD | Jenkins / GitHub Actions compatible |
api-test-framework/
│
├── src/
│ ├── config/ # Environment & endpoint configuration
│ ├── core/ # Framework core (API client, context, hooks)
│ ├── features/ # Gherkin feature files & step definitions
│ ├── models/ # Typed request/response models
│ ├── services/ # API business logic layer
│ ├── utils/ # Reusable helpers & utilities
│ └── types/ # Custom TypeScript types
│
├── test-data/ # Static test data (JSON)
├── reports/ # Test execution reports
├── cucumber.js # Cucumber configuration
├── tsconfig.json # TypeScript configuration
├── package.json # Dependencies & scripts
└── README.md
Feature (Gherkin)
↓
Step Definitions
↓
Service Layer (Business API Logic)
↓
API Client (Playwright)
↓
HTTP Request
-
Feature files → Describe what is being tested
-
Step Definitions → Glue code only, no API logic
-
Services → Encapsulate API calls and endpoints
-
Core → Authentication, request context, hooks
-
Utils → Common reusable helpers (logging, validation, data handling)
- Node.js v18+
- npm or yarn
- Access to target API environments
npm installSet environment variables:
export BASE_URL=https://api.dev.example.com
export API_TOKEN=your-tokenOr use .env file if supported.
Run all API tests:
npm testRun a specific feature:
npx cucumber-js src/features/user/user.featureFeature: User API
Scenario: Create a new user
Given I have a valid user payload
When I send a create user request
Then the response status should be 201✅ Keep steps thin ❌ Do not call Playwright directly in steps ✅ Always delegate to services
export class UserService {
constructor(private api: ApiClient) {}
createUser(payload: User) {
return this.api.post('/users', payload);
}
}- HTTP status checks
- Response body validation
- Optional schema validation (AJV / Zod)
- Custom reusable validators
-
Token-based authentication supported
-
Centralized in
authHelper -
Easy to extend for:
- OAuth2
- JWT refresh
- API keys
-
Cucumber HTML reports
-
Easily extendable to:
- Allure
- JSON reports
- CI dashboards
Reports are generated under:
reports/
The framework is designed to run seamlessly in:
- Jenkins
- GitHub Actions
- GitLab CI
Supports:
- Headless execution
- Parallel runs
- Environment-based configuration
✔ Clean architecture ✔ DRY principles ✔ Typed API contracts ✔ Centralized configuration ✔ Easy scalability ✔ CI-friendly execution
Planned improvements:
- 🔹 OAuth token refresh support
- 🔹 API schema contract testing
- 🔹 Allure reporting
- 🔹 Performance assertions
- 🔹 Test data generation
- 🔹 AI-assisted test creation
- Follow existing folder structure
- Add services for new APIs
- Keep step definitions minimal
- Write meaningful Gherkin scenarios
- Ensure tests are environment-agnostic
This project is intended for internal / enterprise use. License can be defined based on organizational needs.
For questions or improvements:
- Contact the QA / Automation team
- Raise an issue or pull request