@api-core/playwright
v0.0.1
Published
Playwright HTTP / Browser request context executor for API-CORE
Maintainers
Readme
@api-core/playwright
Playwright executor implementation for API-Core. This package allows you to run type-safe, contract-first API requests backed by Playwright's APIRequestContext or browser Page context.
Installation
npm install @api-core/playwright @api-coreQuick Start
import { test } from '@playwright/test';
import { createClient } from '@api-core/playwright';
import { registry } from './registry'; // Your API-Core registry
test('fetches user details', async ({ request }) => {
const client = createClient({
config: {
baseURL: 'https://api.example.com',
},
registry,
request, // Pass Playwright request context
});
const response = await client.get('users.getUser', {
path: { id: 42 },
});
console.log(response.data);
});Features
- Type-Safe API Calls: Fully typed request path parameters, query params, headers, and responses mapped from your contract registry.
- Playwright Context Integration: Seamless integration with Playwright's
requestfixture, browserpagecontext, or browsercontext. - Automatic Auth & Cookie Management: Retains context and headers/cookies across browser contexts.
- Production-Grade Autocomplete: Offers clean IntelliSense scoped strictly to Playwright-specific parameters (e.g.
page,context,request).
Example
For a detailed test suite example, see examples/src/tests/playwright.test.ts.
API Overview
createClient(options)
Instantiates the client. The options object accepts:
registry: The API-Core contract registry.config: Global configuration overrides (likebaseURL).request: Playwright'sAPIRequestContext(from therequestfixture).page: Playwright'sPageinstance.context: Playwright'sBrowserContext.
License
MIT © Shanmuka Chandra Teja Anem
Contributing
Contributions are welcome! Please read the root contributing guidelines, open an issue, or submit a pull request.
