A clean, maintainable, and beginner-friendly API testing framework using Playwright, TypeScript, and Allure reports. This project demonstrates good practices for API testing, including schema validation, response verification, clear reporting, and robust design patterns.
- Simple, readable code: Minimal boilerplate, clear arrange/act/assert pattern
- Easy to maintain: Add new endpoints and tests with simple helpers
- Beginner-friendly: Intuitive structure and clear documentation
- Abstraction for readability: Common API actions are in helpers
- Comprehensive reporting: Allure reports with history and stack traces
- Best practices: Schema validation, negative/edge case tests, secure token management
This framework follows several proven design patterns:
- Page Object Pattern (API version): API helpers encapsulate endpoint interactions
- Factory Pattern: Test data generation with faker.js
- AAA Pattern: Arrange-Act-Assert structure in all tests
- Builder Pattern: Flexible test data creation
- Singleton Pattern: Configuration management
- Strategy Pattern: Different validation approaches for different endpoints
src/
├── api/ # API client abstractions
├── config/ # Configuration management
├── constants/ # Application constants
├── schemas/ # JSON schemas for validation
├── tests/ # Test specifications
├── types/ # TypeScript interfaces
└── utils/ # Helper functions and factories
- Clone the repository
git clone https://github.com/don-peters/playwright-api-framework.git cd playwright-api-framework - Install dependencies
npm install
- Set up your GoRest API token
- Copy
.env.exampleto.env - Add your token to
.env:GOREST_TOKEN=your_gorest_token_here
- Copy
- Run all tests:
npm run test - Run tests and generate Allure report (with history):
npm run test:report
- Generate Allure report only:
npm run report:generate
- Open the Allure report:
npm run report:open
- Clean Allure results and reports:
npm run report:clean
src/
api/ # API client abstraction
schemas/ # JSON schema definitions
tests/ # Test files (CRUD, negative, edge cases)
utils/ # Helpers (API actions, schema validation)
.env.example # Example environment file
README.md # Project documentation
// Example: Validate all users in GET /users
const response = await getUserList(request, token);
const users = await response.json();
for (const user of users) {
const { valid, errors } = validateSchema(userSchema, user);
expect(valid, `Schema errors: ${JSON.stringify(errors)}`).toBe(true);
}- CRUD operations: Create, update, delete users
- Negative & edge cases: Invalid data, duplicate emails, missing fields, unauthorized requests
- Schema validation: Ajv with formats for strict response checks
- Helpers: All API actions abstracted for clean specs
- Allure reporting: History/trends, stack traces, clear pass/fail
- Grouping/filtering is done using supported labels:
feature,epic,story,tag, andseverity(notcategory). - Example annotation usage:
test('should return a valid user', { annotation: [ { type: 'feature', description: 'Get User By ID' }, { type: 'epic', description: 'User API' }, { type: 'tag', description: 'Get User' } ] }, async ({ request }) => { // ...test code... });
- Grouping/filtering is done using supported labels:
- Node.js
- npm
- GoRest API token
Pull requests and suggestions are welcome! Please open an issue or PR for improvements.
For more details, see the example tests in src/tests/.