API Playwright Test Developer
Vendor skill (source: jaktestowac-awesome-copilot-for-testers). Imported 2026-05-31.
This skill defines the standard approach for writing and maintaining Playwright-based API tests. It is optimized for robust, repeatable automated validation of REST/GraphQL services, readable test design, and minimal flakiness.
When to use
- API endpoint functional testing (status, schema, body values)
- Data-driven regression coverage across all environments
- Contract checks (OpenAPI/JSON Schema) for service evolution
- End-to-end test flows mixing UI and API interactions (hybrid tests)
- CI pipeline smoke tests and API health checks
Core principles
- Explicit setup/teardown
- Use
test.beforeEach and test.afterEach for consistent test state management (e.g., create/delete test data).
- Avoid shared mutable state across tests to prevent flakiness.
- Use unique identifiers in test data to avoid collisions and ensure idempotency.
- Dont clean up test data in
afterEach so that you can inspect it after test failures.
- Single responsibility per test case
- Each test should target one behavior (e.g., 200 vs 401, field validation, paginated listing).
- Use descriptive test titles to clarify the intent and expected outcome.
- For complex scenarios, break down into multiple focused tests rather than one large test with many assertions.
- When testing e2e flows, consider using
test.step to logically group related API calls and assertions within a single test case.
- Assertions
- Avoid brittle tests that rely on dynamic timestamps or ordering unless controlled.
- Add descriptive messages to assertions for easier debugging.
- Use soft assertions
expect.soft for multiple checks in a single test without stopping at the first failure.
- Clear data management
- Use fixtures/config to store base URL, auth tokens, test payload templates.
- Use factory functions to generate test data with unique identifiers.
- Avoid hardcoding environment-specific values in tests; use environment variables or config files.
- For complex data setup, consider using API calls in
beforeEach to create necessary resources instead of relying on static test data.
- Patterns and best practices
- Use
request fixture for API calls.
- Use AAA pattern (Arrange-Act-Assert) for test structure.
- Use builders or factories for constructing request payloads to improve readability and maintainability.
- Use Simple Request Object Pattern to encapsulate API interactions and reduce duplication across tests.
- Use
test.describe to group related tests and share setup/teardown logic.
Recommended folder layout
.
├── tests/
│ ├── api/
│ │ ├── users.spec.ts
│ │ ├── auth.spec.ts
│ │ ├── orders.spec.ts
│ │ └── contracts.spec.ts
│ ├── e2e/
│ │ ├── signup-and-purchase.spec.ts
│ │ └── checkout-api-ui.spec.ts
│ └── fixtures/
│ ├── api-fixtures.ts
│ ├── data-fixtures.ts
│ └── auth-fixtures.ts
├── playwright.config.ts
├── .env.example
├── helpers/
│ ├── api-helpers.ts
│ ├── schema-validators.ts
│ └── retry-utils.ts
├── data/
│ └── payloads/
│ ├── create-user.json
│ ├── update-order.json
│ └── login.json
└── docs/
└── api-test-guidelines.md
tests/api/: dedicated API service tests and contract/spec tests.
tests/e2e/: hybrid scenarios that combine UI and API flows.
tests/fixtures/: setup data and auth fixtures for Playwright Test.
helpers/: reusable request builders, response assertions, schema validators.
data/payloads/: canonical test payloads to avoid inline duplication.
.env.example: environment abstraction for endpoints and tokens.
.github/workflows/api-tests.yml: CI pipeline orchestration with separate API test job.
Playwright Test Example (TypeScript)
import { test, expect } from '@playwright/test';
test.describe('API: /users', () => {
test('GET /users returns 200 and JSON schema', async ({ request }) => {
const response = await request.get('/api/users', {
headers: { Authorization: `Bearer ${process.env.API_TOKEN}` },
});
expect(response.status()).toBe(200);
expect(response.headers()['content-type']).toContain('application/json');
const body = await response.json();
expect(Array.isArray(body)).toBeTruthy();
expect(body.length).toBeGreaterThanOrEqual(0);
});
});
Common patterns
request.get, request.post, request.put, request.delete
- HTTP retries for transient 5xx responses (in test infrastructure, not per-test)
- Data-driven tests using
test.each or test.describe.parallel
- Auth token refresh helpers and failures when invalid credentials are used
- Validate headers
cache-control, strict-transport-security, etc. for security tests
Hybrid API+UI scenario
- Authenticate with API:
POST /auth/login → token
- Set browser storage/cookie in Playwright page context
- Visit protected UI page to assert data mirrored from API
- Modify resource via API, then confirm UI updates (or vice versa)
Troubleshooting guide
- 401/403: verify token scope, environment URL, and clock skew
- 404: confirm route path and version (
/v1, /v2), check mock intercepts
- Timeout: increase
timeout in request and page.waitForResponse with precise matcher
- Flakiness: isolate side effects, use dedicated test data, run service health checks before suite
Best practices checklist
References
1---2name: api-playwright-test-developer3description: Writes and reviews API automation tests with Playwright. Use when creating backend API tests, contract checks, data-driven assertions, or API+UI hybrid workflows in Playwright Test. Focus on robust, maintainable test design with clear setup/teardown, single responsibility per test, and best practices for assertions and data management.4---56# API Playwright Test Developer78> _Vendor skill (source: jaktestowac-awesome-copilot-for-testers). Imported 2026-05-31._910This skill defines the standard approach for writing and maintaining Playwright-based API tests. It is optimized for robust, repeatable automated validation of REST/GraphQL services, readable test design, and minimal flakiness.1112## When to use1314- API endpoint functional testing (status, schema, body values)15- Data-driven regression coverage across all environments16- Contract checks (OpenAPI/JSON Schema) for service evolution17- End-to-end test flows mixing UI and API interactions (hybrid tests)18- CI pipeline smoke tests and API health checks1920## Core principles21221. Explicit setup/teardown23 - Use `test.beforeEach` and `test.afterEach` for consistent test state management (e.g., create/delete test data).24 - Avoid shared mutable state across tests to prevent flakiness.25 - Use unique identifiers in test data to avoid collisions and ensure idempotency.26 - Dont clean up test data in `afterEach` so that you can inspect it after test failures.272. Single responsibility per test case28 - Each test should target one behavior (e.g., 200 vs 401, field validation, paginated listing).29 - Use descriptive test titles to clarify the intent and expected outcome.30 - For complex scenarios, break down into multiple focused tests rather than one large test with many assertions.31 - When testing e2e flows, consider using `test.step` to logically group related API calls and assertions within a single test case.323. Assertions33 - Avoid brittle tests that rely on dynamic timestamps or ordering unless controlled.34 - Add descriptive messages to assertions for easier debugging.35 - Use soft assertions `expect.soft` for multiple checks in a single test without stopping at the first failure.364. Clear data management37 - Use fixtures/config to store base URL, auth tokens, test payload templates.38 - Use factory functions to generate test data with unique identifiers.39 - Avoid hardcoding environment-specific values in tests; use environment variables or config files.40 - For complex data setup, consider using API calls in `beforeEach` to create necessary resources instead of relying on static test data.415. Patterns and best practices42 - Use `request` fixture for API calls.43 - Use AAA pattern (Arrange-Act-Assert) for test structure.44 - Use builders or factories for constructing request payloads to improve readability and maintainability.45 - Use Simple Request Object Pattern to encapsulate API interactions and reduce duplication across tests.46 - Use `test.describe` to group related tests and share setup/teardown logic.4748## Recommended folder layout4950```51.52├── tests/53│ ├── api/54│ │ ├── users.spec.ts55│ │ ├── auth.spec.ts56│ │ ├── orders.spec.ts57│ │ └── contracts.spec.ts58│ ├── e2e/59│ │ ├── signup-and-purchase.spec.ts60│ │ └── checkout-api-ui.spec.ts61│ └── fixtures/62│ ├── api-fixtures.ts63│ ├── data-fixtures.ts64│ └── auth-fixtures.ts65├── playwright.config.ts66├── .env.example67├── helpers/68│ ├── api-helpers.ts69│ ├── schema-validators.ts70│ └── retry-utils.ts71├── data/72│ └── payloads/73│ ├── create-user.json74│ ├── update-order.json75│ └── login.json76└── docs/77 └── api-test-guidelines.md78```7980- `tests/api/`: dedicated API service tests and contract/spec tests.81- `tests/e2e/`: hybrid scenarios that combine UI and API flows.82- `tests/fixtures/`: setup data and auth fixtures for Playwright Test.83- `helpers/`: reusable request builders, response assertions, schema validators.84- `data/payloads/`: canonical test payloads to avoid inline duplication.85- `.env.example`: environment abstraction for endpoints and tokens.86- `.github/workflows/api-tests.yml`: CI pipeline orchestration with separate API test job.878889## Playwright Test Example (TypeScript)9091```ts92import { test, expect } from '@playwright/test';9394test.describe('API: /users', () => {95 test('GET /users returns 200 and JSON schema', async ({ request }) => {96 const response = await request.get('/api/users', {97 headers: { Authorization: `Bearer ${process.env.API_TOKEN}` },98 });99100 expect(response.status()).toBe(200);101 expect(response.headers()['content-type']).toContain('application/json');102103 const body = await response.json();104 expect(Array.isArray(body)).toBeTruthy();105 expect(body.length).toBeGreaterThanOrEqual(0);106 });107});108```109110## Common patterns111112- `request.get`, `request.post`, `request.put`, `request.delete`113- HTTP retries for transient 5xx responses (in test infrastructure, not per-test)114- Data-driven tests using `test.each` or `test.describe.parallel`115- Auth token refresh helpers and failures when invalid credentials are used116- Validate headers `cache-control`, `strict-transport-security`, etc. for security tests117118## Hybrid API+UI scenario1191201. Authenticate with API: `POST /auth/login` → token1212. Set browser storage/cookie in Playwright page context1223. Visit protected UI page to assert data mirrored from API1234. Modify resource via API, then confirm UI updates (or vice versa)124125## Troubleshooting guide126127- 401/403: verify token scope, environment URL, and clock skew128- 404: confirm route path and version (`/v1`, `/v2`), check mock intercepts129- Timeout: increase `timeout` in `request` and `page.waitForResponse` with precise matcher130- Flakiness: isolate side effects, use dedicated test data, run service health checks before suite131132## Best practices checklist133134- [ ] Leverage shared fixtures for base URL and authentication135- [ ] Keep request payloads small and reproducible136- [ ] Assert exact response fields and types137- [ ] Log request/response on failure with contextual messages138- [ ] Use `test.step` for complex flows to improve readability139- [ ] Regularly review and refactor tests to remove redundancy and improve clarity140141## References142143- Playwright REST API request docs: https://playwright.dev/docs/api-testing