Use when managing test state and infrastructure with reusable Playwright fixtures and lifecycle hooks for efficient test setup and teardown.
View on GitHubTheBushidoCollective/han
jutsu-playwright
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-playwright/skills/playwright-fixtures-and-hooks/SKILL.md -a claude-code --skill playwright-fixtures-and-hooksInstallation paths:
.claude/skills/playwright-fixtures-and-hooks/# Playwright Fixtures and Hooks
Master Playwright's fixture system and lifecycle hooks to create reusable
test infrastructure, manage test state, and build maintainable test suites.
This skill covers built-in fixtures, custom fixtures, and best practices
for test setup and teardown.
## Built-in Fixtures
### Core Fixtures
```typescript
import { test, expect } from '@playwright/test';
test('using built-in fixtures', async ({
page, // Page instance
context, // Browser context
browser, // Browser instance
request, // API request context
}) => {
// Each test gets fresh page and context
await page.goto('https://example.com');
await expect(page).toHaveTitle(/Example/);
});
```
### Page Fixture
```typescript
test('page fixture examples', async ({ page }) => {
// Navigate
await page.goto('https://example.com');
// Interact
await page.getByRole('button', { name: 'Click me' }).click();
// Wait
await page.waitForLoadState('networkidle');
// Evaluate
const title = await page.title();
expect(title).toBe('Example Domain');
});
```
### Context Fixture
```typescript
test('context fixture examples', async ({ context, page }) => {
// Add cookies
await context.addCookies([
{
name: 'session',
value: 'abc123',
domain: 'example.com',
path: '/',
},
]);
// Set permissions
await context.grantPermissions(['geolocation']);
// Create additional page in same context
const page2 = await context.newPage();
await page2.goto('https://example.com');
// Both pages share cookies and storage
await page.goto('https://example.com');
});
```
### Browser Fixture
```typescript
test('browser fixture examples', async ({ browser }) => {
// Create custom context with options
const context = await browser.newContext({
viewport: { width: 1920, height: 1080 },
locale: 'en-US',
timezoneId: 'America/New_York',
permissions: ['geolocation'],
});
const page = await context.newPage();