Skip to content

GeorgiDrumev/Playwright-API-tests

Repository files navigation

Playwright API Automation — Mockerito Education API

End-to-end API automation suite for the Mockerito Education sandbox, covering all CRUD endpoints across 7 resource groups.

Tech stack

Tool Purpose
@playwright/test Test runner + APIRequestContext for HTTP
Zod Schema definition and runtime response validation
@faker-js/faker Deterministic random test data generation
TypeScript Static typing throughout all layers
Prettier Consistent code formatting
Husky Git pre-commit hook — runs Prettier via lint-staged
lint-staged Runs Prettier only on staged files

Architecture

The project follows a strict layered architecture — each layer has a single responsibility:

dtos/          Zod schemas + inferred TypeScript types (one file per resource)
factories/     Static factory classes — build() / buildMany() / buildUpdate() for test payloads
utils/         Shared utilities (HttpClient with 429 retry, sleep)
services/      One class per endpoint group — wraps HttpClient, returns APIResponse
fixtures/      Playwright fixture files — lifecycle management (create → use → cleanup)
tests/         Spec files — Given / When / Then via test.step()

Layer rules

  • DTOs define the shape via Zod; types are always inferred (z.infer<>)
  • Services accept HttpClient (injected) and expose one method per endpoint
  • HttpClient automatically retries on 429 Too Many Requests (exponential backoff, 3 attempts)
  • Fixtures compose via .extend()enrollment.fixtures extends student.fixtures so createdStudent is inherited; submission.fixtures extends enrollment.fixtures
  • Tests always use Given / When / Then steps; the HTTP call is always visible in the When step

Resources covered

Resource Tests Notes
Auth 2 Login success + invalid credentials
Assignments 9 Full CRUD + types list + submissions sub-resource
Courses 10 Full CRUD + categories/levels lists + search
Teachers 9 Full CRUD + specializations list + courses sub-resource
Users 7 Full CRUD
Students Full CRUD service, DTO, factory, and fixture implemented; spec file pending
Enrollments 9 Full CRUD + statuses list
Submissions 9 Full CRUD + grade endpoint + statuses list

Total: 55 tests

Setup

npm install
npx playwright install

Running tests

# Full suite
npm test

# Re-run only the last-failed tests (fastest feedback after a fix)
npm run test:failed

# Interactive debug mode — Playwright Inspector opens before each request
npm run test:debug

# Open the HTML report with traces for failed tests
npm run report

The sandbox enforces a rate limit. Tests run with --workers=1 and HttpClient retries 429 responses automatically with exponential backoff.

Formatting

npm run format        # fix
npm run format:check  # check only (CI)

A pre-commit hook (Husky + lint-staged) automatically formats staged .ts, .json, and .md files before every commit.

CI / CD

GitHub Actions runs the full test suite on every push to git branch -M main and every pull request.

Pipeline steps:

  1. Install dependencies with npm ci
  2. Run npm test against the live Mockerito sandbox
  3. Upload the Playwright HTML report as a build artifact (retained 30 days)
  4. Deploy the HTML report to GitHub Pages on every master push

View the latest test report: GitHub Pages report (enable Pages under Settings → Pages → Source → GitHub Actions to activate)

Workflow file: .github/workflows/playwright.yml

About

Playwright TypeScript API test suite - full CRUD coverage with Zod schema validation, factory-based test data, and GitHub Actions CI/CD.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors