Skip to content

Repository files navigation

Swagger Petstore API Automation Framework

CI

A robust, modular, and maintainable backend API automation testing suite built with Native Playwright API Request (@playwright/test) and TypeScript, targeting the Swagger Petstore API.

This framework strictly follows Clean Code (DRY) principles by decoupling data generators into domain-driven modules, supporting Data & Token Chaining, and covering both positive and negative API scenarios.

Key Features

  • Native Playwright Execution: Leverages Playwright's built-in request context for lightning-fast API test execution without extra dependencies like Axios or Supertest.

  • Domain-Driven Modular Data: Separated interface types and data factory generators into data/*.data.ts (user.data.ts, pet.data.ts, store.data.ts).

  • Token & Data Chaining: Extracts session keys and entity IDs dynamically from responses to pass across sequential request flows.

  • Comprehensive Test Scenarios: Covers complete CRUD operations, inventory management, batch processing, and negative edge cases (400 Bad Request, 404 Not Found).

  • Interactive HTML Reports: Built-in Playwright HTML reporting with full request/response payload logs.

  • CI/CD Ready: Configured for automated execution via GitHub Actions workflows.

Project Directory Structure

petstore-playwright-api-native/
├── .github/
│   └── workflows/
│       └── playwright.yml       # CI/CD pipeline configuration
├── data/                        # Domain-Driven Data Generators & Interfaces
│   ├── user.data.ts             # User payload schemas & factories
│   ├── pet.data.ts              # Pet payload schemas & factories
│   └── store.data.ts            # Store Order payload schemas & factories
├── tests/                       # Playwright Test Spec Suites
|   ├── pet.spec.ts              # Pet management module tests (/pet)
│   ├── user.spec.ts             # User management module tests (/user)
│   ├── store.spec.ts            # Store & order module tests (/store)
│   └── petstore.spec.ts         # Pet lifecycle & authentication end-to-end tests
├── .env                         # Local environment variables (Git ignored)
├── .env.example                 # Environment variables template
├── .gitignore
├── package.json                 # Project dependencies & script shortcuts
├── playwright.config.ts         # Playwright runner configuration
├── tsconfig.json                # TypeScript compiler settings
└── README.md                    # Project documentation

Getting Started

Prerequisites

  • Node.js: v18.x or higher
  • npm: v9.x or higher

Installation

  1. Clone the repository:

    git clone https://github.com/fasyauliuli/petstore-playwright-api-native
    cd petstore-playwright-api-native
  2. Install dependencies:

    npm install
  3. Configure Environment Variables: Duplicate .env.example and save it as .env:

    cp .env.example .env

    Verify your .env contains:

    BASE_URL=https://petstore.swagger.io/v2
    USER_NAME=qa_automation_user
    USER_PASSWORD=password123

Running the Tests

Action Command
Run All API Tests npm run test:api
Run Tests in UI Mode npx playwright test --ui
Run Specific Test File npx playwright test tests/user.spec.ts
Open HTML Test Report npm run test:ui-report

Reporting & Notifications

HTML Report

Interactive Playwright HTML report generated after every test execution.

HTML Report

GitHub Actions Pipeline

Automated API test execution on every push and pull request.

GitHub Actions

Discord Notification

Test result notification sent automatically to Discord after CI execution.

Discord Notification

API Test Coverage Summary

1. User Management Module (/user)

  • POST /user - Single user creation.
  • POST /user/createWithList - Batch user array creation.
  • GET /user/login - Authenticate user & capture dynamic api_key.
  • GET /user/{username} - Fetch user details by username.
  • PUT /user/{username} - Update user profile information.
  • DELETE /user/{username} - Delete user profile.
  • GET /user/logout - Invalidate active session.
  • Negative Scenarios: Validate 404 Not Found for non-existent users.

2. Store Module (/store)

  • GET /store/inventory - Fetch pet inventory status counts.
  • POST /store/order - Place a new pet purchase order.
  • GET /store/order/{orderId} - Retrieve purchase order details.
  • DELETE /store/order/{orderId} - Cancel and delete order.
  • Negative Scenarios: Validate 400 Bad Request for string order IDs and 404 Not Found for out-of-range IDs.

3. Pet Module (/pet)

  • POST /pet - Create a new pet entry.
  • GET /pet/{petId} - Fetch pet details by numeric ID.
  • PUT /pet - Update pet status (available -> sold).
  • DELETE /pet/{petId} - Remove pet entry.
  • Negative Scenarios: Validate 400 Bad Request for invalid non-integer IDs and 404 Not Found for missing pets.

Important Note on Swagger Petstore Server Behavior

Please note that the target host (petstore.swagger.io) is a public mock server. Certain backend business logic validations (such as duplicate user prevention or strict password authentication) are intentionally bypassed by the server, returning 200 OK.

Negative scenario test cases in this framework explicitly target endpoints with strict backend validation contracts (such as path parameter format validation and missing database key lookups returning 400 Bad Request and 404 Not Found).

License

Distributed under the MIT License.

About

Native Playwright (@playwright/test) & TypeScript API automation framework for Swagger Petstore API with data chaining and Clean Code architecture.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages