playwright-fixtures-and-hooks

Manage Playwright test state with reusable fixtures and lifecycle hooks.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill playwright-fixtures-and-hooks
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: playwright-fixtures-and-hooks
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-playwright/skills/playwright-fixtures-and-hooks
Command: npx skills add https://github.com/TheBushidoCollective/han --skill playwright-fixtures-and-hooks

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill introduces Playwright's fixtures and lifecycle hooks to manage test state and setup/teardown efficiently.

Core Features & Use Cases

  • Built-in Fixtures: Access page, context, browser, and request fixtures.
  • Custom Fixtures: Extend fixtures to share setup code across tests.
  • Scopes & Lifecycle: Test vs. worker-scoped fixtures for optimized resources.

Quick Start

Create a base fixture with a timestamp and use it in a login test.

Frequently Asked Questions about playwright-fixtures-and-hooks

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up reusable test fixtures in Playwright?

Playwright fixtures enable you to define reusable setup and teardown logic shared across tests. Create custom fixtures by declaring them in your configuration, specify their scope (test or worker), and use them as function parameters in your tests to automate state management and initialization.

What's the difference between test-scoped and worker-scoped fixtures?

Test-scoped fixtures run before and after each individual test, isolating state per test. Worker-scoped fixtures run once per worker process, reducing overhead for expensive setup like browser instances. Choose test scope for isolation and worker scope for performance when state can be safely shared.

Can I use Playwright fixtures for authentication flows?

Yes, fixtures support authentication flows by enabling you to store login state, manage cookies, and set storage state once, then reuse authenticated context across multiple tests. This eliminates redundant login steps and accelerates test execution while maintaining consistent session management.

How do fixtures handle permissions and browser context setup?

Fixtures provide built-in context and browser fixtures that let you configure permissions, manage page navigation, and control browser behavior before tests run. Custom fixtures extend these to encapsulate complex setup like granting geolocation or camera permissions across your test suite.

Do fixtures work with unit, integration, and end-to-end tests?

Fixtures apply across all Playwright test types—unit, integration, and end-to-end. They standardize setup and teardown logic regardless of test scope, enabling consistent resource management and state handling across your entire test suite.

Can I combine Playwright fixtures with API requests in tests?

Yes, fixtures include a built-in request fixture for HTTP calls. You can create custom fixtures that set up API contexts, manage authentication tokens, or seed data via API before UI tests run, integrating API automation into your fixture lifecycle.