Skip to content

don-peters/playwright-api-framework

Repository files navigation

Playwright API Testing Framework

Playwright TypeScript Allure

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.


✨ Features & Design Principles

  • 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

🏗️ Architecture & Design Patterns

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

Project Structure

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

🚀 Getting Started

  1. Clone the repository
    git clone https://github.com/don-peters/playwright-api-framework.git
    cd playwright-api-framework
  2. Install dependencies
    npm install
  3. Set up your GoRest API token
    • Copy .env.example to .env
    • Add your token to .env:
      GOREST_TOKEN=your_gorest_token_here
      

🧪 Running Tests & Generating Reports

  • 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

🗂️ Project Structure

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 Usage

// 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);
}

📋 Included Test Patterns

  • 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, and severity (not category).
    • 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...
      });

🛡️ Requirements

  • Node.js
  • npm
  • GoRest API token

🤝 Contributing

Pull requests and suggestions are welcome! Please open an issue or PR for improvements.


📚 References


For more details, see the example tests in src/tests/.

About

API testing using Playwright

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published