A clean and scalable API Test Automation Framework built with Playwright + TypeScript.
This framework is designed for modern API testing with reusable utilities, clean project structure, and maintainable test code.
It includes:
- Custom fixtures
- Reusable request handler
- Token-based authentication
- Custom assertions
- Request / Response logging
- Schema validation
- Environment-based configuration
- Playwright HTML reporting
git clone https://github.com/sharisroy/playwright-ts-framework.git
cd playwright-ts-frameworknpm installnpx playwright installnpx playwright testnpx playwright show-reportplaywright-ts-framework/
│── tests/
│ ├── smokeTest.spec.ts # Main reusable API tests
│ └── basic_requests.spec.ts # Basic API examples
│
│── utils/
│ ├── fixtures.ts # Custom fixtures
│ ├── request_handler.ts # Reusable API methods
│ ├── logger.ts # Request/Response logs
│ ├── schema-validator.ts # Schema validator
│ └── coustom_expect.ts # Custom assertions
│
│── helpers/
│ └── createToken.ts # Auto auth token
│
│── response-schemas/ # JSON schema files
│
│── playwright.config.ts
│── api-test.config.ts
│── package.json
│── README.mdSupports:
- GET
- POST
- PUT
- DELETE
Example:
await api
.path('/articles')
.params({ limit: 10 })
.getRequest(200);Validate API responses using JSON Schema.
npm install ajv --save-dev
npm i genson-js --save-devawait expect(response).shouldMatchSchema('articles', 'GET_articles', true);
await expect(createArticleResponse).shouldMatchSchema('articles', 'POST_article', true);
await expect(createArticleResponse).shouldMatchSchema('articles', 'POST_article');- Use
trueonly when generating schema for the first time. - After schema file is created, remove
true.
await expect(response).shouldMatchSchema('articles', 'GET_articles');If any test fails, logs include:
- URL
- Headers
- Body
- Response
- Status Code
This makes debugging faster and easier.
npx playwright testnpx playwright test --project smoke-testsnpx playwright test tests/smokeTest.spec.tsnpx playwright test -g "Get Articles"npx playwright test --last-failedTEST_ENV=staging npx playwright testAfter execution:
npx playwright show-reportEach test should run separately.
Avoid duplicate code.
Always verify:
- Status code
- Response body
- Schema
Do not hardcode credentials.
You can extend this framework with:
- UI Automation
- Database Validation
- CI/CD Integration
- Allure Reports
- Parallel Execution
- Data Driven Testing
This project is beginner-friendly and suitable for learning:
- Playwright API Testing
- TypeScript Framework Design
- Scalable Automation Framework
- Schema Validation
Haris Chandra Roy
GitHub: https://github.com/sharisroy
If you find this project useful, give it a ⭐ on GitHub.