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.
-
Native Playwright Execution: Leverages Playwright's built-in
requestcontext 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.
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
- Node.js:
v18.xor higher - npm:
v9.xor higher
-
Clone the repository:
git clone https://github.com/fasyauliuli/petstore-playwright-api-native cd petstore-playwright-api-native -
Install dependencies:
npm install
-
Configure Environment Variables: Duplicate
.env.exampleand save it as.env:cp .env.example .env
Verify your
.envcontains:BASE_URL=https://petstore.swagger.io/v2 USER_NAME=qa_automation_user USER_PASSWORD=password123
| 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 |
Interactive Playwright HTML report generated after every test execution.
Automated API test execution on every push and pull request.
Test result notification sent automatically to Discord after CI execution.
POST /user- Single user creation.POST /user/createWithList- Batch user array creation.GET /user/login- Authenticate user & capture dynamicapi_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 Foundfor non-existent users.
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 Requestfor string order IDs and404 Not Foundfor out-of-range IDs.
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 Requestfor invalid non-integer IDs and404 Not Foundfor missing pets.
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).
Distributed under the MIT License.


