/playwright-api:api-testingfrom playwright-api
Run the API test suite via the Playwright coding agent core test-runner with API-specific flags. Uses --project=api, no browser, fullyParallel execution, faster timeouts, and JSON reporter for CI result parsing with response time metrics.
Ships in playwright-api. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill delegates execution to the playwright-coding-agent core test-runner skill with API-specific flags applied. Do not run npx playwright test directly from a spec — always route through the core runner so guardrails (budget monitoring, audit logging) are honoured.
Apply these flags for all API runs unless the caller explicitly overrides them:
| Flag | Value | Purpose |
|---|---|---|
--project | api | Target the api project defined in playwright.config.ts; no browser launched |
--reporter | json,list | Emit machine-readable JSON for CI parsing; also emit list for human-readable log output |
--workers | 4 (CI) / undefined (local) | Maximise parallelism for API tests since there is no browser concurrency limit |
--timeout | 10000 | 10 s per-test timeout; faster than E2E since there is no browser rendering |
Example invocation produced by this skill:
npx playwright test --project=api --reporter=json,list --timeout=10000
playwright.config.ts — API Project BlockWhen scaffolding, add the api project block to the existing playwright.config.ts. API tests do not require browser devices:
import { defineConfig } from '@playwright/test';
export default defineConfig({
// ... shared config
projects: [
// --- existing browser projects ---
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
// --- API project (no browser) ---
{
name: 'api',
testDir: './tests/api/specs',
testMatch: '**/*.api.spec.ts',
use: {
// No browser — APIRequestContext only
baseURL: process.env.API_BASE_URL ?? 'http://localhost:3000/api',
},
timeout: 10_000,
fullyParallel: true,
},
],
});
When the caller specifies a file, directory, or tag, scope the run accordingly:
# Single spec file
npx playwright test tests/api/specs/users.api.spec.ts --project=api
# Directory
npx playwright test tests/api/specs/orders/ --project=api
# Tagged tests
npx playwright test --grep @smoke --project=api
After a run with --reporter=json, the output is written to test-results/results.json. Parse the JSON to extract:
duration from each test result and flag tests that exceed the 2 s SLA.Each test result in the JSON contains a duration field (milliseconds). Flag slow tests:
// Example parsing logic (runs outside Playwright, in a CI script)
import results from './test-results/results.json';
const SLA_MS = 2000;
for (const suite of results.suites) {
for (const spec of suite.specs) {
for (const test of spec.tests) {
if (test.results[0]?.duration > SLA_MS) {
console.warn(
`SLOW: ${spec.title} — ${test.results[0].duration}ms (SLA: ${SLA_MS}ms)`
);
}
}
}
}
After parsing the report, classify failures into these categories and present them grouped:
| Category | Indicators | Suggested action |
|---|---|---|
| Connection refused | ECONNREFUSED / net::ERR_CONNECTION_REFUSED | Verify API_BASE_URL env var and that the API server is running |
| Authentication failure | 401 Unauthorized response | Check API_AUTH_TOKEN / API_CLIENT_SECRET env vars; regenerate token |
| Schema mismatch | ajv validation errors or toMatchObject failure | Review API contract change; update schema file or expectation |
| Timeout | Test timeout of 10000ms exceeded | Increase timeout for slow endpoints or investigate server performance |
| Assertion failed | expect(...).toBe / toMatchObject failure | Check expected vs actual in test output; review endpoint behaviour change |
| Flaky | Passes on retry | Check for race conditions in server-side async processing; add retry in fixture |
Return a structured summary after every run:
API Run Summary
───────────────
Project: api
Workers: 4
Passed: 38
Failed: 1
Flaky: 0
Skipped: 0
Duration: 4.2 s
Failed Tests:
1. Orders API > should complete order workflow (tests/api/specs/orders.api.spec.ts:45)
Category: Assertion failed — expected status 201, received 422
Body: {"message":"Validation error","errors":[{"field":"productId","message":"Required"}]}
Slow Tests (> 2000 ms):
1. Reports API > should return monthly summary (tests/api/specs/reports.api.spec.ts:12) — 3410 ms
In CI pipelines, run the API project as a separate job from browser E2E tests to enable independent parallelism and faster feedback:
# GitHub Actions example
- name: Run API tests
run: npx playwright test --project=api --reporter=json,list --timeout=10000
env:
API_BASE_URL: ${{ secrets.API_BASE_URL }}
API_AUTH_TOKEN: ${{ secrets.API_AUTH_TOKEN }}
- name: Upload API test results
if: always()
uses: actions/upload-artifact@v4
with:
name: api-test-results
path: test-results/results.json
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub gagandeepp/software-agent-teams --plugin playwright-api6 skills in this plugin
/api-assertionsAssertion patterns for Playwright API tests. Covers status code checks, JSON body validation, response time thresholds, header verification, pagination shape assertions, and JSON schema validation using inline schemas or ajv./api-fixture-generationCreate authenticated APIRequestContext fixtures with base URL config, shared headers, token management, and teardown cleanup. Produces a typed api-client.ts fixture barrel used by all API spec files./api-mock-generationGenerate page.route() mocks for hybrid E2E+API tests and standalone mock setups. Covers response factory helpers, route interception patterns, GraphQL mock patterns, and network condition simulation./api-project-structureScaffold the API test directory layout under tests/api/, establish file naming conventions (*.api.spec.ts), and configure the api project block in playwright.config.ts./api-test-generationGenerate API test files using Playwright's `request` context for REST (GET/POST/PUT/DELETE) and GraphQL (query/mutation) endpoints. Produces fully-typed .api.spec.ts files with request chains, status code assertions, body validation, and correct import paths.