musingfox/cc-plugins/playwright

Claude Code and agent skill by musingfox/cc-plugins

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use to write or set up Playwright / @playwright/test E2E tests — test specs, locators, assertions, fixtures, config. Focuses on structuring tests with high-precision locator strategies. Not for live page exploration or debugging (use agent-browser or web-test).

Install

npx vskill@latest install musingfox/cc-plugins/playwright

SKILL.md

The same SKILL.md was published earlier as musingfox/cc-plugins/playwright.

Playwright Test Writing

Overview

Write browser tests using @playwright/test, the official Playwright test runner. It provides auto-waiting, test isolation, built-in web assertions with auto-retry, and parallel execution out of the box.

For console, network, or page-state diagnostics outside a test, use the web-test skill.

Project Setup

bash
npm install -D @playwright/test
npx playwright install

npm init playwright@latest asks interactive questions, so leave it for the user to run in their own terminal.

Essential playwright.config.ts (for full multi-browser, reporter, and webServer config, see references/api-patterns.md):

typescript
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
retries: process.env.CI ? 2 : 0,
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
},
});

Test File Structure

Tests follow the pattern: tests/<feature>.spec.ts

typescript
import { test, expect } from '@playwright/test';
test.describe('Feature Name', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
});
test('should perform expected behavior', async ({ page }) => {
// Arrange
const submitButton = page.getByRole('button', { name: 'Submit' });
// Act
await submitButton.click();
// Assert
await expect(page.getByText('Success', { exact: true })).toBeVisible();
});
});

Always use the AAA pattern: Arrange (locate elements), Act (interact), Assert (verify outcome).

Locator Strategy (Precision Order)

Apply locators in strict priority order — always prefer the highest-precision option available:

PriorityLocatorWhen to UseStability
1getByTestId('id')Element has data-testid attributeHighest — immune to text/structure changes
2getByRole('role', { name })Element has clear ARIA role and accessible nameVery high — maps from accessibility tree
3getByLabel('label')Form inputs with associated <label>High — tied to label text
4getByPlaceholder('text')Input with placeholder textMedium-high — placeholder may change
5getByText('text', { exact: true })Visible text contentMedium — text may change
6page.locator('[data-attr="val"]')Custom data attributesMedium — depends on attribute stability
7page.locator('css')Last resort — specific CSS selectorLow — fragile to DOM restructuring

Rules:

  • Never use index-based locators (nth(0)) unless testing a list where index is semantically meaningful.
  • Never use XPath unless no other option exists.
  • Always pass { exact: true } to getByText() to prevent partial matches.
  • When multiple elements share the same locator, narrow with .filter({ hasText: 'unique' }) or scope to a parent.

For locator disambiguation patterns (filter, chaining, scoping), see references/api-patterns.md.

Web Assertions (Auto-retry)

Playwright's expect API auto-retries assertions until timeout (default 5s):

typescript
// Visibility
await expect(locator).toBeVisible();
await expect(locator).toBeHidden();
// Text content
await expect(locator).toHaveText('exact text');
await expect(locator).toContainText('partial');
// Input values
await expect(locator).toHaveValue('input value');
// Attributes
await expect(locator).toHaveAttribute('href', '/path');
// Count
await expect(locator).toHaveCount(3);
// Element state
await expect(locator).toBeEnabled();
await expect(locator).toBeDisabled();
await expect(locator).toBeChecked();
// Page-level
await expect(page).toHaveURL(/\/dashboard/);
await expect(page).toHaveTitle('Dashboard');

Critical: Always use await expect(locator).toHaveText() — not expect(await locator.textContent()).toBe(). Web assertions auto-retry; manual extraction does not.

Page Interactions

typescript
// Click
await page.getByRole('button', { name: 'Save' }).click();
// Fill (clears existing content first)
await page.getByLabel('Email').fill('user@example.com');
// Type sequentially (appends, triggers key events)
await page.getByLabel('Search').pressSequentially('query');
// Select dropdown
await page.getByLabel('Country').selectOption('US');
// Check / uncheck
await page.getByLabel('Agree to terms').check();
// Keyboard
await page.keyboard.press('Enter');
await page.keyboard.press('Escape');
// File upload
await page.getByLabel('Upload').setInputFiles('path/to/file.pdf');
// Wait for navigation
await page.waitForURL('/dashboard');

Test Lifecycle

typescript
test.describe('Suite', () => {
test.beforeAll(async () => {
// Run once before all tests in this suite
});
test.beforeEach(async ({ page }) => {
// Run before each test — common setup (e.g., navigation)
});
test.afterEach(async ({ page }) => {
// Run after each test — cleanup
});
test.afterAll(async () => {
// Run once after all tests in this suite
});
});
Custom Fixtures

Extend the test object with reusable setup logic:

typescript
import { test as base, Page } from '@playwright/test';
const test = base.extend<{ authenticatedPage: Page }>({
authenticatedPage: async ({ page }, use) => {
await page.goto('/login');
await page.getByLabel('Email').fill('test@test.com');
await page.getByLabel('Password').fill('password');
await page.getByRole('button', { name: 'Sign In' }).click();
await page.waitForURL('/dashboard');
await use(page);
},
});
test('should show user profile', async ({ authenticatedPage }) => {
await authenticatedPage.goto('/profile');
await expect(authenticatedPage.getByRole('heading', { name: 'Profile' })).toBeVisible();
});

Running Tests

bash
npx playwright test # Run all tests
npx playwright test login.spec.ts # Run specific file
npx playwright test --headed # Visible browser
npx playwright test --ui # Interactive UI mode
npx playwright test --debug # Step-through debugger
npx playwright show-report # View HTML report

After writing a spec, run it with npx playwright test <new-file>. On a failure, read the error, fix the spec, and rerun. The spec is done when that run passes.

Additional Resources

Reference Files

For detailed locator mapping, assertion catalog, and advanced configuration:

  • `references/api-patterns.md` — Locator disambiguation patterns, assertion quick reference, advanced fixtures and configuration

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/musingfox/cc-plugins/playwright/badge)](https://verified-skill.com/skills/musingfox/cc-plugins/playwright)

Something wrong with this skill or its page? Tell us.